EMODNet VM creation
This commit is contained in:
parent
2d70c409f9
commit
954c2e2229
|
@ -0,0 +1,109 @@
|
|||
# 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 = "../project-setup/terraform.tfstate"
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Uses common_variables as module
|
||||
#
|
||||
module "common_variables" {
|
||||
source = "../../modules/common_variables"
|
||||
}
|
||||
|
||||
# Module used
|
||||
module "ssh_settings" {
|
||||
source = "../../modules/ssh-key-ref"
|
||||
}
|
||||
|
||||
# SSH access from everywhere
|
||||
resource "openstack_networking_secgroup_v2" "emodnet_ssh_from_outside" {
|
||||
name = "emodnet_ssh_from_outside"
|
||||
delete_default_rules = "true"
|
||||
description = "Access the emodnet VM from the Internet"
|
||||
}
|
||||
|
||||
resource "openstack_networking_secgroup_rule_v2" "emodnet_public_ssh_access" {
|
||||
security_group_id = openstack_networking_secgroup_v2.emodnet_ssh_from_outside.id
|
||||
description = "Access the emodnet VM from the Internet"
|
||||
direction = "ingress"
|
||||
ethertype = "IPv4"
|
||||
protocol = "tcp"
|
||||
port_range_min = 22
|
||||
port_range_max = 22
|
||||
remote_ip_prefix = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
# Instances
|
||||
resource "openstack_compute_instance_v2" "emodnet_service" {
|
||||
name = "emodnet-vm"
|
||||
flavor_name = module.common_variables.flavor_list.m2_medium # 4 cores and 16GB RAM
|
||||
key_pair = module.ssh_settings.ssh_key_name
|
||||
security_groups = [data.terraform_remote_state.privnet_dns_router.outputs.default_security_group_name, data.terraform_remote_state.privnet_dns_router.outputs.security_group_list.http_and_https_from_the_load_balancers, openstack_networking_secgroup_v2.emodnet_ssh_from_outside.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
|
||||
}
|
||||
|
||||
# Creates the networks according to input networks
|
||||
dynamic "network" {
|
||||
for_each = toset([data.terraform_remote_state.privnet_dns_router.outputs.main_private_network.name])
|
||||
content {
|
||||
name = network.value
|
||||
}
|
||||
}
|
||||
|
||||
# user_data script used
|
||||
user_data = file("${module.common_variables.ubuntu_2404.user_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 a floating IP
|
||||
resource "openstack_networking_floatingip_v2" "emodnet_floating_ip" {
|
||||
pool = data.terraform_remote_state.privnet_dns_router.outputs.floating_ip_pools.main_public_ip_pool
|
||||
# The DNS association does not work because of a bug in the OpenStack API
|
||||
# dns_name = "main-lb"
|
||||
# dns_domain = var.dns_zone.zone_name
|
||||
description = "Emodnet VM public IP address"
|
||||
}
|
||||
|
||||
resource "openstack_compute_floatingip_associate_v2" "emodnet_ip" {
|
||||
floating_ip = openstack_networking_floatingip_v2.emodnet_floating_ip.address
|
||||
instance_id = openstack_compute_instance_v2.emodnet_service.id
|
||||
depends_on = [openstack_networking_floatingip_v2.emodnet_floating_ip]
|
||||
}
|
||||
|
||||
resource "openstack_blockstorage_volume_v2" "emodnet_external_volume" {
|
||||
name = "emodnet-external-volume"
|
||||
size = 500
|
||||
description = "External volume for emodnet VM"
|
||||
}
|
||||
|
||||
resource "openstack_compute_volume_attach_v2" "emodnet_volume_attach" {
|
||||
instance_id = openstack_compute_instance_v2.emodnet_service.id
|
||||
volume_id = openstack_blockstorage_volume_v2.emodnet_external_volume.id
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
provider "openstack" {
|
||||
cloud = "d4s-production"
|
||||
}
|
Loading…
Reference in New Issue