#terraform-0_12 - October 2019

41 messages

Discuss upgrading to terraform 0.12

Archive: https://archive.sweetops.com/terraform-0_12/

October 2019
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
New features:
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
1. A complete working example https://github.com/cloudposse/terraform-aws-eks-cluster/tree/master/examples/complete

2. Automatic tests (bats and terratest) to lint the code and provision the example on AWS https://github.com/cloudposse/terraform-aws-eks-cluster/tree/master/test

3. Codefresh pipeline to run the tests (it provisions the cluster on AWS test account and then checks all the outputs for validity)
https://github.com/cloudposse/terraform-aws-eks-cluster/blob/master/codefresh/test.yml

4. You can specify additional IAM Roles, Users and AWS accounts to be added to the Auth ConfigMap to allow authenticating to the EKS cluster
https://github.com/cloudposse/terraform-aws-eks-cluster/blob/master/configmap-auth.yaml.tpl#L9-L19
https://github.com/cloudposse/terraform-aws-eks-cluster/blob/master/variables.tf#L120-L148

5. The Auth ConfigMap accepts a list of worker node ARNs to allow many different worker groups using diff EC2 instances to join the same EKS cluster
https://github.com/cloudposse/terraform-aws-eks-cluster/blob/master/configmap-auth.yaml.tpl#L8
https://github.com/cloudposse/terraform-aws-eks-cluster/blob/master/variables.tf#L75
https://github.com/cloudposse/terraform-aws-eks-cluster/blob/master/examples/complete/main.tf#L89

6. To apply the Auth ConfigMap, the module does not construct kubeconfig anymore. Instead it reads kubeconfig from the cluster after it gets provisioned
https://github.com/cloudposse/terraform-aws-eks-cluster/blob/master/auth.tf#L87
(thanks to @oscar for the ideas)

7. The automatic test now waits for all worker nodes to join the EKS cluster
https://github.com/cloudposse/terraform-aws-eks-cluster/blob/master/test/src/examples_complete_test.go#L81-L122


Waiting for worker nodes to join the EKS cluster                                                                                                                 
Worker Node ip-172-16-119-111.us-east-2.compute.internal has joined the EKS cluster at 2019-10-01 00:47:51 +0000 UTC                                             
Worker Node ip-172-16-155-103.us-east-2.compute.internal has joined the EKS cluster at 2019-10-01 00:48:01 +0000 UTC                                             
All worker nodes have joined the EKS cluster
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
amazing job as usual @Andriy Knysh (Cloud Posse)
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
really like the outcome
oscar
oscarabout 7 years ago
👏 🙌
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
this is a very interesting article https://kubedex.com/90-days-of-aws-eks-in-production
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
the additional settings it describes can be set here
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
When you create an EKS cluster, the user that actually creates the cluster is the only one that can access the cluster by default.  Even IAM Administrator users can't login.  This seems to be due to the way AWS bootstraps the cluster behind the scenes in AWS-land.  Once the cluster is up, you can add users as per normal as you might in any Kubernetes setup.

My recommendation, in a production environment, to use an IAM role to create the cluster.
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
tweetyix
tweetyixabout 7 years ago
Hi, does anybody know a Ruby hack/gem to load HCL2 files into a ruby objects?
PePe Amengual
PePe Amengualabout 7 years ago(edited)
Hi, I was trying to dynamically create some resources in 0.12 and I I do not know if this is possible :
resource "aws_vpc_endpoint_route_table_association" "main_us_east_2" {
  count           = length(local.private_subnet_ids_us_east_2)
  route_table_id  = HERE I need the route _table_id for the subnet_id[count.index]
  vpc_endpoint_id = aws_vpc_endpoint.s3_us_east_2.id
  provider        = aws.primary
}

is it possible to do something like that ? like an inline data resource lookup ?
Sharanya
Sharanyaabout 7 years ago
Create Jenkinsfile to deploy UI code to S3 bucket. Any help ?
PePe Amengual
PePe Amengualabout 7 years ago
you need to use something like withAws jenkins plugin and then the aws s3 sync command, there is many examples out there on how to do this
PePe Amengual
PePe Amengualabout 7 years ago
Is it possible in 0.12 to create resources in two regions without having to run TF twice passing the region as a var ?
PePe Amengual
PePe Amengualabout 7 years ago(edited)
like provider = [ aws.primary, aws.secondary]
Sharanya
Sharanyaabout 7 years ago
Lookin for a terraform Module For - RDS- Instance Configuration : SQL Server Standard 2017, 2017 v14
Gocho
Gochoabout 7 years ago
Hi @all

