#terraform-0_12 - September 2019

44 messages

Discuss upgrading to terraform 0.12

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

September 2019
oscar
oscarabout 7 years ago
How do I change this


names = ["ecr-1", "ecr-2", "ecr-3"]

locals {
  name  = tolist([for name in var.names : "${name}"])
}

resource "aws_ecr_repository" "default" {
  for_each = toset(var.names)
  name     = local.name[0]
}


To a sort of splat / wildcard.
I don’t want just the first index I want them all e.g. local.names[*] — what am I missing?
oscar
oscarabout 7 years ago
I’ve tried all sorts of combos
oscar
oscarabout 7 years ago
Oh lol got it working now
oscar
oscarabout 7 years ago
each.key is working again, I must have changed something else.
Maarten van der Hoef
Maarten van der Hoefabout 7 years ago
@oscarsullivan_old what are you trying to achieve with

name = tolist([for name in var.names : "${name}"])
oscar
oscarabout 7 years ago
I got it now with just a simple for_each and each.key
oscar
oscarabout 7 years ago
I think I tried so many combinations to get it working and made so many changes that I had something overly complex
oscar
oscarabout 7 years ago
ended up being a 3 liner lol
oscar
oscarabout 7 years ago
Anyone noticed how even with the Makefile below, they still end up with .terraform and .module?


 ✗ . (none) services ⨠ cat Makefile
-include ${TF_MODULE_CACHE}/Makefile

# Makefile used by Geodesic shells to operate Terraform projects

init:
	mkdir -p ${TF_MODULE_CACHE}
	terraform init
oscar
oscarabout 7 years ago
@Andriy Knysh (Cloud Posse) I know you’re familiar with this. In your previous example the Reset target does not remove .terraform — have I missed something or misconfigured and now ending up with both dirs?
oscar
oscarabout 7 years ago
---

Any way to have count and for_each on a resource block?
So:
Count for is_enabled and for_each to iterate through, say, a list of strings for ‘name’ (for example)
oscar
oscarabout 7 years ago
All I can think of is some local variable that checks if is__enabled is true and if it is the array used in the resource for_each is populated, else it is made empty as though it were ‘disabled’? But no idea if that’d just cause an unset error or make it null.. unless Null is a keyword for that
Maarten van der Hoef
Maarten van der Hoefabout 7 years ago
you can use something like this

for_each = { for rule in var.waf_rules : rule.name => rule if rule.enabled }
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
or something like this (if is_enabled is to enable/disable globally)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
for_each = var.is_enabled ? toset(var.names) : []
oscar
oscarabout 7 years ago
Oo both interesting examples. Thanks
PePe Amengual
PePe Amengualabout 7 years ago
Anyone knows a way to do in Terraform something like “fire and forget” type of operation ?
PePe Amengual
PePe Amengualabout 7 years ago
I’m creating a rds cluster and it checks for the instance to be created and it takes WAY to long
PePe Amengual
PePe Amengualabout 7 years ago
I added this :
# Make it faster by skipping some checks
  skip_get_ec2_platforms      = true
  skip_metadata_api_check     = true
  skip_region_validation      = true
  skip_credentials_validation = true
  skip_requesting_account_id  = true
PePe Amengual
PePe Amengualabout 7 years ago
but still takes a long time
PePe Amengual
PePe Amengualabout 7 years ago
and some times the connection times out
Igor
Igorabout 7 years ago
@PePe Amengual I think Terraform needs the output of the API call to update the state file
Igor
Igorabout 7 years ago
You can just run the apply in the background
PePe Amengual
PePe Amengualabout 7 years ago
that is what I thought too
PePe Amengual
PePe Amengualabout 7 years ago
and it has been
ing... [48m31s elapsed]
PePe Amengual
PePe Amengualabout 7 years ago
rds is painfull
oscar
oscarabout 7 years ago
We’re looking to use the EKS modules
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
@oscar we’ll get to it soon, sorry for the delay
oscar
oscarabout 7 years ago
Dont apologise!
oscar
oscarabout 7 years ago
I'm using the guys forks for now but let me know when I can move back to Cloudposses repos
oscar
oscarabout 7 years ago
Didn’t quite work. Some sub-module issues. I’ll just slip in a use terraform0.11 👀
PePe Amengual
PePe Amengualabout 7 years ago
terraform 0.12 still fail if data resources return nothing ?
Brandon Wilson
Brandon Wilsonabout 7 years ago
Anyone know if it’s possible to do what amounts to an else if in 0.12?
Brandon Wilson
Brandon Wilsonabout 7 years ago
I’m doing name = (var.branch == "master" ? "${var.namespace}-${var.stage}-${var.service}" : "${var.namespace}-${var.stage}-${var.service}-${var.branch}")
Brandon Wilson
Brandon Wilsonabout 7 years ago
but I want to also check for var.branch == “staging” in the middle there
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
name = var.branch == "master" ? .... : (var.branch == "staging" ? ... : ...)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
or use locals to simplify
Brandon Wilson
Brandon Wilsonabout 7 years ago
Thanks @Andriy Knysh (Cloud Posse). I’ll check into using locals for this as well, that’s a good idea.
Sharanya
Sharanyaabout 7 years ago
Components for secure UI hosting in S3
• S3 — for storing the static site
• CloudFront — for serving the static site over SSL
• AWS Certificate Manager — for generating the SSL certificates
Route53 — for routing the domain name to the correct location Did anyone come across any modules for this in terraform ?
Ruan Arcega
Ruan Arcegaabout 7 years ago
hi guys
i'm using cloudposse/terraform-aws-elasticsearch and i got this error

Error: Reference to undeclared resource

  on main.tf line 42, in module "elasticsearch":
  42:     rest.action.multi.allow_explicit_index = "true"

A managed resource "rest" "action" has not been declared in the root module.

[terragrunt] 2019/09/30 19:05:13 Hit multiple errors:
exit status 1