#terraform-0_12 (2019-08)

terraform

Discuss upgrading to terraform 0.12

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

2019-08-29

maarten avatar
maarten
How to ask for help on IRC - RJ's Notes

How to ask for help properly on IRC so that you get responses faster. Also relevant to forums and mailing lists

oscar avatar
oscar

@Erik Osterman (Cloud Posse) looks like 0.12 for_each on modules is still not yet developed, it is purely reserved ATM https://github.com/hashicorp/terraform/issues/17519

for_each for modules · Issue #17519 · hashicorp/terraform
Is it possible to dynamically select map variable, e.g? Currently I am doing this: [vars.tf> locals { map1 = { name1 = &quot;foo&quot; name2 = &quot;bar&quot; } } <http://main.tf main.tf](http://vars.tf) module &quot;x1&quot; { sour…
oscar avatar
oscar

I’m either going to PR your ECR (https://github.com/cloudposse/terraform-aws-ecr) module to support for_each or work on it privately and have it as an internal module. What’s your pref as that would change a chunk of the code?

Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)

ahk, i got it mixed up

Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)

2019-08-28

oscar avatar
oscar

Can I get some input pls on for_each?

resource "aws_iam_user" "mfa_user" {
  for_each = toset(var.users)
  name = each.value
  force_destroy = true
}

resource "aws_iam_user_group_membership" "mfa" {
  user = aws_iam_user.mfa_user
  groups = [
    aws_iam_group.mfa_group.name
  ]
  depends_on = [aws_iam_user.mfa_user]
}

I’ve tried all variations of the syntax and even had the for_each inside the membership resource…

I need the users to be created from a list of names, and then I need them adding to a group. It also needs to be in that order else the group_membership resource complains about missing users (?)

oscar avatar
oscar

I just can’t seem to nail this for_each thing in 0.12

oscar avatar
oscar

NVM I gots it

oscar avatar
oscar
resource "aws_iam_user" "mfa_user" {
  for_each = toset(var.users)
  name = each.value
  force_destroy = true
}

resource "aws_iam_user_group_membership" "mfa" {
  for_each = toset(var.users)
  user = aws_iam_user.mfa_user[each.key].name
  groups = [
    aws_iam_group.mfa_group.name
  ]
  depends_on = [aws_iam_user.mfa_user]
}
oscar avatar
oscar

For reference

jose.amengual avatar
jose.amengual

does terraform 0.12 supports MFA properly now ?

Sharanya avatar
Sharanya

Did anyone Come across NPM memory Issues ?

2019-08-27

Lakshmi Kallam avatar
Lakshmi Kallam

I am trying to upgrade to 0.12.6 from 0.11.4, with aws emr cluster, I am using multiple bootstrap_action scripts. Now I am getting error: resource “aws_emr_cluster” “cluster”: 124: bootstrap_action = [

An argument named “bootstrap_action” is not expected here. Did you mean to define a block of type “bootstrap_action”?

Lakshmi Kallam avatar
Lakshmi Kallam

any suggestions?

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

Use dynamic blocks

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

In CloudPosse GitHub, search for emr-cluster

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

It’s already in 0.12

Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)
cloudposse/terraform-aws-emr-cluster

Terraform module to provision an Elastic MapReduce (EMR) cluster on AWS - cloudposse/terraform-aws-emr-cluster

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

Deployed it today, so should work :)

Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)
cloudposse/terraform-aws-emr-cluster

Terraform module to provision an Elastic MapReduce (EMR) cluster on AWS - cloudposse/terraform-aws-emr-cluster

Lakshmi Kallam avatar
Lakshmi Kallam

Thanks, Let me check that

Lakshmi Kallam avatar
Lakshmi Kallam

and the same thing applies for having multiple steps also?

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

var.bootstrap_action is a list of objects (each representing a step)

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)
cloudposse/terraform-aws-emr-cluster

Terraform module to provision an Elastic MapReduce (EMR) cluster on AWS - cloudposse/terraform-aws-emr-cluster

2019-08-25

Andrew Jeffree avatar
Andrew Jeffree

@Sharanya you’ll need to specify what module you’re using and provide some more info before anyone can give you any precise help. But the error is pretty clear that you need to set the variable lambda_settings to something appropriate for whatever requires it.

2019-08-23

Sharanya avatar
Sharanya

The variable “lambda_settings” is required, so Terraform cannot proceed without a defined value for it.

Sharanya avatar
Sharanya

anyone came across this issues

2019-08-22

oscarsullivan_old avatar
oscarsullivan_old

How do you go about creating N of a module resource when looping a list of names?

For instance I have a list of ecr repos and I want to have the module create a repo for every item in the list of strings

oscarsullivan_old avatar
oscarsullivan_old

I’m aware the for each is there for resources but I csnt seem to get it working for a module.

oscar avatar
oscar

