1
0
forked from ovh/pci-test
pci-test/ex3/main.tf
2024-12-03 15:50:29 +01:00

59 lines
1.7 KiB
HCL

resource "openstack_networking_router_v2" "rt" {
name = "rt"
admin_state_up = "true"
external_network_id = var.network_external_id
}
resource "openstack_networking_network_v2" "network_internal" {
name = var.network_lan
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "network_subnet" {
name = var.network_lan
network_id = openstack_networking_network_v2.network_internal.id
cidr = var.network_subnet_cidr
ip_version = 4
enable_dhcp = true
dns_nameservers = ["1.1.1.1"]
}
resource "openstack_networking_router_interface_v2" "network_router_interface" {
router_id = openstack_networking_router_v2.rt.id
subnet_id = openstack_networking_subnet_v2.network_subnet.id
}
resource "openstack_networking_floatingip_v2" "d2_fip" {
pool = "Ext-Net"
}
resource "openstack_compute_keypair_v2" "instance_keypair" {
provider = openstack.ovh
name = "instance_keypair"
public_key = file(var.ssh_pubkey)
}
resource "openstack_compute_instance_v2" "instance" {
name = "d2_test"
provider = openstack.ovh
image_name = "Debian 12"
flavor_name = "d2-4"
key_pair = openstack_compute_keypair_v2.instance_keypair.name
user_data = var.cloudinit_script
network {
name = var.network_lan
}
depends_on = [ openstack_networking_subnet_v2.network_subnet ]
}
data "openstack_networking_port_v2" "port" {
device_id = openstack_compute_instance_v2.instance.id
network_id = openstack_compute_instance_v2.instance.network.0.uuid
}
resource "openstack_networking_floatingip_associate_v2" "fip_associate" {
floating_ip = openstack_networking_floatingip_v2.d2_fip.address
port_id = data.openstack_networking_port_v2.port.id
}