mirror of
https://github.com/jpetazzo/container.training.git
synced 2026-07-19 21:09:27 +00:00
⏫ Upgrade OpenStack Terraform config to Terraform 1.0
This commit is contained in:
@@ -14,9 +14,9 @@ infra_start() {
|
||||
die "Aborting."
|
||||
fi
|
||||
echo prefix = \"$TAG\" >> terraform.tfvars
|
||||
echo count = \"$COUNT\" >> terraform.tfvars
|
||||
echo how_many_nodes = \"$COUNT\" >> terraform.tfvars
|
||||
terraform apply -auto-approve
|
||||
terraform output ip_addresses > ips.txt
|
||||
terraform output -raw ip_addresses > ips.txt
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
resource "openstack_compute_keypair_v2" "ssh_deploy_key" {
|
||||
name = "${var.prefix}"
|
||||
public_key = "${file("~/.ssh/id_rsa.pub")}"
|
||||
name = var.prefix
|
||||
public_key = file("~/.ssh/id_rsa.pub")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
resource "openstack_compute_instance_v2" "machine" {
|
||||
count = "${var.count}"
|
||||
name = "${format("%s-%04d", "${var.prefix}", count.index+1)}"
|
||||
image_name = "${var.image}"
|
||||
flavor_name = "${var.flavor}"
|
||||
security_groups = ["${openstack_networking_secgroup_v2.full_access.name}"]
|
||||
key_pair = "${openstack_compute_keypair_v2.ssh_deploy_key.name}"
|
||||
count = var.how_many_nodes
|
||||
name = format("%s-%04d", var.prefix, count.index+1)
|
||||
image_name = var.image
|
||||
flavor_name = var.flavor
|
||||
security_groups = [openstack_networking_secgroup_v2.full_access.name]
|
||||
key_pair = openstack_compute_keypair_v2.ssh_deploy_key.name
|
||||
|
||||
network {
|
||||
name = "${openstack_networking_network_v2.internal.name}"
|
||||
fixed_ip_v4 = "${cidrhost("${openstack_networking_subnet_v2.internal.cidr}", count.index+10)}"
|
||||
name = openstack_networking_network_v2.internal.name
|
||||
fixed_ip_v4 = cidrhost(openstack_networking_subnet_v2.internal.cidr, count.index+10)
|
||||
}
|
||||
}
|
||||
|
||||
resource "openstack_compute_floatingip_v2" "machine" {
|
||||
count = "${var.count}"
|
||||
count = var.how_many_nodes
|
||||
# This is something provided to us by Enix when our tenant was provisioned.
|
||||
pool = "Public Floating"
|
||||
}
|
||||
|
||||
resource "openstack_compute_floatingip_associate_v2" "machine" {
|
||||
count = "${var.count}"
|
||||
floating_ip = "${openstack_compute_floatingip_v2.machine.*.address[count.index]}"
|
||||
instance_id = "${openstack_compute_instance_v2.machine.*.id[count.index]}"
|
||||
fixed_ip = "${cidrhost("${openstack_networking_subnet_v2.internal.cidr}", count.index+10)}"
|
||||
count = var.how_many_nodes
|
||||
floating_ip = openstack_compute_floatingip_v2.machine.*.address[count.index]
|
||||
instance_id = openstack_compute_instance_v2.machine.*.id[count.index]
|
||||
fixed_ip = cidrhost(openstack_networking_subnet_v2.internal.cidr, count.index+10)
|
||||
}
|
||||
|
||||
output "ip_addresses" {
|
||||
value = "${join("\n", openstack_compute_floatingip_v2.machine.*.address)}"
|
||||
value = join("", formatlist("%s\n", openstack_compute_floatingip_v2.machine.*.address))
|
||||
}
|
||||
|
||||
variable "flavor" {}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
resource "openstack_networking_network_v2" "internal" {
|
||||
name = "${var.prefix}"
|
||||
name = var.prefix
|
||||
}
|
||||
|
||||
resource "openstack_networking_subnet_v2" "internal" {
|
||||
name = "${var.prefix}"
|
||||
network_id = "${openstack_networking_network_v2.internal.id}"
|
||||
name = var.prefix
|
||||
network_id = openstack_networking_network_v2.internal.id
|
||||
cidr = "10.10.0.0/16"
|
||||
ip_version = 4
|
||||
dns_nameservers = ["1.1.1.1"]
|
||||
}
|
||||
|
||||
resource "openstack_networking_router_v2" "router" {
|
||||
name = "${var.prefix}"
|
||||
name = var.prefix
|
||||
external_network_id = "15f0c299-1f50-42a6-9aff-63ea5b75f3fc"
|
||||
}
|
||||
|
||||
resource "openstack_networking_router_interface_v2" "router_internal" {
|
||||
router_id = "${openstack_networking_router_v2.router.id}"
|
||||
subnet_id = "${openstack_networking_subnet_v2.internal.id}"
|
||||
router_id = openstack_networking_router_v2.router.id
|
||||
subnet_id = openstack_networking_subnet_v2.internal.id
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
terraform {
|
||||
required_version = ">= 1"
|
||||
required_providers {
|
||||
openstack = {
|
||||
source = "terraform-provider-openstack/openstack"
|
||||
version = "~> 1.45.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "openstack" {
|
||||
user_name = "${var.user}"
|
||||
tenant_name = "${var.tenant}"
|
||||
domain_name = "${var.domain}"
|
||||
password = "${var.password}"
|
||||
auth_url = "${var.auth_url}"
|
||||
user_name = var.user
|
||||
tenant_name = var.tenant
|
||||
domain_name = var.domain
|
||||
password = var.password
|
||||
auth_url = var.auth_url
|
||||
}
|
||||
|
||||
variable "user" {}
|
||||
|
||||
@@ -7,6 +7,6 @@ resource "openstack_networking_secgroup_rule_v2" "full_access" {
|
||||
ethertype = "IPv4"
|
||||
protocol = ""
|
||||
remote_ip_prefix = "0.0.0.0/0"
|
||||
security_group_id = "${openstack_networking_secgroup_v2.full_access.id}"
|
||||
security_group_id = openstack_networking_secgroup_v2.full_access.id
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
variable "prefix" {
|
||||
type = "string"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "count" {
|
||||
type = "string"
|
||||
variable "how_many_nodes" {
|
||||
type = number
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user