New account as that was registered to my old work email so couldn’t log in on different devices.

oscar avatar
oscar

It doesnt seem like you can use for each or dynamic in a module

Sharanya avatar
Sharanya

Error: The role “arnawsiam:role/gc-invoicedataimport-function-role” cannot be assumed.

There are a number of possible causes of this - the most common are:

* The credentials used in order to assume the role are invalid

* The credentials do not have appropriate permission to assume the role

* The role ARN is not valid

2019-08-20

geertn avatar
geertn

Anyone know how to access the iterator count within a dynamic block? EG:

  dynamic "security_rule" {
    for_each = module.tf-var-globals.wl-trust

    content {
      name = "${local.saname_prefix}-wl-tcp-${count.index}"
      priority = "14${count.index}"
      direction = "Inbound"
      access = "Allow"
      protocol = "Tcp"
      source_port_range = "*"
      destination_port_range = "80"
      source_address_prefix = "${security_rule.value.ip}"
      description = "${security_rule.value.description}"
      destination_address_prefix = "*"
    }
  }
Vitaliy Lobachev avatar
Vitaliy Lobachev

Yes I do : dynamic “website” { for_each = contains(each.value.type, “website”) ? [each.value.website] : [] content { error_document = each.value.website.error_document index_document = each.value.website.index_document } }

https://github.com/devops-best-practices/terraform-best-practice/blob/master/s3.tf

devops-best-practices/terraform-best-practice

Contribute to devops-best-practices/terraform-best-practice development by creating an account on GitHub.

Vitaliy Lobachev avatar
Vitaliy Lobachev

===================== for_each = contains(each.value.type, “website”) ? [each.value.website] : [] =====================

geertn avatar
geertn

If at all possible

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)
The iterator object  has two attributes:

key is the map key or list element index for the current element. If the for_each expression produces a set value then key is identical to value and should not be used.
value is the value of the current element.
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)
Expressions - Configuration Language - Terraform by HashiCorp

The Terraform language allows the use of expressions to access data exported by resources and to transform and combine that data to produce other values.

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

if module.tf-var-globals.wl-trust is a list, then name = "${local.saname_prefix}-wl-tcp-${security_rule.key}"

geertn avatar
geertn

Thanks!!

mpmsimo avatar
mpmsimo

If using a list it must be a set(list) if you are using for_each. Otherwise maps are fine.

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

for_each could be used with any collection type

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

map, list, set

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

it does not have to be always a set

mpmsimo avatar
mpmsimo

Hmm, I remember trying to pass in a list of strings and explicitly getting a failure for this.

mpmsimo avatar
mpmsimo

I could of been doing something weird, as it was a local variable being passed into a module, the module manipulating that var and creating a list.

mpmsimo avatar
mpmsimo

Lots of places where I could of gone wrong I think

mpmsimo avatar
mpmsimo
Error: Invalid for_each argument

  on .terraform/modules/inventor/github.tf line 56, in resource "github_repository_webhook" "discord":
  56:   for_each = var.discord_webhooks

The given "for_each" argument value is unsuitable: the "for_each" argument
must be a map, or set of strings, and you have provided a value of type list
of dynamic.
mpmsimo avatar
mpmsimo

Where var.discord_webhooks was something like: ["a8efu9a8fuae8u9f8eua98fu", "a3ijoij40958092840932j"]

mpmsimo avatar
mpmsimo

Within the var definition, it was associated explicitly with the list type and when I had changed it to set(list) was resolved.

mpmsimo avatar
mpmsimo

0.12.6 for reference, unsure if it’s applicable all the time but in my specific case it helped me.

mpmsimo avatar
mpmsimo

dynamic looks so useful! Haven’t been able to try it out yet.

mpmsimo avatar
mpmsimo

Would help me be more DRY with file provisioners in some of the resources I have. Any sub-resource block expansion really

2019-08-19

2019-08-16

2019-08-15

joshmyers avatar
joshmyers

Any ideas about Error: Invalid combination of "count" and "for_each" in TF 0.12 ?

joshmyers avatar
joshmyers

What are the semantics of for_each to replicate boolean logic of count?

joshmyers avatar
joshmyers

nvm, got it

maarten avatar
maarten

joshmyers avatar
joshmyers

Does 0.12 have the ability to do nested loops?

joshmyers avatar
joshmyers

for_each gives you each.key / each.value

joshmyers avatar
joshmyers

I want to loop through each.value too

maarten avatar
maarten

it does, one moment

joshmyers avatar
joshmyers

ah ha, think I can… for foo in bar

joshmyers avatar
joshmyers
joshmyers avatar
joshmyers

lol

maarten avatar
maarten

playing with null again ?

joshmyers avatar
joshmyers

No, playing with loops, no null

joshmyers avatar
joshmyers

Nothing particularly complex either, sigh

joshmyers avatar
joshmyers

