#terraform-0_12 - August 2019

82 messages

Discuss upgrading to terraform 0.12

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

August 2019
Julio Tain Sueiras
Julio Tain Sueirasover 7 years ago
note: 0.12.6 have been released and added for each on resource
Julio Tain Sueiras
Julio Tain Sueirasover 7 years ago
(and probably data source as well)
loren
lorenover 7 years ago
Bam! Nice!
Julio Tain Sueiras
Julio Tain Sueirasover 7 years ago
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
Julio Tain Sueirasover 7 years ago
Julio Tain Sueiras
Julio Tain Sueirasover 7 years ago
basically due to show behaviour changed in 0.12
Julio Tain Sueiras
Julio Tain Sueirasover 7 years ago
you can generate terraform code from any resource that support import
loren
lorenover 7 years ago
way cool
PePe Amengual
PePe Amengualover 7 years ago
so it is like terraforming ?
PePe Amengual
PePe Amengualover 7 years ago
Julio Tain Sueiras
Julio Tain Sueirasover 7 years ago
similar, but the nice thing about the trick above is that it apply to any resouurce
Julio Tain Sueiras
Julio Tain Sueirasover 7 years ago
not limited to aws
Julio Tain Sueiras
Julio Tain Sueirasover 7 years ago
as long as the resource support import
PePe Amengual
PePe Amengualover 7 years ago
ohhh I c ok, yep that is cool
Maarten van der Hoef
Maarten van der Hoefabout 7 years ago
Just made https://github.com/Flaconi/terraform-aws-waf-acl-rules using the for_each directive
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
hcl1 was completely string based (loose/weak typing)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
hcl2 added some strong typing by having first-class bool, number and object types
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago
also added nesting type like map, list
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago
(so you can define it as map(list(string))
Milos Backonja
Milos Backonjaabout 7 years ago
Guys, I am looking how can I tag resources dynamically, and without repeating same block of code with one change.
Milos Backonja
Milos Backonjaabout 7 years ago
# 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
Milos Backonjaabout 7 years ago
any suggestions are welcome, thanks
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
Have you looked at terraform-null-label?
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
it supports inheritance using context
Milos Backonja
Milos Backonjaabout 7 years ago
Awesome. Thanks @Erik Osterman (Cloud Posse)
Vitaliy Lobachev
Vitaliy Lobachevabout 7 years ago(edited)
Hello! I want to share with you resource:for_each and dynamic:block:for_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
Sharanyaabout 7 years ago
Hey people, looking for terraform template on vpc peering ( syntax 0.12) any help plz
joshmyers
joshmyersabout 7 years ago
Any ideas about Error: Invalid combination of "count" and "for_each" in TF 0.12 ?
joshmyers
joshmyersabout 7 years ago
What are the semantics of for_each to replicate boolean logic of count?
joshmyers
joshmyersabout 7 years ago
nvm, got it
Maarten van der Hoef
Maarten van der Hoefabout 7 years ago
🙂
joshmyers
joshmyersabout 7 years ago
Does 0.12 have the ability to do nested loops?
joshmyers
joshmyersabout 7 years ago
for_each gives you each.key / each.value
joshmyers
joshmyersabout 7 years ago
I want to loop through each.value too 🙂
Maarten van der Hoef
Maarten van der Hoefabout 7 years ago
it does, one moment
joshmyers
joshmyersabout 7 years ago
ah ha, think I can… for foo in bar
joshmyers
joshmyersabout 7 years ago
joshmyers
joshmyersabout 7 years ago
lol
Maarten van der Hoef
Maarten van der Hoefabout 7 years ago
playing with null again ? 🙂
joshmyers
joshmyersabout 7 years ago
No, playing with loops, no null
joshmyers
joshmyersabout 7 years ago
Nothing particularly complex either, sigh
joshmyers
joshmyersabout 7 years ago
back to count for me.
Addison Higham
Addison Highamabout 7 years ago
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
iG
iGabout 7 years ago
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)?
geertn
geertnabout 7 years ago
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 = "*"
    }
  }
geertn
geertnabout 7 years ago
If at all possible
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
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)
Andriy Knysh (Cloud Posse)about 7 years ago
if module.tf-var-globals.wl-trust is a list, then name = "${local.saname_prefix}-wl-tcp-${security_rule.key}"
geertn
geertnabout 7 years ago
Thanks!!
mpmsimo
mpmsimoabout 7 years ago(edited)
If using a list it must be a set(list) if you are using for_each. Otherwise maps are fine.
mpmsimo
mpmsimoabout 7 years ago
dynamic looks so useful! Haven't been able to try it out yet.
oscar
oscarabout 7 years ago
New account as that was registered to my old work email so couldn't log in on different devices.
oscar
oscarabout 7 years ago
It doesnt seem like you can use for each or dynamic in a module
Sharanya
Sharanyaabout 7 years ago
Error: The role "arn:aws:iam::474562475633: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
Sharanya
Sharanyaabout 7 years ago
The variable "lambda_settings" is required, so Terraform cannot proceed
without a defined value for it.
Sharanya
Sharanyaabout 7 years ago
anyone came across this issues
Andrew Jeffree
Andrew Jeffreeabout 7 years ago
@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.
Lakshmi Kallam
Lakshmi Kallamabout 7 years ago
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
Lakshmi Kallamabout 7 years ago
any suggestions?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
Use dynamic blocks
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
In CloudPosse GitHub, search for emr-cluster
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
It’s already in 0.12
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
Deployed it today, so should work :)
Lakshmi Kallam
Lakshmi Kallamabout 7 years ago
Thanks, Let me check that
Lakshmi Kallam
Lakshmi Kallamabout 7 years ago
and the same thing applies for having multiple steps also?
oscar
oscarabout 7 years ago
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
oscarabout 7 years ago
I just can’t seem to nail this for_each thing in 0.12 😕
oscar
oscarabout 7 years ago
NVM I gots it
oscar
oscarabout 7 years ago

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
oscarabout 7 years ago
For reference 🙂
PePe Amengual
PePe Amengualabout 7 years ago
does terraform 0.12 supports MFA properly now ?
Sharanya
Sharanyaabout 7 years ago
Did anyone Come across NPM memory Issues ?
Maarten van der Hoef
Maarten van der Hoefabout 7 years ago
oscar
oscarabout 7 years ago
@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
oscar
oscarabout 7 years ago(edited)
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)
Erik Osterman (Cloud Posse)about 7 years ago
ahk, i got it mixed up
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
erik
erikabout 7 years ago