#terraform-0_12 - November 2019

57 messages

Discuss upgrading to terraform 0.12

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

November 2019
PePe Amengual
PePe Amengualabout 7 years ago(edited)
I’m working with the git::https://github.com/cloudposse/terraform-aws-rds-cluster.git?ref=0.17.0 module and when global databases are used Aurora changes the replication_source_identifier of the secondary cluster so every time we apply is trying to do and update in place, is it possible to add some sort of ignore if global databases are configured?
cytopia
cytopiaabout 7 years ago
@Erik Osterman (Cloud Posse) latest terraform-docs.awk fix: https://github.com/cloudposse/build-harness/pull/174
winter
winterabout 7 years ago
terraform is replacing the instance while enabling ebs encryption after creation of the instance. Is this expected behaviour?
PePe Amengual
PePe Amengualalmost 7 years ago
PePe Amengual
PePe Amengualalmost 7 years ago
do you guys know if is possible to extract from a provider alias the region? like aws.secondary.region ?
tweetyix
tweetyixalmost 7 years ago
PePe Amengual
PePe Amengualalmost 7 years ago
I have two provides for different regions in the same file
PePe Amengual
PePe Amengualalmost 7 years ago
so the resource block have a provider = aws.primary
PePe Amengual
PePe Amengualalmost 7 years ago
that is on a specific region
joshmyers
joshmyersalmost 7 years ago
Use the provider in a data resource to fetch the region?
PePe Amengual
PePe Amengualalmost 7 years ago
I think I’m just going to add an additional variable
PePe Amengual
PePe Amengualalmost 7 years ago
this thing runs in one region but spins up multiple dependent resources in multiple regions
joshmyers
joshmyersalmost 7 years ago
What happens if one of those regions is having availability issues? Could you keep each region a separate state?
PePe Amengual
PePe Amengualalmost 7 years ago
this is for Aurora Global DBs
PePe Amengual
PePe Amengualalmost 7 years ago
so I might not have access to the state but we do not have to touch the state even if the region is down
PePe Amengual
PePe Amengualalmost 7 years ago
I think I will separate it later
mrwacky
mrwackyalmost 7 years ago
Ok, the documentation for dynamic leaves a lot of useful examples out of the equation.
How do I do nested dynamic blocks? We have a module for aws_elasticsearch_domain that takes a cluster_config var. This can have a nested block inside.. https://www.terraform.io/docs/providers/aws/r/elasticsearch_domain.html#cluster_config
mrwacky
mrwackyalmost 7 years ago
I need to only sometimes supply zone_awareness_config..
mrwacky
mrwackyalmost 7 years ago
The dynamic/for_each syntax in 0.12 is complete trash, and the documentation is complete trash
mrwacky
mrwackyalmost 7 years ago
This is so non-obvious and poorly explained
mrwacky
mrwackyalmost 7 years ago
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
@mrwacky examples of nested dynamic blocks ^
mrwacky
mrwackyalmost 7 years ago
ha. I just gave up and passed a bunch of string variables to the module
mrwacky
mrwackyalmost 7 years ago
thanks though
loren
lorenalmost 7 years ago
It was confusing at first, but now I use it for everything
Gabe
Gabealmost 7 years ago
Hey all, new here and still new to Terraform - I’m trying to use Terraform to configure an AWS CodePipeline. It will plan and apply just fine, but the pipeline fails in the real world every time at the source stage. It seems to need additional S3 permissions and I haven’t yet figured out how to provide them. The error is Insufficient permissions The provided role does not have permissions to perform this action. Underlying error: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID:... I’ve tried a blanket S3 allow-all permission policy on both the pipeline’s associated role and the codebuild’s associated role (desperation) to no avail. - anyone got any advice?
chrism
chrismalmost 7 years ago
@Andriy Knysh (Cloud Posse) https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/pull/17 I redid the mixed type scaling based on what was done for 11. There's a bug filed on there as well regarding the variable type constraint (which tbh is easier fixed by removal / I didn't remove it from my repo and PR it due to the existing pr 😄 )
Igor
Igoralmost 7 years ago(edited)
What's up with the list/set type differences in TF0.12? Is having both actually beneficial? Seems to cause more grief than good.
loren
lorenalmost 7 years ago
Lists can have duplicate items and are ordered, sets cannot have duplicates (and I don't think are ordered)
Igor
Igoralmost 7 years ago
I understand how they're different, but it's hard to work with both at the same time (mixing for_each and count, or having to convert toset or tolist to use the correct functions)
loren
lorenalmost 7 years ago
well, it's go-based. so it is strongly typed. can't really have one object type with different properties like that
loren
lorenalmost 7 years ago
for_each requires a map or a set. that's because the value/key is used as the resource id, and the resource id must be unique. so lists are not appropriate, or would result in late failures (during apply, instead of plan)
loren
lorenalmost 7 years ago
count works with lists because the index is used as the resource id, rather than the value, so it does not matter if there are duplicate values in the list
loren
lorenalmost 7 years ago(edited)
personally, i'm abandoning count anywhere i can, and using a map with for_each instead of a set
Igor
Igoralmost 7 years ago
@loren Thanks, that helps. So I would just use each.key instead of count.index?
Igor
Igoralmost 7 years ago
Seems odd that it would use the key as the resource id, since the key can be an arbitrary string
loren
lorenalmost 7 years ago
yep
loren
lorenalmost 7 years ago
one goal with for_each is to address the problem with count where modifying the list items (changing order, removing an item, etc), would cause resources to be deleted and recreated because their index changed
loren
lorenalmost 7 years ago
for_each addresses that by mapping the resource to the value instead of the index
Igor
Igoralmost 7 years ago
👍️ Thanks for the explanation. Makes sense.
Callum Robertson
Callum Robertsonalmost 7 years ago
Hi All,

Is there a best-practice way of create a list of maps to feed into a secrets_manager_secret resource for example? I have a few maps that represent their own respective secret, with each map will keys that detail "name", "description" and "secret"?

Something like this:
[
{
name = secret_name
description = secret_description
value = secret_value
},
{
name = secret_name
description = secret_description
value = secret_value
}
]

If I was feeding this into a variable, how would I achieve this given the TYPE constraints? I thought of creating an object for this but it seems messy to have a attribute id for each map.

Be keen to understand if anyone else has done something like this in TF 12+
loren
lorenalmost 7 years ago
Looks to me like list(map(string))?
Callum Robertson
Callum Robertsonalmost 7 years ago
Can you do this? Wasn't aware you could have collection types constructed in this way?
loren
lorenalmost 7 years ago
A list of objects would be pretty clean for that example, also... If you definitely wanted every item to require those three keys...
loren
lorenalmost 7 years ago
Yeah, sure, lists of maps are great
loren
lorenalmost 7 years ago
On my phone, or I'd write out the object code for you
Callum Robertson
Callum Robertsonalmost 7 years ago
This is great @loren. I'll give it a go and come back to you on this
Callum Robertson
Callum Robertsonalmost 7 years ago
You're an animal
loren
lorenalmost 7 years ago
PePe Amengual
PePe Amengualalmost 7 years ago(edited)
Hi, is it possible to do

data "aws_vpc" "main_vpc" {
  tags = {
    provisioning = "terraform"
    environment != "prod"
  }
  provider = aws.primary
}
PePe Amengual
PePe Amengualalmost 7 years ago
actually what I need is to find a vpc that does not have an specific tag
PePe Amengual
PePe Amengualalmost 7 years ago
I have one vpc that have a tag shared = true and I need to find the other vpc that have the same tags except for that one
joshmyers
joshmyersalmost 7 years ago
Why not add the tag shared = false on the other lot and look for that...
PePe Amengual
PePe Amengualalmost 7 years ago
I thought about that too
PePe Amengual
PePe Amengualalmost 7 years ago
I think that is easier