|
| 1 | +terraform { |
| 2 | + required_providers { |
| 3 | + mgc = { |
| 4 | + source = "MagaluCloud/mgc" |
| 5 | + version = "0.31.0" |
| 6 | + } |
| 7 | + } |
| 8 | +} |
| 9 | + |
| 10 | +provider "mgc" { |
| 11 | + alias = "mgc" |
| 12 | + region = var.provider_region |
| 13 | +} |
| 14 | + |
| 15 | +resource "mgc_ssh_keys" "my_key" { |
| 16 | + provider = mgc |
| 17 | + name = "local" |
| 18 | + key = var.ssh_key |
| 19 | +} |
| 20 | + |
| 21 | +resource "mgc_network_security_groups" "basic_security_group" { |
| 22 | + name = "basic-security-group" |
| 23 | + description = "A basic security group" |
| 24 | + disable_default_rules = false |
| 25 | +} |
| 26 | + |
| 27 | +resource "mgc_network_security_groups_rules" "allow_ssh" { |
| 28 | + description = "Allow incoming SSH traffic" |
| 29 | + direction = "ingress" |
| 30 | + ethertype = "IPv4" |
| 31 | + port_range_max = 22 |
| 32 | + port_range_min = 22 |
| 33 | + protocol = "tcp" |
| 34 | + remote_ip_prefix = "0.0.0.0/0" |
| 35 | + security_group_id = mgc_network_security_groups.basic_security_group.id |
| 36 | +} |
| 37 | + |
| 38 | +resource "mgc_network_security_groups_rules" "allow_ssh_ipv6" { |
| 39 | + description = "Allow incoming SSH traffic from IPv6" |
| 40 | + direction = "ingress" |
| 41 | + ethertype = "IPv6" |
| 42 | + port_range_max = 22 |
| 43 | + port_range_min = 22 |
| 44 | + protocol = "tcp" |
| 45 | + remote_ip_prefix = "::/0" |
| 46 | + security_group_id = mgc_network_security_groups.basic_security_group.id |
| 47 | +} |
| 48 | + |
| 49 | +resource "mgc_network_security_groups_rules" "allow_http" { |
| 50 | + description = "Allow incoming HTTP traffic" |
| 51 | + direction = "ingress" |
| 52 | + ethertype = "IPv4" |
| 53 | + port_range_max = 80 |
| 54 | + port_range_min = 80 |
| 55 | + protocol = "tcp" |
| 56 | + remote_ip_prefix = "0.0.0.0/0" |
| 57 | + security_group_id = mgc_network_security_groups.basic_security_group.id |
| 58 | +} |
| 59 | + |
| 60 | +resource "mgc_network_security_groups_rules" "allow_http_ipv6" { |
| 61 | + description = "Allow incoming HTTP traffic from IPv6" |
| 62 | + direction = "ingress" |
| 63 | + ethertype = "IPv6" |
| 64 | + port_range_max = 80 |
| 65 | + port_range_min = 80 |
| 66 | + protocol = "tcp" |
| 67 | + remote_ip_prefix = "::/0" |
| 68 | + security_group_id = mgc_network_security_groups.basic_security_group.id |
| 69 | +} |
| 70 | + |
| 71 | +resource "mgc_network_security_groups_rules" "allow_https" { |
| 72 | + description = "Allow incoming HTTPS traffic" |
| 73 | + direction = "ingress" |
| 74 | + ethertype = "IPv4" |
| 75 | + port_range_max = 443 |
| 76 | + port_range_min = 443 |
| 77 | + protocol = "tcp" |
| 78 | + remote_ip_prefix = "0.0.0.0/0" |
| 79 | + security_group_id = mgc_network_security_groups.basic_security_group.id |
| 80 | +} |
| 81 | + |
| 82 | +resource "mgc_network_security_groups_rules" "allow_https_ipv6" { |
| 83 | + description = "Allow incoming HTTPS traffic from IPv6" |
| 84 | + direction = "ingress" |
| 85 | + ethertype = "IPv6" |
| 86 | + port_range_max = 443 |
| 87 | + port_range_min = 443 |
| 88 | + protocol = "tcp" |
| 89 | + remote_ip_prefix = "::/0" |
| 90 | + security_group_id = mgc_network_security_groups.basic_security_group.id |
| 91 | +} |
| 92 | + |
| 93 | +resource "mgc_virtual_machine_instances" "server" { |
| 94 | + provider = mgc.mgc |
| 95 | + name = var.vm_name |
| 96 | + |
| 97 | + machine_type = { |
| 98 | + name = var.machine_type |
| 99 | + } |
| 100 | + |
| 101 | + image = { |
| 102 | + name = var.image |
| 103 | + } |
| 104 | + |
| 105 | + network = { |
| 106 | + associate_public_ip = var.associate_public_ip |
| 107 | + interface = { |
| 108 | + security_groups = [{ id = mgc_network_security_groups.basic_security_group.id }] |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + ssh_key_name = mgc_ssh_keys.my_key.name |
| 113 | +} |
| 114 | + |
| 115 | +resource "mgc_network_security_groups_attach" "attach_sg_to_interface" { |
| 116 | + security_group_id = mgc_network_security_groups.basic_security_group.id |
| 117 | + interface_id = var.interface_id |
| 118 | +} |
0 commit comments