back to count for me.

Addison Higham avatar
Addison Higham

hey, not sure where the best place to ask this is, curious if there is a place where ya’ll are tracking compatibility with terraform 0.12? I am making use primarily of https://github.com/cloudposse/terraform-aws-eks-workers and https://github.com/cloudposse/terraform-aws-eks-cluster (great modules btw!), happy also to help get them ported, but just was curious if you have a guide on how you are approaching that? I noticed it looks like you are maintaining a 0.11 branch

cloudposse/terraform-aws-eks-workers

Terraform module to provision an AWS AutoScaling Group, IAM Role, and Security Group for EKS Workers - cloudposse/terraform-aws-eks-workers

cloudposse/terraform-aws-eks-cluster

Terraform module for provisioning an EKS cluster. Contribute to cloudposse/terraform-aws-eks-cluster development by creating an account on GitHub.

igeorgopoulos avatar
igeorgopoulos

I have an existing aws ecs cluster (made by hand) and would like to update it by using terraform. Is there any documentation for updating existing aws services (alb, ecr, ecs)?

github140 avatar
github140

Check terraform import.

1
mpmsimo avatar
mpmsimo

Alternatively, if you are doing imports at scale: https://github.com/dtan4/terraforming

dtan4/terraforming

Export existing AWS resources to Terraform style (tf, tfstate) - dtan4/terraforming

2019-08-12

Vitaliy Lobachev avatar
Vitaliy Lobachev

Hello! I want to share with you resource:for_each and dynamicfor_each construction for terraform 12.6 . Hope this helps you work with large arrays of resources. https://github.com/devops-best-practices/terraform-best-practice/blob/master/s3.tf

Sharanya avatar
Sharanya

Hey people, looking for terraform template on vpc peering ( syntax 0.12) any help plz

2019-08-08

Milos Backonja avatar
Milos Backonja

Awesome. Thanks @Erik Osterman (Cloud Posse)

2019-08-07

Milos Backonja avatar
Milos Backonja

Guys, I am looking how can I tag resources dynamically, and without repeating same block of code with one change.

Milos Backonja avatar
Milos Backonja
# Resource 1
tags = merge(
    var.tags,
    map(
      "Name", format("dev-bastion-0%s.${var.domain}",count.index+1),
      "type", "bastion"
    )
  )
  
# Resource 2

tags = merge(
    var.tags,
    map(
      "Name", format("dev-app-0%s.${var.domain}",count.index+1),
      "type", "app"
    )
  )
Milos Backonja avatar
Milos Backonja

any suggestions are welcome, thanks

Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)

Have you looked at terraform-null-label?

Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)
cloudposse/terraform-null-label

Terraform Module to define a consistent naming convention by (namespace, stage, name, [attributes]) - cloudposse/terraform-null-label

Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)

it supports inheritance using context

2019-08-06

AgustínGonzalezNicolini avatar
AgustínGonzalezNicolini

hi guys, quick one

AgustínGonzalezNicolini avatar
AgustínGonzalezNicolini

is hcl string or weak type?

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

hcl1 was completely string based (loose/weak typing)

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

hcl2 added some strong typing by having first-class bool, number and object types

AgustínGonzalezNicolini avatar
AgustínGonzalezNicolini

thanks!

Julio Tain Sueiras avatar
Julio Tain Sueiras

also added nesting type like map, list

1
Julio Tain Sueiras avatar
Julio Tain Sueiras

(so you can define it as map(list(string))

2019-08-05

maarten avatar
maarten

Just made https://github.com/Flaconi/terraform-aws-waf-acl-rules using the for_each directive

Flaconi/terraform-aws-waf-acl-rules

Module for simple management of WAF Rules and the ACL - Flaconi/terraform-aws-waf-acl-rules

4

2019-08-02

Julio Tain Sueiras avatar
Julio Tain Sueiras

P.S. since I am not sure if anybody used this trick, but someone on reddit ask the question and I did a small recording of it

Julio Tain Sueiras avatar
Julio Tain Sueiras

basically due to show behaviour changed in 0.12

Julio Tain Sueiras avatar
Julio Tain Sueiras

you can generate terraform code from any resource that support import

loren avatar
loren

way cool

jose.amengual avatar
jose.amengual

so it is like terraforming ?

jose.amengual avatar
jose.amengual
dtan4/terraforming

Export existing AWS resources to Terraform style (tf, tfstate) - dtan4/terraforming

Julio Tain Sueiras avatar
Julio Tain Sueiras

similar, but the nice thing about the trick above is that it apply to any resouurce

Julio Tain Sueiras avatar
Julio Tain Sueiras

not limited to aws

Julio Tain Sueiras avatar
Julio Tain Sueiras

as long as the resource support import

jose.amengual avatar
jose.amengual

ohhh I c ok, yep that is cool

    keyboard_arrow_up