#terraform - December 2019

December 2019
Julio Tain Sueiras
Julio Tain Sueirasalmost 7 years ago
TIL that terraform support list explode notation( the three dot)
Maarten van der Hoef
Maarten van der Hoefalmost 7 years ago
merge(local.list_of_maps...)

amazing stuff
Pierre Humberdroz
Pierre Humberdrozalmost 7 years ago
hey,

I currently have to split up a terraform project into multipile ones since the providers needs data from a resource.

Does anyone have an idea on how to share the state / resources?
For example I have azure Database and would like to use the terraform postgres provider.
I would use the data source but the name I generate for the database has a random string attached to it.
C
Cloud Possealmost 7 years ago
:zoom: Join us for "Office Hours" every Wednesday 11:30AM (PST, GMT-7) via Zoom.

This is an opportunity to ask us questions on terraform and get to know others in the community on a more personal level. Next one is Dec 11, 2019 11:30AM.

👉️ Register for Webinar

:slack: #office-hours (our channel)
Mahesh
Maheshalmost 7 years ago(edited)
Hi Guys, do we really have to tag VPC, to get a EKS cluster created? does the subnet level tagging will do as well?
 tags = {
    "<http://kubernetes.io/cluster/$|kubernetes.io/cluster/$>{local.cluster_name}" = "shared"
  }

asking this because we dont have permissions to add tags at VPC level but we can at Subnet level, Couldn't find much info hence asking this.
Chris Fowles
Chris Fowlesalmost 7 years ago
i think when i was playing around with stuff it was working without the vpc tags but i have no idea what piece depends on it and i'd be very hesitant to move forward without it
curious deviant
curious deviantalmost 7 years ago
I agree completely with @Chris Fowles. While spinning my EKS cluster with TF, I forgot to tag my VPC appropriately. It seemed to work fine for the tests I carried out (deploy an API with an external ELB). However I fixed it once I caught it since it is indeed recommended by AWS
Reinholds Zviedris
Reinholds Zviedrisalmost 7 years ago
Hi all! Quick question about TF - is it possible to check in AWS if private IP address in subnet is taken or not?
giphy
giphyalmost 7 years ago
Reinholds Zviedris
Reinholds Zviedrisalmost 7 years ago(edited)
I’m writing a TF script to deploy Exasol into AWS - it ties to specific IPs where first is for management node and following are for DB nodes. I’m able to get CIDR of VPC subnet and using cirdhost assign address to network interface - the only thing missing is precaution to check whether this address isn’t already taken in the subnet.
stobiewankenobi
stobiewankenobialmost 7 years ago
Terraform support for the new AWS EKS Fargate feature.
stobiewankenobi
stobiewankenobialmost 7 years ago
Ah looks like a provider dev put one in just after me: https://github.com/terraform-providers/terraform-provider-aws/issues/11110
Wayne Johnson
Wayne Johnsonalmost 7 years ago(edited)
Hello all. Forgive me, but I'm new to terraform as well as CloudPasse. I do have an issue that may or may not be a bug.
I tried to use terraform-aws-cloudfront-s3-cdn, but am geting the error:
Error downloading modules: Error loading modules: module cdn: Error parsing .terraform\modules\8b3cb57814301845ecb9970841a29803\main.tf: At 3:16: Unknown token: 3:16 IDENT var.namespace
Looking at the code I see:
module "origin_label" {
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.4.0"
namespace = var.namespace
stage = var.stage
name = var.name
delimiter = var.delimiter
attributes = compact(concat(var.attributes, ["origin"]))
tags = var.tags
}
Shouldn't that be
namespace = ${var.namespace}
??
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
@Wayne Johnson you’re using TF 0.12 version of the module, but with terraform binary 0.11
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
Either pin a module to a release for 0.11, or use terraform binary 0.12
Wayne Johnson
Wayne Johnsonalmost 7 years ago
Thanks. I'll look into upgrading.
getSurreal
getSurrealalmost 7 years ago
Since terraform-docs doesn't support TF 0.12 yet, how are you guys maintaining your module docs?
Bruce
Brucealmost 7 years ago
Hey! Does anyone have a good example of creating dynamic blocks or content for the aws_security_group_rule resource? I need to create an ingress resource that has quite a few rules.
Maarten van der Hoef
Maarten van der Hoefalmost 7 years ago
have you thought of using the largest community module for security groups ?
Bruce
Brucealmost 7 years ago
I have in the past but in this instance I am importing an existing security group. I wasn't sure if this fits the use case.
Maarten van der Hoef
Maarten van der Hoefalmost 7 years ago
what about creating a new security group and applying next to the old one
Maarten van der Hoef
Maarten van der Hoefalmost 7 years ago
and then drop the old one
Bruce
Brucealmost 7 years ago
I think that's what I am going to have to do. Thanks for the help 👍️😁
Hugo Lesta
Hugo Lestaalmost 7 years ago
Hello there, do you know any aws application load balancer terraform module?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
@Hugo Lesta ^
Hugo Lesta
Hugo Lestaalmost 7 years ago
THanks @Andriy Knysh (Cloud Posse) 😄
getSurreal
getSurrealalmost 7 years ago
On your terraform modules why do you choose to reference resources that have a count for enable/disable using a join() instead of [0]?
join("", aws_ecr_repository.default.*.name)
aws_ecr_repository.default[0].name
getSurreal
getSurrealalmost 7 years ago
resource "aws_ecr_repository" "default" {
  count = var.enabled ? 1 : 0
  name  = var.use_fullname ? module.label.id : module.label.name

  image_scanning_configuration {
    scan_on_push = var.scan_images_on_push
  }

  tags = module.label.tags
}

