diff --git a/terraform/modules/aks-rancher-k8s/main.tf b/terraform/modules/aks-rancher-k8s/main.tf index 21221e41..7dcd3a4d 100644 --- a/terraform/modules/aks-rancher-k8s/main.tf +++ b/terraform/modules/aks-rancher-k8s/main.tf @@ -2,51 +2,52 @@ data "external" "rancher_cluster" { program = ["bash", "${path.module}/files/rancher_cluster_import.sh"] query = { - rancher_api_url = "${var.rancher_api_url}" - rancher_access_key = "${var.rancher_access_key}" - rancher_secret_key = "${var.rancher_secret_key}" - name = "${var.name}" + rancher_api_url = var.rancher_api_url + rancher_access_key = var.rancher_access_key + rancher_secret_key = var.rancher_secret_key + name = var.name } } provider "azurerm" { - subscription_id = "${var.azure_subscription_id}" - client_id = "${var.azure_client_id}" - client_secret = "${var.azure_client_secret}" - tenant_id = "${var.azure_tenant_id}" - environment = "${var.azure_environment}" + version = "=2.0.0" + subscription_id = var.azure_subscription_id + client_id = var.azure_client_id + client_secret = var.azure_client_secret + tenant_id = var.azure_tenant_id + environment = var.azure_environment } resource "azurerm_resource_group" "resource_group" { name = "${var.name}-resource_group" - location = "${var.azure_location}" + location = var.azure_location } resource "azurerm_kubernetes_cluster" "primary" { - name = "${var.name}" - location = "${azurerm_resource_group.resource_group.location}" - resource_group_name = "${azurerm_resource_group.resource_group.name}" - dns_prefix = "${var.name}" + name = var.name + location = azurerm_resource_group.resource_group.location + resource_group_name = azurerm_resource_group.resource_group.name + dns_prefix = var.name - kubernetes_version = "${var.k8s_version}" + kubernetes_version = var.k8s_version linux_profile { - admin_username = "${var.azure_ssh_user}" + admin_username = var.azure_ssh_user ssh_key { - key_data = "${file(var.azure_public_key_path)}" + key_data = file(var.azure_public_key_path) } } - agent_pool_profile { - name = "default" - count = "${var.node_count}" - vm_size = "${var.azure_size}" + default_node_pool { + name = "default" + node_count = var.node_count + vm_size = var.azure_size } service_principal { - client_id = "${var.azure_client_id}" - client_secret = "${var.azure_client_secret}" + client_id = var.azure_client_id + client_secret = var.azure_client_secret } } @@ -56,19 +57,23 @@ locals { # Bootstrap rancher in aks environment resource "null_resource" "import_rancher" { - triggers { - cluster = "${azurerm_kubernetes_cluster.primary.id}" + triggers = { + cluster = azurerm_kubernetes_cluster.primary.id } provisioner "local-exec" { - command = "${format("cat << EOF > %s \n%s\nEOF", local.kube_config_path, azurerm_kubernetes_cluster.primary.kube_config_raw)}" + command = format( + "cat << EOF > %s \n%s\nEOF", + local.kube_config_path, + azurerm_kubernetes_cluster.primary.kube_config_raw, + ) } provisioner "local-exec" { command = "curl --insecure -sfL ${var.rancher_api_url}/v3/import/${data.external.rancher_cluster.result.registration_token}.yaml | kubectl apply -f -" - environment { - KUBECONFIG = "${local.kube_config_path}" + environment = { + KUBECONFIG = local.kube_config_path } } @@ -76,3 +81,4 @@ resource "null_resource" "import_rancher" { command = "rm ${local.kube_config_path}" } } + diff --git a/terraform/modules/aks-rancher-k8s/outputs.tf b/terraform/modules/aks-rancher-k8s/outputs.tf index 5af2b9e1..5239f359 100644 --- a/terraform/modules/aks-rancher-k8s/outputs.tf +++ b/terraform/modules/aks-rancher-k8s/outputs.tf @@ -1,11 +1,12 @@ output "rancher_cluster_id" { - value = "${lookup(data.external.rancher_cluster.result, "cluster_id")}" + value = data.external.rancher_cluster.result["cluster_id"] } output "rancher_cluster_registration_token" { - value = "${lookup(data.external.rancher_cluster.result, "registration_token")}" + value = data.external.rancher_cluster.result["registration_token"] } output "rancher_cluster_ca_checksum" { - value = "${lookup(data.external.rancher_cluster.result, "ca_checksum")}" -} \ No newline at end of file + value = data.external.rancher_cluster.result["ca_checksum"] +} + diff --git a/terraform/modules/aks-rancher-k8s/variables.tf b/terraform/modules/aks-rancher-k8s/variables.tf index 05bca0fa..cf1dc64c 100644 --- a/terraform/modules/aks-rancher-k8s/variables.tf +++ b/terraform/modules/aks-rancher-k8s/variables.tf @@ -14,21 +14,27 @@ variable "rancher_secret_key" { description = "" } -variable "azure_subscription_id" {} +variable "azure_subscription_id" { +} -variable "azure_client_id" {} +variable "azure_client_id" { +} -variable "azure_client_secret" {} +variable "azure_client_secret" { +} -variable "azure_tenant_id" {} +variable "azure_tenant_id" { +} variable "azure_environment" { default = "public" } -variable "azure_location" {} +variable "azure_location" { +} -variable "azure_size" {} +variable "azure_size" { +} variable "azure_ssh_user" { default = "root" @@ -42,4 +48,6 @@ variable "k8s_version" { default = "1.9.6" } -variable "node_count" {} +variable "node_count" { +} + diff --git a/terraform/modules/aks-rancher-k8s/versions.tf b/terraform/modules/aks-rancher-k8s/versions.tf new file mode 100644 index 00000000..ac97c6ac --- /dev/null +++ b/terraform/modules/aks-rancher-k8s/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/terraform/modules/aws-rancher-k8s-host/main.tf b/terraform/modules/aws-rancher-k8s-host/main.tf index cfe45d84..477a2854 100644 --- a/terraform/modules/aws-rancher-k8s-host/main.tf +++ b/terraform/modules/aws-rancher-k8s-host/main.tf @@ -1,55 +1,53 @@ provider "aws" { - access_key = "${var.aws_access_key}" - secret_key = "${var.aws_secret_key}" - region = "${var.aws_region}" + version = "~> 2.0" + access_key = var.aws_access_key + secret_key = var.aws_secret_key + region = var.aws_region } locals { - rancher_node_role = "${element(keys(var.rancher_host_labels), 0)}" + rancher_node_role = element(keys(var.rancher_host_labels), 0) } data "template_file" "install_rancher_agent" { - template = "${file("${path.module}/files/install_rancher_agent.sh.tpl")}" + template = file("${path.module}/files/install_rancher_agent.sh.tpl") - vars { - hostname = "${var.hostname}" - docker_engine_install_url = "${var.docker_engine_install_url}" - - rancher_api_url = "${var.rancher_api_url}" - rancher_cluster_registration_token = "${var.rancher_cluster_registration_token}" - rancher_cluster_ca_checksum = "${var.rancher_cluster_ca_checksum}" - rancher_node_role = "${local.rancher_node_role == "control" ? "controlplane" : local.rancher_node_role}" - rancher_agent_image = "${var.rancher_agent_image}" - - rancher_registry = "${var.rancher_registry}" - rancher_registry_username = "${var.rancher_registry_username}" - rancher_registry_password = "${var.rancher_registry_password}" - - volume_device_name = "${var.ebs_volume_device_name}" - volume_mount_path = "${var.ebs_volume_mount_path}" + vars = { + hostname = var.hostname + docker_engine_install_url = var.docker_engine_install_url + rancher_api_url = var.rancher_api_url + rancher_cluster_registration_token = var.rancher_cluster_registration_token + rancher_cluster_ca_checksum = var.rancher_cluster_ca_checksum + rancher_node_role = local.rancher_node_role == "control" ? "controlplane" : local.rancher_node_role + rancher_agent_image = var.rancher_agent_image + rancher_registry = var.rancher_registry + rancher_registry_username = var.rancher_registry_username + rancher_registry_password = var.rancher_registry_password + volume_device_name = var.ebs_volume_device_name + volume_mount_path = var.ebs_volume_mount_path } } resource "aws_instance" "host" { - ami = "${var.aws_ami_id}" - instance_type = "${var.aws_instance_type}" - subnet_id = "${var.aws_subnet_id}" - vpc_security_group_ids = ["${var.aws_security_group_id}"] - key_name = "${var.aws_key_name}" + ami = var.aws_ami_id + instance_type = var.aws_instance_type + subnet_id = var.aws_subnet_id + vpc_security_group_ids = [var.aws_security_group_id] + key_name = var.aws_key_name tags = { - Name = "${var.hostname}" + Name = var.hostname } - user_data = "${data.template_file.install_rancher_agent.rendered}" + user_data = data.template_file.install_rancher_agent.rendered } resource "aws_ebs_volume" "host_volume" { - count = "${var.ebs_volume_device_name != "" ? 1 : 0}" + count = var.ebs_volume_device_name != "" ? 1 : 0 - availability_zone = "${aws_instance.host.availability_zone}" - type = "${var.ebs_volume_type}" - size = "${var.ebs_volume_size}" + availability_zone = aws_instance.host.availability_zone + type = var.ebs_volume_type + size = var.ebs_volume_size tags = { Name = "${var.hostname}-volume" @@ -57,12 +55,13 @@ resource "aws_ebs_volume" "host_volume" { } resource "aws_volume_attachment" "host_volume_attachment" { - count = "${var.ebs_volume_device_name != "" ? 1 : 0}" + count = var.ebs_volume_device_name != "" ? 1 : 0 # Forcing detach to prevent VolumeInUse error force_detach = true - device_name = "${var.ebs_volume_device_name}" - volume_id = "${aws_ebs_volume.host_volume.id}" - instance_id = "${aws_instance.host.id}" + device_name = var.ebs_volume_device_name + volume_id = aws_ebs_volume.host_volume[0].id + instance_id = aws_instance.host.id } + diff --git a/terraform/modules/aws-rancher-k8s-host/outputs.tf b/terraform/modules/aws-rancher-k8s-host/outputs.tf deleted file mode 100644 index 8b137891..00000000 --- a/terraform/modules/aws-rancher-k8s-host/outputs.tf +++ /dev/null @@ -1 +0,0 @@ - diff --git a/terraform/modules/aws-rancher-k8s-host/variables.tf b/terraform/modules/aws-rancher-k8s-host/variables.tf index a4454990..98e70254 100644 --- a/terraform/modules/aws-rancher-k8s-host/variables.tf +++ b/terraform/modules/aws-rancher-k8s-host/variables.tf @@ -6,12 +6,14 @@ variable "rancher_api_url" { description = "" } -variable "rancher_cluster_registration_token" {} +variable "rancher_cluster_registration_token" { +} -variable "rancher_cluster_ca_checksum" {} +variable "rancher_cluster_ca_checksum" { +} variable "rancher_host_labels" { - type = "map" + type = map(string) description = "A map of key/value pairs that get passed to the rancher agent on the host." } @@ -92,3 +94,4 @@ variable "ebs_volume_size" { default = "" description = "The size of the volume, in GiBs." } + diff --git a/terraform/modules/aws-rancher-k8s-host/versions.tf b/terraform/modules/aws-rancher-k8s-host/versions.tf new file mode 100644 index 00000000..ac97c6ac --- /dev/null +++ b/terraform/modules/aws-rancher-k8s-host/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/terraform/modules/aws-rancher-k8s/main.tf b/terraform/modules/aws-rancher-k8s/main.tf index a2f89fb1..d551e7c7 100644 --- a/terraform/modules/aws-rancher-k8s/main.tf +++ b/terraform/modules/aws-rancher-k8s/main.tf @@ -2,87 +2,88 @@ data "external" "rancher_cluster" { program = ["bash", "${path.module}/files/rancher_cluster.sh"] query = { - rancher_api_url = "${var.rancher_api_url}" - rancher_access_key = "${var.rancher_access_key}" - rancher_secret_key = "${var.rancher_secret_key}" - name = "${var.name}" - k8s_version = "${var.k8s_version}" - k8s_network_provider = "${var.k8s_network_provider}" - k8s_registry = "${var.k8s_registry}" - k8s_registry_username = "${var.k8s_registry_username}" - k8s_registry_password = "${var.k8s_registry_password}" + rancher_api_url = var.rancher_api_url + rancher_access_key = var.rancher_access_key + rancher_secret_key = var.rancher_secret_key + name = var.name + k8s_version = var.k8s_version + k8s_network_provider = var.k8s_network_provider + k8s_registry = var.k8s_registry + k8s_registry_username = var.k8s_registry_username + k8s_registry_password = var.k8s_registry_password } } /* Setup our aws provider */ provider "aws" { - access_key = "${var.aws_access_key}" - secret_key = "${var.aws_secret_key}" - region = "${var.aws_region}" + version = "~> 2.0" + access_key = var.aws_access_key + secret_key = var.aws_secret_key + region = var.aws_region } /* Define our vpc */ resource "aws_vpc" "default" { - cidr_block = "${var.aws_vpc_cidr}" + cidr_block = var.aws_vpc_cidr - tags { - Name = "${var.name}" + tags = { + Name = var.name } } resource "aws_internet_gateway" "default" { - vpc_id = "${aws_vpc.default.id}" + vpc_id = aws_vpc.default.id } resource "aws_subnet" "public" { - vpc_id = "${aws_vpc.default.id}" - cidr_block = "${var.aws_subnet_cidr}" + vpc_id = aws_vpc.default.id + cidr_block = var.aws_subnet_cidr map_public_ip_on_launch = true - depends_on = ["aws_internet_gateway.default"] + depends_on = [aws_internet_gateway.default] - tags { + tags = { Name = "public" } } resource "aws_route_table" "public" { - vpc_id = "${aws_vpc.default.id}" + vpc_id = aws_vpc.default.id route { cidr_block = "0.0.0.0/0" - gateway_id = "${aws_internet_gateway.default.id}" + gateway_id = aws_internet_gateway.default.id } } resource "aws_route_table_association" "public" { - subnet_id = "${aws_subnet.public.id}" - route_table_id = "${aws_route_table.public.id}" + subnet_id = aws_subnet.public.id + route_table_id = aws_route_table.public.id } resource "aws_key_pair" "deployer" { // Only attempt to create the key pair if the public key was provided - count = "${var.aws_public_key_path != "" ? 1 : 0}" + count = var.aws_public_key_path != "" ? 1 : 0 - key_name = "${var.aws_key_name}" - public_key = "${file("${var.aws_public_key_path}")}" + key_name = var.aws_key_name + public_key = file(var.aws_public_key_path) } # Firewall requirements taken from: # https://rancher.com/docs/rancher/v2.0/en/quick-start-guide/ resource "aws_security_group" "rke_ports" { - name = "${var.name}" + name = var.name description = "Security group for rancher hosts in ${var.name} cluster" - vpc_id = "${aws_vpc.default.id}" + vpc_id = aws_vpc.default.id ingress { - from_port = "22" # SSH + from_port = "22" # SSH to_port = "22" protocol = "tcp" self = true } ingress { - from_port = "80" # Canal + from_port = "80" # Canal to_port = "80" protocol = "tcp" self = true @@ -151,3 +152,4 @@ resource "aws_security_group" "rke_ports" { cidr_blocks = ["0.0.0.0/0"] } } + diff --git a/terraform/modules/aws-rancher-k8s/outputs.tf b/terraform/modules/aws-rancher-k8s/outputs.tf index 88fa1f5f..1b33c47d 100644 --- a/terraform/modules/aws-rancher-k8s/outputs.tf +++ b/terraform/modules/aws-rancher-k8s/outputs.tf @@ -1,23 +1,24 @@ output "rancher_cluster_id" { - value = "${lookup(data.external.rancher_cluster.result, "cluster_id")}" + value = data.external.rancher_cluster.result["cluster_id"] } output "rancher_cluster_registration_token" { - value = "${lookup(data.external.rancher_cluster.result, "registration_token")}" + value = data.external.rancher_cluster.result["registration_token"] } output "rancher_cluster_ca_checksum" { - value = "${lookup(data.external.rancher_cluster.result, "ca_checksum")}" + value = data.external.rancher_cluster.result["ca_checksum"] } output "aws_subnet_id" { - value = "${aws_subnet.public.id}" + value = aws_subnet.public.id } output "aws_security_group_id" { - value = "${aws_security_group.rke_ports.id}" + value = aws_security_group.rke_ports.id } output "aws_key_name" { - value = "${var.aws_key_name}" + value = var.aws_key_name } + diff --git a/terraform/modules/aws-rancher-k8s/variables.tf b/terraform/modules/aws-rancher-k8s/variables.tf index bcd06996..4ef64ecb 100644 --- a/terraform/modules/aws-rancher-k8s/variables.tf +++ b/terraform/modules/aws-rancher-k8s/variables.tf @@ -14,11 +14,11 @@ variable "rancher_secret_key" { description = "" } -variable k8s_version { +variable "k8s_version" { default = "v1.17.6-rancher2-1" } -variable k8s_network_provider { +variable "k8s_network_provider" { default = "flannel" } @@ -87,3 +87,4 @@ variable "aws_public_key_path" { variable "aws_key_name" { description = "Name of the public key to be used for provisioning" } + diff --git a/terraform/modules/aws-rancher-k8s/versions.tf b/terraform/modules/aws-rancher-k8s/versions.tf new file mode 100644 index 00000000..ac97c6ac --- /dev/null +++ b/terraform/modules/aws-rancher-k8s/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/terraform/modules/aws-rancher/main.tf b/terraform/modules/aws-rancher/main.tf index e090691d..62b4f88c 100644 --- a/terraform/modules/aws-rancher/main.tf +++ b/terraform/modules/aws-rancher/main.tf @@ -1,77 +1,78 @@ provider "aws" { - access_key = "${var.aws_access_key}" - secret_key = "${var.aws_secret_key}" - region = "${var.aws_region}" + version = "~> 2.0" + access_key = var.aws_access_key + secret_key = var.aws_secret_key + region = var.aws_region } resource "aws_vpc" "default" { - cidr_block = "${var.aws_vpc_cidr}" + cidr_block = var.aws_vpc_cidr - tags { - Name = "${var.name}" + tags = { + Name = var.name } } resource "aws_internet_gateway" "default" { - vpc_id = "${aws_vpc.default.id}" + vpc_id = aws_vpc.default.id } resource "aws_subnet" "public" { - vpc_id = "${aws_vpc.default.id}" - cidr_block = "${var.aws_subnet_cidr}" + vpc_id = aws_vpc.default.id + cidr_block = var.aws_subnet_cidr map_public_ip_on_launch = true - depends_on = ["aws_internet_gateway.default"] + depends_on = [aws_internet_gateway.default] - tags { + tags = { Name = "public" } } resource "aws_route_table" "public" { - vpc_id = "${aws_vpc.default.id}" + vpc_id = aws_vpc.default.id route { cidr_block = "0.0.0.0/0" - gateway_id = "${aws_internet_gateway.default.id}" + gateway_id = aws_internet_gateway.default.id } } resource "aws_route_table_association" "public" { - subnet_id = "${aws_subnet.public.id}" - route_table_id = "${aws_route_table.public.id}" + subnet_id = aws_subnet.public.id + route_table_id = aws_route_table.public.id } resource "aws_key_pair" "deployer" { // Only attempt to create the key pair if the public key was provided - count = "${var.aws_public_key_path != "" ? 1 : 0}" + count = var.aws_public_key_path != "" ? 1 : 0 - key_name = "${var.aws_key_name}" - public_key = "${file("${var.aws_public_key_path}")}" + key_name = var.aws_key_name + public_key = file(var.aws_public_key_path) } # Firewall requirements taken from: # https://rancher.com/docs/rancher/v2.0/en/quick-start-guide/ resource "aws_security_group" "rke_ports" { - name = "${var.name}" + name = var.name description = "Security group for rancher hosts in ${var.name} cluster" - vpc_id = "${aws_vpc.default.id}" + vpc_id = aws_vpc.default.id ingress { - from_port = "22" # SSH + from_port = "22" # SSH to_port = "22" protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress { - from_port = "80" # Rancher UI + from_port = "80" # Rancher UI to_port = "80" protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress { - from_port = "443" # Rancher UI + from_port = "443" # Rancher UI to_port = "443" protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] @@ -86,101 +87,103 @@ resource "aws_security_group" "rke_ports" { } resource "aws_instance" "host" { - ami = "${var.aws_ami_id}" - instance_type = "${var.aws_instance_type}" - subnet_id = "${aws_subnet.public.id}" - vpc_security_group_ids = ["${aws_security_group.rke_ports.id}"] - key_name = "${var.aws_key_name}" + ami = var.aws_ami_id + instance_type = var.aws_instance_type + subnet_id = aws_subnet.public.id + vpc_security_group_ids = [aws_security_group.rke_ports.id] + key_name = var.aws_key_name tags = { - Name = "${var.name}" + Name = var.name } - user_data = "${data.template_file.install_docker.rendered}" + user_data = data.template_file.install_docker.rendered } locals { - rancher_master_id = "${aws_instance.host.id}" - rancher_master_ip = "${aws_instance.host.public_ip}" - ssh_user = "${var.aws_ssh_user}" - key_path = "${var.aws_private_key_path}" + rancher_master_id = aws_instance.host.id + rancher_master_ip = aws_instance.host.public_ip + ssh_user = var.aws_ssh_user + key_path = var.aws_private_key_path } data "template_file" "install_docker" { - template = "${file("${path.module}/files/install_docker_rancher.sh.tpl")}" + template = file("${path.module}/files/install_docker_rancher.sh.tpl") - vars { - docker_engine_install_url = "${var.docker_engine_install_url}" - - rancher_server_image = "${var.rancher_server_image}" - rancher_registry = "${var.rancher_registry}" - rancher_registry_username = "${var.rancher_registry_username}" - rancher_registry_password = "${var.rancher_registry_password}" + vars = { + docker_engine_install_url = var.docker_engine_install_url + rancher_server_image = var.rancher_server_image + rancher_registry = var.rancher_registry + rancher_registry_username = var.rancher_registry_username + rancher_registry_password = var.rancher_registry_password } } data "template_file" "install_rancher_master" { - template = "${file("${path.module}/files/install_rancher_master.sh.tpl")}" + template = file("${path.module}/files/install_rancher_master.sh.tpl") - vars { - rancher_server_image = "${var.rancher_server_image}" - rancher_registry = "${var.rancher_registry}" - rancher_registry_username = "${var.rancher_registry_username}" - rancher_registry_password = "${var.rancher_registry_password}" + vars = { + rancher_server_image = var.rancher_server_image + rancher_registry = var.rancher_registry + rancher_registry_username = var.rancher_registry_username + rancher_registry_password = var.rancher_registry_password } } resource "null_resource" "install_rancher_master" { # Changes to any instance of the cluster requires re-provisioning - triggers { - rancher_master_id = "${local.rancher_master_id}" + triggers = { + rancher_master_id = local.rancher_master_id } connection { type = "ssh" - user = "${local.ssh_user}" - host = "${local.rancher_master_ip}" - private_key = "${file(local.key_path)}" + user = local.ssh_user + host = local.rancher_master_ip + private_key = file(local.key_path) } provisioner "remote-exec" { inline = < kubeconfig.yaml - EOT + +EOT + } provisioner "local-exec" { # Write minio_manta_deployment.yaml to disk - command = "${format("cat << EOF > minio_manta_deployment.yaml \n%s\nEOF", data.template_file.minio_manta_deployment.rendered)}" + command = format( + "cat << EOF > minio_manta_deployment.yaml \n%s\nEOF", + data.template_file.minio_manta_deployment.rendered, + ) } provisioner "local-exec" { @@ -60,3 +65,4 @@ resource "null_resource" "setup_ark_backup" { command = "rm -rf ark ark-* minio_manta_deployment.yaml kubeconfig.yaml v0.7.1.tar.gz" } } + diff --git a/terraform/modules/k8s-backup-manta/outputs.tf b/terraform/modules/k8s-backup-manta/outputs.tf deleted file mode 100644 index 8b137891..00000000 --- a/terraform/modules/k8s-backup-manta/outputs.tf +++ /dev/null @@ -1 +0,0 @@ - diff --git a/terraform/modules/k8s-backup-manta/variables.tf b/terraform/modules/k8s-backup-manta/variables.tf index 03a49cc3..8ef03702 100644 --- a/terraform/modules/k8s-backup-manta/variables.tf +++ b/terraform/modules/k8s-backup-manta/variables.tf @@ -1,10 +1,14 @@ -variable "rancher_api_url" {} +variable "rancher_api_url" { +} -variable "rancher_access_key" {} +variable "rancher_access_key" { +} -variable "rancher_secret_key" {} +variable "rancher_secret_key" { +} -variable "rancher_cluster_id" {} +variable "rancher_cluster_id" { +} variable "triton_key_path" { default = "" @@ -23,3 +27,4 @@ variable "manta_subuser" { default = "" description = "The Manta subuser" } + diff --git a/terraform/modules/k8s-backup-manta/versions.tf b/terraform/modules/k8s-backup-manta/versions.tf new file mode 100644 index 00000000..ac97c6ac --- /dev/null +++ b/terraform/modules/k8s-backup-manta/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/terraform/modules/k8s-backup-s3/main.tf b/terraform/modules/k8s-backup-s3/main.tf index eb5c213f..6bd79542 100644 --- a/terraform/modules/k8s-backup-s3/main.tf +++ b/terraform/modules/k8s-backup-s3/main.tf @@ -25,7 +25,9 @@ resource "null_resource" "setup_ark_backup" { -H 'Content-Type: application/json' \ -d '' \ '${var.rancher_api_url}/v3/clusters/${var.rancher_cluster_id}?action=generateKubeconfig' | jq -r '.config' > kubeconfig.yaml - EOT + +EOT + } provisioner "local-exec" { @@ -35,7 +37,9 @@ resource "null_resource" "setup_ark_backup" { aws_access_key_id=${var.aws_access_key} aws_secret_access_key=${var.aws_secret_key} EOF - EOT + +EOT + } provisioner "local-exec" { @@ -45,7 +49,7 @@ resource "null_resource" "setup_ark_backup" { provisioner "local-exec" { command = "kubectl create secret generic cloud-credentials --namespace $ARK_SERVER_NAMESPACE --from-file cloud=credentials-ark --kubeconfig=kubeconfig.yaml --dry-run -o yaml | kubectl apply --kubeconfig=kubeconfig.yaml -f -" - environment { + environment = { ARK_SERVER_NAMESPACE = "heptio-ark-server" } } @@ -54,7 +58,9 @@ resource "null_resource" "setup_ark_backup" { command = </${var.aws_s3_bucket}/g' ark-0.7.1/examples/aws/00-ark-config.yaml sed -i '.original' 's//${var.aws_region}/g' ark-0.7.1/examples/aws/00-ark-config.yaml - EOT + +EOT + } provisioner "local-exec" { @@ -69,3 +75,4 @@ resource "null_resource" "setup_ark_backup" { command = "rm -rf ark ark-* credentials-ark kubeconfig.yaml v0.7.1.tar.gz" } } + diff --git a/terraform/modules/k8s-backup-s3/outputs.tf b/terraform/modules/k8s-backup-s3/outputs.tf deleted file mode 100644 index 8b137891..00000000 --- a/terraform/modules/k8s-backup-s3/outputs.tf +++ /dev/null @@ -1 +0,0 @@ - diff --git a/terraform/modules/k8s-backup-s3/variables.tf b/terraform/modules/k8s-backup-s3/variables.tf index e2c3c47e..11946cbc 100644 --- a/terraform/modules/k8s-backup-s3/variables.tf +++ b/terraform/modules/k8s-backup-s3/variables.tf @@ -1,10 +1,14 @@ -variable "rancher_api_url" {} +variable "rancher_api_url" { +} -variable "rancher_access_key" {} +variable "rancher_access_key" { +} -variable "rancher_secret_key" {} +variable "rancher_secret_key" { +} -variable "rancher_cluster_id" {} +variable "rancher_cluster_id" { +} variable "aws_access_key" { default = "" @@ -25,3 +29,4 @@ variable "aws_s3_bucket" { default = "" description = "Name of the AWS bucket where the Heptio ARK backup will be stored." } + diff --git a/terraform/modules/k8s-backup-s3/versions.tf b/terraform/modules/k8s-backup-s3/versions.tf new file mode 100644 index 00000000..ac97c6ac --- /dev/null +++ b/terraform/modules/k8s-backup-s3/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/terraform/modules/triton-rancher-k8s-host/versions.tf b/terraform/modules/triton-rancher-k8s-host/versions.tf new file mode 100644 index 00000000..ac97c6ac --- /dev/null +++ b/terraform/modules/triton-rancher-k8s-host/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/terraform/modules/triton-rancher-k8s/versions.tf b/terraform/modules/triton-rancher-k8s/versions.tf new file mode 100644 index 00000000..ac97c6ac --- /dev/null +++ b/terraform/modules/triton-rancher-k8s/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/terraform/modules/triton-rancher/versions.tf b/terraform/modules/triton-rancher/versions.tf new file mode 100644 index 00000000..ac97c6ac --- /dev/null +++ b/terraform/modules/triton-rancher/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/terraform/modules/vsphere-rancher-k8s-host/main.tf b/terraform/modules/vsphere-rancher-k8s-host/main.tf index aa8a4ad9..b86a7ae1 100644 --- a/terraform/modules/vsphere-rancher-k8s-host/main.tf +++ b/terraform/modules/vsphere-rancher-k8s-host/main.tf @@ -1,102 +1,103 @@ provider "vsphere" { - user = "${var.vsphere_user}" - password = "${var.vsphere_password}" - vsphere_server = "${var.vsphere_server}" + user = var.vsphere_user + password = var.vsphere_password + vsphere_server = var.vsphere_server allow_unverified_ssl = true } locals { - rancher_node_role = "${element(keys(var.rancher_host_labels), 0)}" + rancher_node_role = element(keys(var.rancher_host_labels), 0) } data "template_file" "install_rancher_agent" { - template = "${file("${path.module}/files/install_rancher_agent.sh.tpl")}" - - vars { - hostname = "${var.hostname}" - docker_engine_install_url = "${var.docker_engine_install_url}" - - rancher_api_url = "${var.rancher_api_url}" - rancher_cluster_registration_token = "${var.rancher_cluster_registration_token}" - rancher_cluster_ca_checksum = "${var.rancher_cluster_ca_checksum}" - rancher_node_role = "${local.rancher_node_role == "control" ? "controlplane" : local.rancher_node_role}" - rancher_agent_image = "${var.rancher_agent_image}" - - rancher_registry = "${var.rancher_registry}" - rancher_registry_username = "${var.rancher_registry_username}" - rancher_registry_password = "${var.rancher_registry_password}" + template = file("${path.module}/files/install_rancher_agent.sh.tpl") + + vars = { + hostname = var.hostname + docker_engine_install_url = var.docker_engine_install_url + rancher_api_url = var.rancher_api_url + rancher_cluster_registration_token = var.rancher_cluster_registration_token + rancher_cluster_ca_checksum = var.rancher_cluster_ca_checksum + rancher_node_role = local.rancher_node_role == "control" ? "controlplane" : local.rancher_node_role + rancher_agent_image = var.rancher_agent_image + rancher_registry = var.rancher_registry + rancher_registry_username = var.rancher_registry_username + rancher_registry_password = var.rancher_registry_password } } data "vsphere_datacenter" "dc" { - name = "${var.vsphere_datacenter_name}" + name = var.vsphere_datacenter_name } data "vsphere_datastore" "datastore" { - name = "${var.vsphere_datastore_name}" - datacenter_id = "${data.vsphere_datacenter.dc.id}" + name = var.vsphere_datastore_name + datacenter_id = data.vsphere_datacenter.dc.id } data "vsphere_resource_pool" "pool" { - name = "${var.vsphere_resource_pool_name}" - datacenter_id = "${data.vsphere_datacenter.dc.id}" + name = var.vsphere_resource_pool_name + datacenter_id = data.vsphere_datacenter.dc.id } data "vsphere_network" "network" { - name = "${var.vsphere_network_name}" - datacenter_id = "${data.vsphere_datacenter.dc.id}" + name = var.vsphere_network_name + datacenter_id = data.vsphere_datacenter.dc.id } data "vsphere_virtual_machine" "template" { - name = "${var.vsphere_template_name}" - datacenter_id = "${data.vsphere_datacenter.dc.id}" + name = var.vsphere_template_name + datacenter_id = data.vsphere_datacenter.dc.id } resource "vsphere_virtual_machine" "vm" { - name = "${var.hostname}" - resource_pool_id = "${data.vsphere_resource_pool.pool.id}" - datastore_id = "${data.vsphere_datastore.datastore.id}" + name = var.hostname + resource_pool_id = data.vsphere_resource_pool.pool.id + datastore_id = data.vsphere_datastore.datastore.id num_cpus = 2 memory = 2048 - guest_id = "${data.vsphere_virtual_machine.template.guest_id}" + guest_id = data.vsphere_virtual_machine.template.guest_id - scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}" + scsi_type = data.vsphere_virtual_machine.template.scsi_type network_interface { - network_id = "${data.vsphere_network.network.id}" - adapter_type = "${data.vsphere_virtual_machine.template.network_interface_types[0]}" + network_id = data.vsphere_network.network.id + adapter_type = data.vsphere_virtual_machine.template.network_interface_types[0] } disk { label = "disk0" - size = "${data.vsphere_virtual_machine.template.disks.0.size}" - eagerly_scrub = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}" - thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}" + size = data.vsphere_virtual_machine.template.disks[0].size + eagerly_scrub = data.vsphere_virtual_machine.template.disks[0].eagerly_scrub + thin_provisioned = data.vsphere_virtual_machine.template.disks[0].thin_provisioned } clone { - template_uuid = "${data.vsphere_virtual_machine.template.id}" + template_uuid = data.vsphere_virtual_machine.template.id } } resource "null_resource" "install_rancher_agent" { - triggers { - vsphere_virtual_machine_id = "${vsphere_virtual_machine.vm.id}" + triggers = { + vsphere_virtual_machine_id = vsphere_virtual_machine.vm.id } connection { type = "ssh" - user = "${var.ssh_user}" + user = var.ssh_user - host = "${vsphere_virtual_machine.vm.default_ip_address}" - private_key = "${file(var.key_path)}" + host = vsphere_virtual_machine.vm.default_ip_address + private_key = file(var.key_path) } provisioner "remote-exec" { inline = <