101 lines
3.4 KiB
HCL
101 lines
3.4 KiB
HCL
# Define required providers
|
|
terraform {
|
|
required_version = ">= 0.14.0"
|
|
required_providers {
|
|
openstack = {
|
|
source = "terraform-provider-openstack/openstack"
|
|
version = ">= 1.54.0"
|
|
}
|
|
}
|
|
}
|
|
|
|
data "terraform_remote_state" "privnet_dns_router" {
|
|
backend = "local"
|
|
|
|
config = {
|
|
path = "../main_net_dns_router/terraform.tfstate"
|
|
}
|
|
}
|
|
|
|
module "ssh_settings" {
|
|
source = "../../modules/ssh-key-ref"
|
|
}
|
|
#
|
|
# Uses common_variables as module
|
|
#
|
|
module "common_variables" {
|
|
source = "../../modules/labs_common_variables"
|
|
}
|
|
|
|
resource "openstack_compute_instance_v2" "wp_musit_proj" {
|
|
name = "wp-musit-project"
|
|
availability_zone_hints = module.common_variables.availability_zone_no_gpu_name
|
|
flavor_name = module.common_variables.flavor_list.m1_medium
|
|
key_pair = module.ssh_settings.ssh_key_name
|
|
security_groups = [data.terraform_remote_state.privnet_dns_router.outputs.default_security_group_name]
|
|
block_device {
|
|
uuid = module.common_variables.ubuntu_2404.uuid
|
|
source_type = "image"
|
|
volume_size = 30
|
|
boot_index = 0
|
|
destination_type = "volume"
|
|
delete_on_termination = false
|
|
}
|
|
network {
|
|
name = data.terraform_remote_state.privnet_dns_router.outputs.main_private_network.name
|
|
}
|
|
user_data = file("${data.terraform_remote_state.privnet_dns_router.outputs.ubuntu2404_data_file}")
|
|
# Do not replace the instance when the ssh key changes
|
|
lifecycle {
|
|
ignore_changes = [
|
|
# Ignore changes to tags, e.g. because a management agent
|
|
# updates these based on some ruleset managed elsewhere.
|
|
key_pair, user_data, network
|
|
]
|
|
}
|
|
}
|
|
|
|
# Allocate and associate a floating IP address
|
|
#
|
|
resource "openstack_networking_floatingip_v2" "wp_musit_proj_ip" {
|
|
pool = module.common_variables.floating_ip_pools.main_public_ip_pool
|
|
# The DNS association does not work because of a bug in the OpenStack API
|
|
description = "Wordpress for the musit project"
|
|
}
|
|
|
|
data "openstack_networking_port_v2" "wp_musit_proj_port" {
|
|
device_id = openstack_compute_instance_v2.wp_musit_proj.id
|
|
network_id = openstack_compute_instance_v2.wp_musit_proj.network.0.uuid
|
|
}
|
|
|
|
resource "openstack_networking_floatingip_associate_v2" "wp_musit_proj_fip_associate" {
|
|
floating_ip = openstack_networking_floatingip_v2.wp_musit_proj_ip.address
|
|
port_id = data.openstack_networking_port_v2.wp_musit_proj_port.id
|
|
}
|
|
|
|
#
|
|
# Add a DNS record to the floating IP address
|
|
#
|
|
module "dns_records_create" {
|
|
source = "../../modules/dns_resources"
|
|
|
|
dns_resources_map = {
|
|
wp = {
|
|
zone_id = data.terraform_remote_state.privnet_dns_router.outputs.dns_zone_id
|
|
name = join(".", ["wp-musit-proj", data.terraform_remote_state.privnet_dns_router.outputs.dns_zone.name])
|
|
description = "Wordpress for the musit project"
|
|
ttl = 8600
|
|
type = "A"
|
|
records = [openstack_networking_floatingip_v2.wp_musit_proj_ip.address]
|
|
},
|
|
phpadmin = {
|
|
zone_id = data.terraform_remote_state.privnet_dns_router.outputs.dns_zone_id
|
|
name = join(".", ["phpadmin-musit", data.terraform_remote_state.privnet_dns_router.outputs.dns_zone.name])
|
|
description = "PHPMyAdmin for the Wordpress DB of the musit project"
|
|
ttl = 8600
|
|
type = "CNAME"
|
|
records = [join(".", ["wp-musit-proj", data.terraform_remote_state.privnet_dns_router.outputs.dns_zone.name])]
|
|
}
|
|
}
|
|
}
|