I'm wondering how to deal with terraform 0.12 update.

Say I have 3 terraform repositories, A, B and ...tadam : C!
Both B & C rely on A states (mututlizaton of some components)
/--------B
A ------/
\---------- C

(Please note my graphical skills 🙂 )

All repositories are in terraform 0.11.
What would be the best way to achieve that (and avoid conflicts) ?
Can I simply update B then A and C ? Or should I take care about a particular order ?

Is it possible to do it in multiple time ? like doing repo A first while still updating repos B and C (so a 0.11 repo references a 0.12 state), then deal with others repos few weeks/months later.

The main point is that I would avoid any compatibility issue

Any advice is welcome :)
Igor
Igorabout 7 years ago
Is there a good pattern for overriding input variables
Igor
Igorabout 7 years ago
For example, if I have a big map as a default variable on the module, and I want to provide an override to a part of that map, instead of giving the whole list in?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
you can make the var an object with specified item types. For those items that you don’t want to provide a specific type, you can use any. For default values that you don’t want to specify, you can use null
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
in this case you could provide a part of object as input with only the necessary fields specified
loren
lorenabout 7 years ago
my gosh, i love love love for_each and for expressions ❤️
winter
winterabout 7 years ago
In the dynamic content block, any ideas on how to add if-else condition ?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
(for_each can iterate not only over the existing collection, but over a sequence you create using some expressions)
winter
winterabout 7 years ago(edited)
Thanks @Andriy Knysh (Cloud Posse) , I am looking for something like
for_each = [for s in [{"name":"abc"},{"name":"xyz"}]
if(s.name==abc)
{content {...}}
if(s.name=xyz)
{content{..}}
winter
winterabout 7 years ago
What is the variable type for this kind of data in terraform?
security_group_rules:
- from_port: 49152
to_port: 65535
protocol: tcp
source: [10.0.0.0/8,172.16.0.0/12,192.168.0.0/16]
- from_port: 0
to_port: 0
protocol: "-1"
source: [10.0.0.0/8,172.16.0.0/12,192.168.0.0/16]
- from_port: 53
to_port: 53
protocol: udp
source: source: [10.0.0.0/8,172.16.0.0/12,192.168.0.0/16]
winter
winterabout 7 years ago
Thank you.
loren
lorenabout 7 years ago
new gotcha introduced in tf 0.12.11... bummed. i really was liking the ability to use the 0-index everywhere to reference attributes of optional resources... linking straight to the workaround: https://github.com/hashicorp/terraform/issues/23222#issuecomment-547462883
PePe Amengual
PePe Amengualabout 7 years ago(edited)
@Andriy Knysh (Cloud Posse) I’m trying the new version : https://github.com/cloudposse/terraform-aws-ecs-alb-service-task?ref=0.17.0 and I’m setting a ALB so I added this :
ecs_load_balancers                = [
  {
    container_name = module.webworker_server_label.id
    container_port = var.container_port
    target_group_arn = local.alb_default_target_group_arn
  }
that is how is supposed to look like ?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
ecs_load_balancers                = [
  {
    container_name = module.webworker_server_label.id
    container_port = var.container_port
    target_group_arn = local.alb_default_target_group_arn
    elb_name = null
  }
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
set elb_name to null since it’s in the var definition, but is not required for ALB
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
elb_name - (Required for ELB Classic) The name of the ELB (Classic) to associate with the service.
target_group_arn - (Required for ALB/NLB) The ARN of the Load Balancer target group to associate with the service.
PePe Amengual
PePe Amengualabout 7 years ago
got it working
PePe Amengual
PePe Amengualabout 7 years ago
awesome
PePe Amengual
PePe Amengualabout 7 years ago
I had a bit of trouble with the autoscaling group module
PePe Amengual
PePe Amengualabout 7 years ago(edited)
block_device_mappings = [
    {
      device_name = var.device_name
      no_device    = false
      virtual_name = var.device_name
      ebs = {
          delete_on_termination = true
          encrypted = true
          iops = 0
          snapshot_id = ""
          kms_key_id = data.aws_kms_key.cluster.arn
          volume_size = var.volume_size
          volume_type = var.volume_type
      }
    }
  ]
PePe Amengual
PePe Amengualabout 7 years ago
after many iterations 🙂