From aafde5a308e23462cf220faa5fe9c66964d8ecb7 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Sat, 20 Apr 2024 15:33:45 +0200 Subject: [PATCH] Add the garr-ct1 basic configuration. --- openstack-tf/garr-ct1/project-setup/README.md | 12 + openstack-tf/garr-ct1/project-setup/main.tf | 56 ++++ .../garr-ct1/project-setup/outputs-ct1.tf | 35 +++ .../garr-ct1/project-setup/provider.tf | 4 + .../garr-ct1/project-setup/terraform.tfstate | 249 ++++++++++++++++++ .../garr-ct1/project-setup/variables-ct1.tf | 63 +++++ 6 files changed, 419 insertions(+) create mode 100644 openstack-tf/garr-ct1/project-setup/README.md create mode 100644 openstack-tf/garr-ct1/project-setup/main.tf create mode 100644 openstack-tf/garr-ct1/project-setup/outputs-ct1.tf create mode 100644 openstack-tf/garr-ct1/project-setup/provider.tf create mode 100644 openstack-tf/garr-ct1/project-setup/terraform.tfstate create mode 100644 openstack-tf/garr-ct1/project-setup/variables-ct1.tf diff --git a/openstack-tf/garr-ct1/project-setup/README.md b/openstack-tf/garr-ct1/project-setup/README.md new file mode 100644 index 0000000..e29817c --- /dev/null +++ b/openstack-tf/garr-ct1/project-setup/README.md @@ -0,0 +1,12 @@ +# How to obtain the "generated" data + +We can import resources using the `terraform import command. The terraform tasks must be already defined for the import to be successful. +Those resources have been imported running: + +```shell-session +terraform import openstack_networking_network_v2.main-private-network 310d65b2-fc5b-4079-b5c2-eb286fbde757 +terraform import openstack_networking_subnet_v2.main-private-subnet 780bcac9-3835-436c-901a-339e38e7345f +terraform import openstack_networking_router_v2.external-router e621a18a-d8f8-4b5a-a9e7-d1ebc9f82a91 +terraform import openstack_networking_router_interface_v2.private-network-routing 2979ba87-2498-4a75-8fcf-b11bb4dadf7a +``` + diff --git a/openstack-tf/garr-ct1/project-setup/main.tf b/openstack-tf/garr-ct1/project-setup/main.tf new file mode 100644 index 0000000..ca439ea --- /dev/null +++ b/openstack-tf/garr-ct1/project-setup/main.tf @@ -0,0 +1,56 @@ +# Define required providers +terraform { + required_version = ">= 0.14.0" + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + } + } +} + +resource "openstack_networking_network_v2" "main-private-network" { + name = var.main_private_network.name + admin_state_up = "true" + external = "false" + description = var.main_private_network.description + mtu = var.mtu_size + port_security_enabled = true + shared = false + region = var.os_region_data.name + tenant_id = var.os_project_data.id +} + +resource "openstack_networking_subnet_v2" "main-private-subnet" { + name = var.main_private_subnet.name + description = var.main_private_subnet.description + network_id = openstack_networking_network_v2.main-private-network.id + cidr = var.main_private_subnet.cidr + gateway_ip = var.main_private_subnet.gateway_ip + dns_nameservers = var.resolvers_ip + ip_version = 4 + enable_dhcp = true + tenant_id = var.os_project_data.id + allocation_pool { + start = var.main_private_subnet.allocation_start + end = var.main_private_subnet.allocation_end + } +} + +resource "openstack_networking_router_v2" "external-router" { + name = var.external_router.name + description = var.external_router.description + external_network_id = var.external_network.id + tenant_id = var.os_project_data.id + enable_snat = true + vendor_options { + set_router_gateway_after_create = true + } +} + +# Router interface configuration +resource "openstack_networking_router_interface_v2" "private-network-routing" { + router_id = openstack_networking_router_v2.external-router.id + # router_id = var.external_router.id + subnet_id = openstack_networking_subnet_v2.main-private-subnet.id +} + diff --git a/openstack-tf/garr-ct1/project-setup/outputs-ct1.tf b/openstack-tf/garr-ct1/project-setup/outputs-ct1.tf new file mode 100644 index 0000000..2a69f12 --- /dev/null +++ b/openstack-tf/garr-ct1/project-setup/outputs-ct1.tf @@ -0,0 +1,35 @@ +output "os_project_data" { + value = var.os_project_data +} + +output "os_region_data" { + value = var.os_region_data + +} +output "default_security_group_name" { + value = "default" +} + +output "main_private_network" { + value = var.main_private_network +} + +output "mtu_size" { + value = var.mtu_size +} + +output "main_private_subnet" { + value = var.main_private_subnet +} + +output "resolvers_ip" { + value = var.resolvers_ip +} + +output "external_router" { + value = var.external_router +} + +output "external_network" { + value = var.external_network +} \ No newline at end of file diff --git a/openstack-tf/garr-ct1/project-setup/provider.tf b/openstack-tf/garr-ct1/project-setup/provider.tf new file mode 100644 index 0000000..e916fc5 --- /dev/null +++ b/openstack-tf/garr-ct1/project-setup/provider.tf @@ -0,0 +1,4 @@ +provider "openstack" { + cloud = "garr-ct1" +} + diff --git a/openstack-tf/garr-ct1/project-setup/terraform.tfstate b/openstack-tf/garr-ct1/project-setup/terraform.tfstate new file mode 100644 index 0000000..ac5d3d3 --- /dev/null +++ b/openstack-tf/garr-ct1/project-setup/terraform.tfstate @@ -0,0 +1,249 @@ +{ + "version": 4, + "terraform_version": "1.7.5", + "serial": 9, + "lineage": "fbd4cad6-e66b-bb4c-d3e4-6440732201b7", + "outputs": { + "default_security_group_name": { + "value": "default", + "type": "string" + }, + "external_network": { + "value": { + "id": "bf588091-e239-4fc8-8d35-eee2bd7d3cb0", + "name": "floating-ip" + }, + "type": [ + "map", + "string" + ] + }, + "external_router": { + "value": { + "description": "GARR-CT1 main router", + "name": "isti-router" + }, + "type": [ + "map", + "string" + ] + }, + "main_private_network": { + "value": { + "description": "GARR CT1 main network", + "name": "isti-VM-CT1-net" + }, + "type": [ + "map", + "string" + ] + }, + "main_private_subnet": { + "value": { + "allocation_end": "192.168.100.253", + "allocation_start": "192.168.100.2", + "cidr": "192.168.100.0/24", + "description": "GARR-CT1 main subnet", + "gateway_ip": "192.168.100.1", + "name": "isti-VM-subnet" + }, + "type": [ + "map", + "string" + ] + }, + "mtu_size": { + "value": 9000, + "type": "number" + }, + "os_project_data": { + "value": { + "id": "a2de533851354b1f8d99ac6b6216d92e" + }, + "type": [ + "map", + "string" + ] + }, + "os_region_data": { + "value": { + "name": "garr-ct1" + }, + "type": [ + "map", + "string" + ] + }, + "resolvers_ip": { + "value": [ + "193.206.141.38", + "193.206.141.42" + ], + "type": [ + "list", + "string" + ] + } + }, + "resources": [ + { + "mode": "managed", + "type": "openstack_networking_network_v2", + "name": "main-private-network", + "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "admin_state_up": true, + "all_tags": [], + "availability_zone_hints": [], + "description": "GARR CT1 main network", + "dns_domain": "", + "external": false, + "id": "310d65b2-fc5b-4079-b5c2-eb286fbde757", + "mtu": 9000, + "name": "isti-VM-CT1-net", + "port_security_enabled": true, + "qos_policy_id": "", + "region": "garr-ct1", + "segments": [], + "shared": false, + "tags": [], + "tenant_id": "a2de533851354b1f8d99ac6b6216d92e", + "timeouts": null, + "transparent_vlan": false, + "value_specs": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=" + } + ] + }, + { + "mode": "managed", + "type": "openstack_networking_router_interface_v2", + "name": "private-network-routing", + "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "force_destroy": null, + "id": "2979ba87-2498-4a75-8fcf-b11bb4dadf7a", + "port_id": "2979ba87-2498-4a75-8fcf-b11bb4dadf7a", + "region": "garr-ct1", + "router_id": "e621a18a-d8f8-4b5a-a9e7-d1ebc9f82a91", + "subnet_id": "780bcac9-3835-436c-901a-339e38e7345f", + "timeouts": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfSwic2NoZW1hX3ZlcnNpb24iOiIwIn0=", + "dependencies": [ + "openstack_networking_network_v2.main-private-network", + "openstack_networking_router_v2.external-router", + "openstack_networking_subnet_v2.main-private-subnet" + ] + } + ] + }, + { + "mode": "managed", + "type": "openstack_networking_router_v2", + "name": "external-router", + "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "admin_state_up": true, + "all_tags": [], + "availability_zone_hints": [], + "description": "GARR-CT1 main router", + "distributed": false, + "enable_snat": true, + "external_fixed_ip": [ + { + "ip_address": "90.147.166.112", + "subnet_id": "ea6832ed-a62d-41a1-83e9-09095bea9c7d" + } + ], + "external_gateway": "bf588091-e239-4fc8-8d35-eee2bd7d3cb0", + "external_network_id": "bf588091-e239-4fc8-8d35-eee2bd7d3cb0", + "external_subnet_ids": null, + "id": "e621a18a-d8f8-4b5a-a9e7-d1ebc9f82a91", + "name": "isti-router", + "region": "garr-ct1", + "tags": [], + "tenant_id": "a2de533851354b1f8d99ac6b6216d92e", + "timeouts": null, + "value_specs": null, + "vendor_options": [ + { + "set_router_gateway_after_create": true + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=" + } + ] + }, + { + "mode": "managed", + "type": "openstack_networking_subnet_v2", + "name": "main-private-subnet", + "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "all_tags": [], + "allocation_pool": [ + { + "end": "192.168.100.253", + "start": "192.168.100.2" + } + ], + "allocation_pools": [ + { + "end": "192.168.100.253", + "start": "192.168.100.2" + } + ], + "cidr": "192.168.100.0/24", + "description": "GARR-CT1 main subnet", + "dns_nameservers": [ + "193.206.141.38", + "193.206.141.42" + ], + "enable_dhcp": true, + "gateway_ip": "192.168.100.1", + "host_routes": [], + "id": "780bcac9-3835-436c-901a-339e38e7345f", + "ip_version": 4, + "ipv6_address_mode": "", + "ipv6_ra_mode": "", + "name": "isti-VM-subnet", + "network_id": "310d65b2-fc5b-4079-b5c2-eb286fbde757", + "no_gateway": false, + "prefix_length": null, + "region": "garr-ct1", + "service_types": [], + "subnetpool_id": "", + "tags": [], + "tenant_id": "a2de533851354b1f8d99ac6b6216d92e", + "timeouts": null, + "value_specs": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=", + "dependencies": [ + "openstack_networking_network_v2.main-private-network" + ] + } + ] + } + ], + "check_results": null +} diff --git a/openstack-tf/garr-ct1/project-setup/variables-ct1.tf b/openstack-tf/garr-ct1/project-setup/variables-ct1.tf new file mode 100644 index 0000000..c942902 --- /dev/null +++ b/openstack-tf/garr-ct1/project-setup/variables-ct1.tf @@ -0,0 +1,63 @@ +# +variable "os_project_data" { + type = map(string) + default = { + id = "a2de533851354b1f8d99ac6b6216d92e" + } +} + +variable "os_region_data" { + type = map(string) + default = { + name = "garr-ct1" + } +} + +variable "default_security_group_name" { + default = "default" +} + +variable "main_private_network" { + type = map(string) + default = { + name = "isti-VM-CT1-net" + description = "GARR CT1 main network" + } +} + +variable "mtu_size" { + default = 9000 +} + +variable "main_private_subnet" { + type = map(string) + default = { + name = "isti-VM-subnet" + description = "GARR-CT1 main subnet" + cidr = "192.168.100.0/24" + gateway_ip = "192.168.100.1" + allocation_start = "192.168.100.2" + allocation_end = "192.168.100.253" + } +} + +variable "resolvers_ip" { + type = list(string) + default = ["193.206.141.38", "193.206.141.42"] +} + +variable "external_router" { + type = map(string) + default = { + name = "isti-router" + description = "GARR-CT1 main router" + } +} + +variable "external_network" { + type = map(string) + default = { + name = "floating-ip" + id = "bf588091-e239-4fc8-8d35-eee2bd7d3cb0" + } +} \ No newline at end of file