resource "aws_ecr_lifecycle_policy" "default" {
  count      = var.enabled ? 1 : 0
  repository = join("", aws_ecr_repository.default.*.name)

More context
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
join always works regardless of whether the resource list is empty or not
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
and it worked in TF 0.11 (.0. or [0] did not)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
if enabled=false, this will not work aws_ecr_repository.default[0].name
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
b/c the list is empty
getSurreal
getSurrealalmost 7 years ago
that makes sense. thanks for explaining!
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
in TF 0.12, the ternary operator could be used: var name = var.enabled ? aws_ecr_repository.default[0].name : “”
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
which did not work in TF 0.11 b/c it always evaluated both sides
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
and got errors on getting the name for an item from the empty list
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
join works in all cases in 0.11 and 0.12
getSurreal
getSurrealalmost 7 years ago
good to know! thanks again
Brij S
Brij Salmost 7 years ago
does anyone know how to transfer state from TFE to s3?
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
@Brij S you would need to add the configuration in terraform for that https://www.terraform.io/docs/backends/types/s3.html
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
just make sure the bucket is not public and it has versioning enabled
Pierre-Yves
Pierre-Yvesalmost 7 years ago(edited)
Hello,
I am new to terraform.
Terraform plan don't catch all issue and often they are discovered during the terraform apply .
How do you validate the terraform apply before pushing in production ? is that the purpose of workspace ?
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
Hi Pierre, that is usualy because of the api
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
e.g. the most common thing is when you've policies, plan doesn't have a way to validate a policy in aws
Pierre-Yves
Pierre-Yvesalmost 7 years ago
yes, I know
but then should I deploy like this ?
create new workspace -> deploy to test -> validate -> delete all resource in the test workspace -> deploy to prod workspace
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
hmm that's a good question
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
I think you'll find this tool useful
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
Pierre-Yves
Pierre-Yvesalmost 7 years ago
ha nice I found a kitchen-terraform module , I'll check this
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
👍️
Brij S
Brij Salmost 7 years ago
@Nikola Velkovski if I change the backend to s3, wont it try to destroy the current resources and rebuild them?
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
nope
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
it will seamlessy migrate to the new backend
Brij S
Brij Salmost 7 years ago
so let me get this straight, I simply switch the backend to s3, run tf init/plan/apply etc and it will not try to destroy the already created resources and say no changes necessary?
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
yup
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
you'll see on STDOUT, terraform will ask you if you would like to migrate to the new backend and so on.
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
beer is on me if that's not the case 😄
Nikola Velkovski
Nikola Velkovskialmost 7 years ago
just joking
Michael Kolb
Michael Kolbalmost 7 years ago(edited)
Does anyone know if there is a way to group resource variables in the .tfvars file by the uniquely named resource? An example would be where I have 2 AWS RDS resources that share the same variable names, but I want the variable inputs to be unique for each resource. I know that this can be done with a module:
terraform.tfvars file
module_name = {
engine = “postgres”
engine_version = “11.5"
}
However, I would like to do this without having to create a module.
Bruce
Brucealmost 7 years ago(edited)
Has anyone used modules to import existing resources?
Bruce
Brucealmost 7 years ago
Can the RDS module be used for creating a cross region replica?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
it’s for creating cross-region replicas. PR https://github.com/cloudposse/terraform-aws-rds-replica/pull/4/files added possibility to create replicas in the same region as the master
Bruce
Brucealmost 7 years ago
thanks @Andriy Knysh (Cloud Posse)!
Pierre-Yves
Pierre-Yvesalmost 7 years ago(edited)
is there some naming convention recommended when naming resources ? ( like in some programming language )
should my resource be named az_vnet_internal or azVnetInternal ? what about the object name ?
how would you rewrite the resource below ?

resource "azurerm_virtual_network" "internal" {
  name                = "az_vnet_internal"
  ...
}
C
Cloud Possealmost 7 years ago
:zoom: Join us for "Office Hours" every Wednesday 11:30AM (PST, GMT-7) via Zoom.

This is an opportunity to ask us questions on terraform and get to know others in the community on a more personal level. Next one is Dec 18, 2019 11:30AM.

👉️ Register for Webinar

:slack: #office-hours (our channel)
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
Thanks to @Andriy Knysh (Cloud Posse) we now have support for AWS-managed EKS node pools: https://github.com/cloudposse/terraform-aws-eks-node-group
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago(edited)
support for EKS Fargate node pools coming in a few hours 😃
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
---
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
anyone have any prior art for a terraform provider that downloads binary dependencies?
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
e.g. imagine a terraform provider that wrapped a cli tool
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago(edited)
that provider would depend on the cli tool in order to function
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
@Andriy Knysh (Cloud Posse) has just finished implementing support for EKS Fargate node pools!
PePe Amengual
PePe Amengualalmost 7 years ago(edited)
Do you guys see any problems of adding
lifecycle {
    create_before_destroy = true
  }

to :
https://github.com/cloudposse/terraform-aws-rds-cluster/blob/master/main.tf#L90
PePe Amengual
PePe Amengualalmost 7 years ago
any objections if I send a PR?
Taras
Tarasalmost 7 years ago
Hey guys,
Please advise on what is the structure of this value so that I could provide additional S3 bucket policy?
https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn/blob/a05cffd71b6b5ea8d9a881e20c8b41d038dc9167/variables.tf#L66
Whatever I provide it blames on this or that character somewhere. Can’t find example of what it actually expects.
NVMeÐÐi
NVMeÐÐialmost 7 years ago
Hi, I have a module that isn’t playing well in 0.12 specifically because it previously referenced private_ip[0] to name an aws_route53_record. I previously used replace() to change the . to -
NVMeÐÐi
NVMeÐÐialmost 7 years ago
My question is this… Is there anyway to change a tuple to a string in 0.12? (Interpolation doesn’t seem to do it anymore).
NVMeÐÐi
NVMeÐÐialmost 7 years ago
Example below, I get the tuple error for the name, but records is fine.

resource "aws_route53_record" "this" {
  name = "ip-${replace(module.this_mybox.private_ip[0], ".", "-")}"
  type = "A"
  zone_id = "${var.dns_zone_id}"
  records = "${module.this_mybox.private_ip[0]}"
  ttl = "600"
}
NVMeÐÐi
NVMeÐÐialmost 7 years ago
Oof, got it resolved. Artburkart got me.
Andrew Roth
Andrew Rothalmost 7 years ago
Daniel
Danielalmost 7 years ago
Hey folks, any guidance on this issue I’m running into with the elasticache-memcached module? https://github.com/cloudposse/terraform-aws-elasticache-memcached/issues/8
Iiro Niinikoski
Iiro Niinikoskialmost 7 years ago
Any Terratest users? Tried to find a better channel (maybe #terragrunt would have been better here) - but I'm wondering, how can I manage which Terraform version I would be using for doing the runs...? Tried to read the module's source code also but did not find anything obvious... only TerraformBin variable but I'd guess that does not help crazy much...
Joe Presley
Joe Presleyalmost 7 years ago
I haven’t used Terratest but given these lines of code TerraformBinary and the documentation in their basic terraform example, https://github.com/gruntwork-io/terratest/tree/master/examples/terraform-basic-example “Install Terraform and make sure it’s on your PATH.” that Terratest runs the terraform binary that is in your path.
Joe Presley
Joe Presleyalmost 7 years ago
Joe Presley
Joe Presleyalmost 7 years ago
To manage the terraform versions, I would use a tool such as tfenv.
Iiro Niinikoski
Iiro Niinikoskialmost 7 years ago(edited)
@Joe Presley ok, thanks. I currently plugging our Terratest-orchestrated Terraform tests into GitHub Actions, and I was surprised when I was able to do a Terratest-run with just installing the module-dependencies and running "go test" - no need to install TF in PATH... Hence I starting doubting on what's happening 🙂
Iiro Niinikoski
Iiro Niinikoskialmost 7 years ago
@Joe Presley I was also using tfenv before locally, but I found tfswitch more... ux-friendly maybe 🙂
Joe Presley
Joe Presleyalmost 7 years ago
Does the GitHub actions use HashiCorp’s terraform GitHub action? https://www.terraform.io/docs/github-actions/getting-started.html I’ll have to checkout tfswitch.
Iiro Niinikoski
Iiro Niinikoskialmost 7 years ago
@Joe Presley I could use those yes... And, I'd need to find a small balance here, as I'd need to pull dependent TF modules from TF Enterprise's Module Registry - meaning, I anyway need to configure ~/.terraformrc somehow...
Iiro Niinikoski
Iiro Niinikoskialmost 7 years ago
I might build a fork of the official Terraform Actions which just includes an additional command, "test" (which executes a "make test"... Might be the easiest at the end...
Iiro Niinikoski
Iiro Niinikoskialmost 7 years ago
Sent my question to the Terratest team: https://github.com/gruntwork-io/terratest/issues/419 - let's see...
C
Cloud Possealmost 7 years ago
:zoom: Join us for "Office Hours" every Wednesday 11:30AM (PST, GMT-7) via Zoom.

This is an opportunity to ask us questions on terraform and get to know others in the community on a more personal level. Next one is Dec 25, 2019 11:30AM.

👉️ Register for Webinar

:slack: #office-hours (our channel)
Chris McConnell
Chris McConnellalmost 7 years ago
chatting in general re nodegroups vs separate ASGs per zone for stateful apps/services in eks kube. the convo being more appropriate here. . .
Chris McConnell
Chris McConnellalmost 7 years ago
since using TF to manage. I was refactoring to support PVCs and dealing with some very active operators which are running tons of node-shells that I did'nt know use 'nodeSelector' when templatizing the helm chart and applying the manifests.
Chris McConnell
Chris McConnellalmost 7 years ago
so also curious how folks are managing stateful apps/services like operators, kafka, etc that set 'nodeSelector', it seems like I need to find a dynamic solution to keeping the 'nodeSelector' s updated as scaling events occur, etc.
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
btw, I don't know why @Maarten van der Hoef didn't share this yet, but this looks really rad: https://github.com/Flaconi/terraform-aws-bastion-ssm-iam
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
Bastion server with zero outside ports open 😃
PePe Amengual
PePe Amengualalmost 7 years ago(edited)
Hi so I’m using this : https://github.com/cloudposse/terraform-aws-rds-cluster/blob/master/main.tf#L163 option to create cluster CNAMES to the cluster endpoint byt my app are not able to resolve the CNAME records, so I’m guessing maybe this is a problem wit the way that aurora cluster endpoint work on route53? If the default cluster endpoints are CNAMEs then my CNAMES will point to a CNAME than then it will point to A record that is the rds instance endpoint so maybe java has an issue with following multiple CNAMES or somesthing?
PePe Amengual
PePe Amengualalmost 7 years ago
I never had this problem before but I never pointed CNAMEs to cluster endpoint, I was wondering to maybe switch to custom endpoints
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
What happens when you dig it?
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
Does it resolve correctly?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
we use CNAMEs with Aurora clusters all the time with no issues
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
works with any SQL client. Also works with Metabase, which is Java-based
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
in your app, try to use the cluster endpoint first to check if it’s working
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
it could be any other issue (e.g. SSL etc.)
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
Ya maybe trying to use SSL? That won’t work with the CNAME
BikalKumar K Jha
BikalKumar K Jhaalmost 7 years ago
@channel, need help with below module for ALB.
This module is a combined one which created ALB, target group, listerner, Listener rule, attaching certificate. However, as you may see, we are passing a list of elements to this module which is causing this module to break.

It breaks if I remove any element from the list and but this, all the element post the one removed gets deleted and recreated.
George Platon
George Platonalmost 7 years ago
hei guys, I've started recently with terraform-aws-rds(https://github.com/cloudposse/terraform-aws-rds.git?ref=tags/0.9.3)
) and terraform-aws-vpc (https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.7.0)

yet it seems they are completely incompatible.

As soon as I run terraform plan, it gives me errors like the ones below, which require me to go an tweak the generated .terraform modules files, in order for them to work together.

Error: Unsupported block type

  on .terraform/modules/rds_instance/main.tf line 71, in resource "random_string" "default":
  71:   keepers {

Blocks of type "keepers" are not expected here. Did you mean to define
argument "keepers"? If so, use the equals sign to assign it a value.


Error: Incorrect attribute value type

  on .terraform/modules/rds_instance/main.tf line 104, in resource "aws_db_subnet_group" "default":
 104:   subnet_ids = ["${var.subnet_ids}"]

Inappropriate value for attribute "subnet_ids": element 0: string required.


Error: Incorrect attribute value type

  on .terraform/modules/rds_instance/main.tf line 134, in resource "aws_security_group_rule" "ingress_cidr_blocks":
 134:   cidr_blocks       = ["${var.allowed_cidr_blocks}"]

Inappropriate value for attribute "cidr_blocks": element 0: string required.
George Platon
George Platonalmost 7 years ago
Any idea if that is norm ? is there some best practices to avoid having such incompatibilities ?
George Platon
George Platonalmost 7 years ago
I don't think its ok for me to tweak the generated .terraform modules, just to make those work
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago(edited)
looks like you are mixing up TF 0.11 and 0.12. cidr_blocks = ["${var.allowed_cidr_blocks}"] is 0.11 syntax
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
for TF 0.12, use the latest versions of the modules (that’s what the tests usually do)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
for TF 0.11, find the prior releases for 0.11 and use all modules for 0.11
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
George Platon
George Platonalmost 7 years ago
I'm using terraform v.0.12.17 locally now. Is there a way to check for each module release if its on Terraform 12 or 11 ?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
there is no automatic way to check it
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
look into examples/complete of each module
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
they should use the latest TF 0.12 version (or almost latest)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
it will say “Convert to TF 0.12”. All tags after that are 0.12
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
sometimes we make new releases for 0.11, but the tag will be smaller than the first 0.12 release, e.g. https://github.com/cloudposse/terraform-aws-rds/releases/tag/0.9.3 is a bug fix release for 0.11 version
George Platon
George Platonalmost 7 years ago
alright, thanks a lot, will check now :github:
getSurreal
getSurrealalmost 7 years ago
I'm curious what CloudPosse uses as a rule of thumb for when to have a module call another module vs defining the terraform resource. For instance the aws-ecs-alb-service-task module doesn't reference the aws-iam-role module for creating its roles.
https://github.com/cloudposse/terraform-aws-ecs-alb-service-task/blob/master/main.tf
https://github.com/cloudposse/terraform-aws-iam-role
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
I think the iam role module was created much, much later.
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
In our case, we use the IAM role module to provision roles needed by pods in kubernetes
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
and use it more in a standalone context
getSurreal
getSurrealalmost 7 years ago
So if the ecs-alb-service-task was written from scratch today, it would likely reference the iam-role module?
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
So in < 0.12, using modules like this could very often lead to "count of ... could not be computed" https://docs.cloudposse.com/troubleshooting/terraform-value-of-count-cannot-be-computed/
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
post 0.12, we encounter that much less often, so perhaps.
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
the main reason we have the iam role module is to enforce consistent names
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
however, if we're just provisioning some roles in another module, we probably wouldn't use this module because we're already using the null label module for that everywhere else
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
i don't think this is the "rule of thumb" you were looking for though 🙂
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
We wanted to use this module all over the place, but ended up not being able to because of the count-of problems. Thus, we just ended up using the raw resources everywhere.
getSurreal
getSurrealalmost 7 years ago
Thanks Erik. I appreciate it. So I guess you could say the rule of thumb is to reference other modules unless it creates more problems than benefits. 😀
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
That's a good paraphrasing.
Igor
Igoralmost 7 years ago
Is there a way to release the lock on terraform file in dynamo db through terraform CLI
Maarten van der Hoef
Maarten van der Hoefalmost 7 years ago(edited)
have you tried terraform force-unlock ?
Igor
Igoralmost 7 years ago
Just tried it, thanks - it worked
Igor
Igoralmost 7 years ago
Just need the lock id
Igor
Igoralmost 7 years ago
But if you give it the wrong one, it will tell you the existing one
Matt Law
Matt Lawalmost 7 years ago
Hello all, In the last 24 hours, all of our terraform-null-label modules started failing, with the following error, anyone have any ideas?
Error: Failed to download module

Could not download module "s3_bizrewards_dev_label" (<http://s3_bizrewards.tf:31|s3_bizrewards.tf:31>)
source code from
"<https://api.github.com/repos/cloudposse/terraform-null-label/tarball/0.16.0//*?archive=tar.gz>":
Error opening a gzip reader for
/var/folders/1d/gpvdrwrd0y1_d0jv64w76j645nyvdq/T/getter001152442/archive: EOF.
Rahul Kathpal
Rahul Kathpalalmost 7 years ago
Hi everyone,

Could you please check the following issue & let me know what's wrong here.

Error: Missing resource instance key

on terraform-aws-codebuild/main.tf line 144, in data "aws_iam_policy_document" "permissions_cache_bucket":
144: "${aws_s3_bucket.cache_bucket.arn}",

Because aws_s3_bucket.cache_bucket has "count" set, its attributes must be
accessed on specific instances.

For example, to correlate with indices of a referring resource, use:
aws_s3_bucket.cache_bucket[count.index]


Error: Missing resource instance key

on terraform-aws-codebuild/main.tf line 144, in data "aws_iam_policy_document" "permissions_cache_bucket":
144: "${aws_s3_bucket.cache_bucket.arn}",

Because aws_s3_bucket.cache_bucket has "count" set, its attributes must be
accessed on specific instances.

For example, to correlate with indices of a referring resource, use:
aws_s3_bucket.cache_bucket[count.index]


Error: Missing resource instance key

on terraform-aws-codebuild/main.tf line 145, in data "aws_iam_policy_document" "permissions_cache_bucket":
145: "${aws_s3_bucket.cache_bucket.arn}/*",

Because aws_s3_bucket.cache_bucket has "count" set, its attributes must be
accessed on specific instances.

For example, to correlate with indices of a referring resource, use:
aws_s3_bucket.cache_bucket[count.index]


Error: Missing resource instance key
Rahul Kathpal
Rahul Kathpalalmost 7 years ago
Hi @UFC8P2WJG Thanks for the update! Let me take a look into this, basically I would like to achieve the following things, let me know if you can help me out on this:- My stack is: AWS CodePipeline (github integration) + CodeBuild (lambda deploy) packed in terraform. AWS Lambda + API gateway dev environment and a commit in prod branch goes to AWS Lambda + API gateway prod environment
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
looks like you are using the old TF 0.11 version of the module which has that issue (and newer version of terraform complains about it, but did not do it before)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
take a look at the new 0.12 version (where the issue is fixed) https://github.com/cloudposse/terraform-aws-codebuild
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)almost 7 years ago
ikar
ikaralmost 7 years ago
Hey there!
The iam_access_key doc (https://www.terraform.io/docs/providers/aws/r/iam_access_key.html#secret) says for the secret attribute:

secret - The secret access key. Note that this will be written to the state file. If you use this, please protect your backend state file judiciously. Alternatively, you may supply a pgp_key instead, which will prevent the secret from being stored in plaintext, at the cost of preventing the use of the secret key in automation.

The If you use this part means if you use the resource as a whole? Or just the attribute? Is there a way how to prevent storing secret in the state file? The terraform apply knows it's a sensitive value:
$ terraform apply 

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # module.elasticprop.aws_iam_access_key.elasticprop_access_key will be created
  + resource "aws_iam_access_key" "elasticprop_access_key" {
      + encrypted_secret  = (known after apply)
      + id                = (known after apply)
      + key_fingerprint   = (known after apply)
      + secret            = (sensitive value)
      + ses_smtp_password = (sensitive value)
...

...using terraform 0.12.18
Pierre-Yves
Pierre-Yvesalmost 7 years ago(edited)
Hello,
can resources be generated from an interpolated variable ?
or may be i should use templates ?
by example will this work :
resource "azurerm_managed_disk" "Disk${var.ServerName}" {}
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
Rejoice!!!
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)almost 7 years ago
Pr merged
PePe Amengual
PePe Amengualalmost 7 years ago
finally!!!!
Joe Niland
Joe Nilandalmost 7 years ago
I was just wondering what is the best option for supplying secrets to Terraform. For example, when writing secrets to parameter store.

Options I can see are:
1. Create an input variable and supply via cli, prompt or ENV var
2. Create a gitignored tfvars file and store secrets in there for use in input vars
3. Same as (2) but use git-crypt on the tfvars file and keep the encrypted version in git
4. Manually add to Vault (or some other secure place that Terraform can access - SecretHub?) and retrieve value
I guess the best option will partly depend on how many people are running the Terraform modules.

Interested in what people have found is most practical.
Related GitHub issue: https://github.com/hashicorp/terraform/issues/516
vvsp
vvspalmost 7 years ago
Folks, any comments here pls ?
I have created a security group in account x. But later on updated it with a different privider (account Y); with this updated a security group created in an accountY; but then should the old resource be left in accountX; that’s what I see … is that expected ?
Bruce
Brucealmost 7 years ago
Has anyone been able to create a module for creating a lambda to rotate RDS credentials for Postgres in AWS Secrets manager? There is a CloudFormation template for it but I'm finding it a real pain to replicate it.
Maarten van der Hoef
Maarten van der Hoefalmost 7 years ago
@Bruce Have you thought of using aws_cloudformation_stack in terraform. It's maybe not the nicest solution, but it will save you time and you can still deploy it with terraform.
Bruce
Brucealmost 7 years ago
I was trying to avoid that but that may be the solution 😁
C
Cloud Possealmost 7 years ago
:zoom: Join us for "Office Hours" every Wednesday 11:30AM (PST, GMT-7) via Zoom.

This is an opportunity to ask us questions on terraform and get to know others in the community on a more personal level. Next one is Jan 01, 2020 11:30AM.

👉️ Register for Webinar

:slack: #office-hours (our channel)
vvsp
vvspalmost 7 years ago
Is “aws organisations” the best way to deal with creating and maintaining users across environments (Dev/Stage/Prod) ?
Wondering what will be the differences of creating user base and role access to different environment in terraform versus using “aws organizations” ?
Will there be any specific advantages of using “organizations” as such ?

Many thanks in advance.
Omer Sen
Omer Senalmost 7 years ago
Hi i have just used the eks nodegroup module
Omer Sen
Omer Senalmost 7 years ago
Great effort
Omer Sen
Omer Senalmost 7 years ago
Btw i spent 2 hours to find out an issue
Omer Sen
Omer Senalmost 7 years ago
It seems that there is a bug on aws API if you come from ipv6 ip
Omer Sen
Omer Senalmost 7 years ago
I have switched to ip4 and it is fixed
Akram Mousselmal
Akram Mousselmalalmost 7 years ago
Hi I have just started using terraform. I was reading elasticsearch aws terraform module : https://github.com/cloudposse/terraform-aws-elasticsearch
Akram Mousselmal
Akram Mousselmalalmost 7 years ago
I did not find any precision about if its includes logstash in the stack or not.
Akram Mousselmal
Akram Mousselmalalmost 7 years ago
I am trying to build an ELK cluster on AWS 🙂
Milos Backonja
Milos Backonjaalmost 7 years ago
Hi Guys, is there a way to for loop in templatefale through miltiple lists/tuples?
something like this for example:
%{ for name lastname age in names lastnames ages ~}

echo ${name} ${lastname} ${age}

%{ endfor ~}

Julio Tain Sueiras
Julio Tain Sueirasalmost 7 years ago
Are they the same length?
Milos Backonja
Milos Backonjaalmost 7 years ago
yes
rohit
rohitalmost 7 years ago
any recommendations for terraform version manager ?
mhodzic
mhodzicalmost 7 years ago
Ashwini Swain
Ashwini Swainalmost 7 years ago
Hello Guys

Stuck in a aws_launch_template user data issue since a long time.
Ashwini Swain
Ashwini Swainalmost 7 years ago
Trying to deploy this template:

data "template_file" "user-data"{

 template = <<EOF
 echo export DB_CONNECTION="${var.rds_endpoint}" >> /etc/profile
 EOF
}

resource "aws_launch_template" "django-launch-template" {

 image_id        = "${data.aws_ami.django-ami.id}"
 instance_type     = "${var.instance_type}"
 name          = "${var.template_name}"
 key_name        = "${var.key_pair}"

 user_data       = "${base64decode(data.template_file.user-data.rendered)}"
}
Ashwini Swain
Ashwini Swainalmost 7 years ago
Ans this is the error I get:

Error: Error in function call

 on main.tf line 41, in resource "aws_launch_template" "django-launch-template":
 41:  user_data       = "${base64decode(data.template_file.user-data.rendered)}"
  |----------------
  | data.template_file.user-data.rendered is " echo export DB_CONNECTION=\"<http://Test.String.com|Test.String.com>\" >> /etc/profile\n"

Call to function "base64decode" failed: failed to decode base64 data ' echo
export DB_CONNECTION="<http://Test.String.com|Test.String.com>" >> /etc/profile

'=
rohit
rohitalmost 7 years ago
how would we translate
"${var.var1}${var.var2}"
rohit
rohitalmost 7 years ago
in terraform 12 ?
rohit
rohitalmost 7 years ago
when upgrading from terraform 0.11.x to 0.12, what is the best practice to deal with state stored in S3?
Igor
Igoralmost 7 years ago
It should update without problems
Igor
Igoralmost 7 years ago
If you don't have versioning turned on (which you should), I would make sure to have a backup
rohit
rohitalmost 7 years ago
i am not sure if versioning is turned on not, how do you enable versioning ?
loren
lorenalmost 7 years ago
Haven't had any problems with the state updating automatically. Update to 0.11.14 first, then 0.12.x