Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
fix: More compatibility fixes for Terraform v0.13 and aws v3 (terrafo…
Browse files Browse the repository at this point in the history
…rm-aws-modules#976)

Additional support for Terraform v0.13 and aws v3!
- The update to the vpc module in examples was, strictly speaking, unnecessary but it adds the terraform block with supported versions.
- Update for iam module in the example was very necessary to support new versions
- Workaround for "Provider produced inconsistent final plan" when creating ASGs at the same time as the cluster. See  hashicorp/terraform-provider-aws#14085 for full details.
- Blacklist 0.13.0 as it was too strict when migrating from aws v2 to v3 about dropped attributes.
  • Loading branch information
dpiddockcmp authored and BARRY Thierno Ibrahima (Canal Plus Prestataire) committed Oct 25, 2020
1 parent 8b6d7d9 commit 0e9383c
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 56 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a

| Name | Version |
|------|---------|
| terraform | >= 0.12.9 |
| terraform | >= 0.12.9, != 0.13.0 |
| aws | >= 2.55.0 |
| kubernetes | >= 1.11.1 |
| local | >= 1.4 |
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ resource "aws_security_group" "all_worker_mgmt" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.6.0"
version = "2.47.0"

name = "test-vpc"
cidr = "10.0.0.0/16"
Expand Down
2 changes: 1 addition & 1 deletion examples/irsa/irsa.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "iam_assumable_role_admin" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
version = "~> v2.6.0"
version = "2.14.0"
create_role = true
role_name = "cluster-autoscaler"
provider_url = replace(module.eks.cluster_oidc_issuer_url, "https://", "")
Expand Down
2 changes: 1 addition & 1 deletion examples/irsa/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ data "aws_caller_identity" "current" {}

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.6.0"
version = "2.47.0"
name = "test-vpc"
cidr = "10.0.0.0/16"
azs = data.aws_availability_zones.available.names
Expand Down
2 changes: 1 addition & 1 deletion examples/launch_templates/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resource "random_string" "suffix" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.6.0"
version = "2.47.0"

name = "test-vpc-lt"
cidr = "10.0.0.0/16"
Expand Down
2 changes: 1 addition & 1 deletion examples/managed_node_groups/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resource "random_string" "suffix" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2.6"
version = "2.47.0"

name = "test-vpc"
cidr = "172.16.0.0/16"
Expand Down
2 changes: 1 addition & 1 deletion examples/secrets_encryption/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ resource "aws_kms_key" "eks" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.6.0"
version = "2.47.0"

name = "test-vpc"
cidr = "10.0.0.0/16"
Expand Down
2 changes: 1 addition & 1 deletion examples/spot_instances/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resource "random_string" "suffix" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.6.0"
version = "2.47.0"

name = "test-vpc-spot"
cidr = "10.0.0.0/16"
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 0.12.9"
required_version = ">= 0.12.9, != 0.13.0"

required_providers {
aws = ">= 2.55.0"
Expand Down
55 changes: 31 additions & 24 deletions workers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,31 +102,38 @@ resource "aws_autoscaling_group" "workers" {
}
}

tags = concat(
[
{
"key" = "Name"
"value" = "${aws_eks_cluster.this[0].name}-${lookup(var.worker_groups[count.index], "name", count.index)}-eks_asg"
"propagate_at_launch" = true
},
{
"key" = "kubernetes.io/cluster/${aws_eks_cluster.this[0].name}"
"value" = "owned"
"propagate_at_launch" = true
},
{
"key" = "k8s.io/cluster/${aws_eks_cluster.this[0].name}"
"value" = "owned"
"propagate_at_launch" = true
},
],
local.asg_tags,
lookup(
var.worker_groups[count.index],
"tags",
local.workers_group_defaults["tags"]
dynamic "tag" {
for_each = concat(
[
{
"key" = "Name"
"value" = "${aws_eks_cluster.this[0].name}-${lookup(var.worker_groups[count.index], "name", count.index)}-eks_asg"
"propagate_at_launch" = true
},
{
"key" = "kubernetes.io/cluster/${aws_eks_cluster.this[0].name}"
"value" = "owned"
"propagate_at_launch" = true
},
{
"key" = "k8s.io/cluster/${aws_eks_cluster.this[0].name}"
"value" = "owned"
"propagate_at_launch" = true
},
],
local.asg_tags,
lookup(
var.worker_groups[count.index],
"tags",
local.workers_group_defaults["tags"]
)
)
)
content {
key = tag.value.key
value = tag.value.value
propagate_at_launch = tag.value.propagate_at_launch
}
}

lifecycle {
create_before_destroy = true
Expand Down
54 changes: 31 additions & 23 deletions workers_launch_template.tf
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ resource "aws_autoscaling_group" "workers_launch_template" {
}
}
}

dynamic launch_template {
iterator = item
for_each = (lookup(var.worker_groups_launch_template[count.index], "override_instance_types", null) != null) || (lookup(var.worker_groups_launch_template[count.index], "on_demand_allocation_strategy", local.workers_group_defaults["on_demand_allocation_strategy"]) != null) ? [] : list(var.worker_groups_launch_template[count.index])
Expand Down Expand Up @@ -178,30 +179,37 @@ resource "aws_autoscaling_group" "workers_launch_template" {
}
}

tags = concat(
[
{
"key" = "Name"
"value" = "${aws_eks_cluster.this[0].name}-${lookup(
var.worker_groups_launch_template[count.index],
"name",
count.index,
)}-eks_asg"
"propagate_at_launch" = true
},
{
"key" = "kubernetes.io/cluster/${aws_eks_cluster.this[0].name}"
"value" = "owned"
"propagate_at_launch" = true
},
],
local.asg_tags,
lookup(
var.worker_groups_launch_template[count.index],
"tags",
local.workers_group_defaults["tags"]
dynamic "tag" {
for_each = concat(
[
{
"key" = "Name"
"value" = "${aws_eks_cluster.this[0].name}-${lookup(
var.worker_groups_launch_template[count.index],
"name",
count.index,
)}-eks_asg"
"propagate_at_launch" = true
},
{
"key" = "kubernetes.io/cluster/${aws_eks_cluster.this[0].name}"
"value" = "owned"
"propagate_at_launch" = true
},
],
local.asg_tags,
lookup(
var.worker_groups_launch_template[count.index],
"tags",
local.workers_group_defaults["tags"]
)
)
)
content {
key = tag.value.key
value = tag.value.value
propagate_at_launch = tag.value.propagate_at_launch
}
}

lifecycle {
create_before_destroy = true
Expand Down

0 comments on commit 0e9383c

Please sign in to comment.