Skip to content

Commit

Permalink
Update providers to terraform 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
kusor committed Jun 8, 2020
1 parent 557d65b commit 876bdd4
Show file tree
Hide file tree
Showing 79 changed files with 1,064 additions and 839 deletions.
62 changes: 34 additions & 28 deletions terraform/modules/aks-rancher-k8s/main.tf
Expand Up @@ -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
}
}

Expand All @@ -56,23 +57,28 @@ 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
}
}

provisioner "local-exec" {
command = "rm ${local.kube_config_path}"
}
}

9 changes: 5 additions & 4 deletions 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")}"
}
value = data.external.rancher_cluster.result["ca_checksum"]
}

22 changes: 15 additions & 7 deletions terraform/modules/aks-rancher-k8s/variables.tf
Expand Up @@ -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"
Expand All @@ -42,4 +48,6 @@ variable "k8s_version" {
default = "1.9.6"
}

variable "node_count" {}
variable "node_count" {
}

4 changes: 4 additions & 0 deletions terraform/modules/aks-rancher-k8s/versions.tf
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}
71 changes: 35 additions & 36 deletions terraform/modules/aws-rancher-k8s-host/main.tf
@@ -1,68 +1,67 @@
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"
}
}

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
}

1 change: 0 additions & 1 deletion terraform/modules/aws-rancher-k8s-host/outputs.tf

This file was deleted.

9 changes: 6 additions & 3 deletions terraform/modules/aws-rancher-k8s-host/variables.tf
Expand Up @@ -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."
}

Expand Down Expand Up @@ -92,3 +94,4 @@ variable "ebs_volume_size" {
default = ""
description = "The size of the volume, in GiBs."
}

4 changes: 4 additions & 0 deletions terraform/modules/aws-rancher-k8s-host/versions.tf
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}

0 comments on commit 876bdd4

Please sign in to comment.