#terraform - September 2019

September 2019
sahil
sahilabout 7 years ago
Hi,
I have been using the resource aws_ami_from_instance to create AMI. The problem with this approach is that I cannot delete instance after creating the AMI. The instance is useless after this. So basically my workflow is as follows:
1. Create an Instance
2. Run some script inside the instance
3. Create an AMI from the instance
4. Terminate the instance
I have been recommended to use packer for this but problem with packer is that it is doesn't have a good integration with Terraform (Also I'm passing a lot of variables in the scripts in step 2)
Any suggestions please? 😄
C
Cloud Posseabout 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 Sep 11, 2019 11:30AM.

👉️ Register for Webinar

:slack: #office-hours (our channel)
Brij S
Brij Sabout 7 years ago
I'm not sure if this is a TF12 problem or not, but I made another module just recently and this seemed to work, however - providers and their aliases are not found by the module anymore:

Error: Provider configuration not present

To work with
module.cicd-web.aws_iam_policy_attachment.cloudformation_policy_attachment its
original provider configuration at module.cicd-web.provider.aws.nonprod is
required, but it has been removed. This occurs when a provider configuration
is removed while objects created by that provider still exist in the state.
Re-add the provider configuration to destroy
module.cicd-web.aws_iam_policy_attachment.cloudformation_policy_attachment,
after which you can remove the provider configuration again.


I found this link: https://github.com/hashicorp/terraform/issues/21472
that states that providers need to be explicitly passed down to the module, which I tried but still doesnt work
Matt
Mattabout 7 years ago(edited)
Cross posting this from r/terraform:
https://old.reddit.com/r/Terraform/comments/czjnvq/analysis_paralysis_bootstrapping_a_new_terraform/
Anyone here have good examples for bootstrapping a clean parameterized Terraform deployment on AWS?
oscar
oscarabout 7 years ago
@Matt is this your thread? If so #geodesic is a great tool that many of us will talk to you about
oscar
oscarabout 7 years ago
It avoids Workspaces & wrappers like Terragrunt
oscar
oscarabout 7 years ago(edited)
Matt
Mattabout 7 years ago
yes, that's my thread @oscar
Matt
Mattabout 7 years ago
I will take a look at Geodesic
oscar
oscarabout 7 years ago
It is Sweetops weekly hour session
oscar
oscarabout 7 years ago
Great chance to get a demo and ask Qs.
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
#office-hours starting in 15 minutes
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
#office-hours starting now! ask questions, get answers. free for everyone. https://zoom.us/j/508587304
Matt
Mattabout 7 years ago
not sure I can make it @oscar, not this week
Matt
Mattabout 7 years ago
but this is one of my major grips about Terraform which I generally like a lot
Matt
Mattabout 7 years ago
otherwise
Tum
Tumabout 7 years ago(edited)
Sorry, for your modules, they compatible with Terraform version 0.12+?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
not all of them are converted to 0.12 yet (we are working on it)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
Jonathan Le
Jonathan Leabout 7 years ago
https://github.com/terraform-providers/terraform-provider-aws/issues/9995

Add your thumbs up if that would be useful to you.
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago
being quite busy the past few weeks (going back to fixing terraform-lsp on the weekend) was working on a nice research and production project 😃
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago
the project being openstack on nomad
Bruce
Bruceabout 7 years ago
Hey guys, I am looking for a way to have my AWS autoscaling group perform a shutdown script before scaling down. The only way I can find to do this is using lifecycle hooks > Cloudwatch Events > lambda > SSM . But this seems quite a chain to string together. Any suggestions?
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
imho that's the only way
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
it is normally used for ecs/ecs2 connection draining on scale in(down)
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
but in your case it might be even more complex since the script has to report success
Bruce
Bruceabout 7 years ago
Thanks @Nikola Velkovski 👍️
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
you are welcome
Brij S
Brij Sabout 7 years ago
was hoping someone with regex expertise can help me out here, Im trying the following:
${replace(var.project, "/\\s$/", "")}
where var.project is a string that will end in the letter s. I'm trying to strip the s at the end but im not having any luck. When I run this the s remains. Any ideas?
antonbabenko
antonbabenkoabout 7 years ago(edited)
Igor
Igorabout 7 years ago
@Brij S Your regex is replacing \s, not s
Igor
Igorabout 7 years ago
Try ${replace(var.project, "/s$/", "")}
Igor
Igorabout 7 years ago
The other approach, to @antonbabenko point, is to match the whole string: ${replace(var.project, "/^(.*)s$/", "$1")}
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
or just use substr("str", 0, length("str") - 1) without messing up with regex (https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/)
Michał Czeraszkiewicz
Michał Czeraszkiewiczabout 7 years ago
Hi, How can I reference resources created with for_each?
Below the example what I try to accomplish:


locals {
  users = ["user1", "user2"]
}

resource "aws_iam_user" "this" {
  for_each = toset(local.users)
  name     = "${each.value}"
}

resource "aws_iam_access_key" "this" {
  for_each = toset(local.users)

  user = # Reference above created users
}
Maarten van der Hoef
Maarten van der Hoefabout 7 years ago(edited)
Hi @Michał Czeraszkiewicz 🙂

    user = aws_iam_user.this[each.key].name
Michał Czeraszkiewicz
Michał Czeraszkiewiczabout 7 years ago
@Maarten van der Hoef thx :thumbsup_all:
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
Hello
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
is terragrunt considered a "best practice" tool to be using?
sarkis
sarkisabout 7 years ago
I don't know if I consider it a "best practice" tool... most of the must have features of terragrunt (i.e. state locking during apply) have made it to terraform, my answer would be different if this was asked a year or so ago 🙂
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
just asking because i previously worked in a place that we had one terraform repo per environment(dev,prod,staging)
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
and we had to do alot of repeatable work in each env
sarkis
sarkisabout 7 years ago
It could be used for a very specific style of writing TF to keep things DRY, though you can do this now with workspaces, as well... I'm a fan of this workflow: https://github.com/cochransj/tf_dynamic_environment_regions
sarkis
sarkisabout 7 years ago
Note: a lot of that assumes you are using TF 0.12+ 🙂
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
thanks
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
another question
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
imagine that i have an RDS instance in prod env, but i do not have it in dev env
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
i would be able to accomplish this with terragrunt or workspaces?
sarkis
sarkisabout 7 years ago
sure
sarkis
sarkisabout 7 years ago
conditional statement on count which i believe is possible in 0.12, psuedo code: IF $terraform.workspace == "prod" THEN count = 1 ELSE count = 0 on the RDS resource
Fernando Torresan
Fernando Torresanabout 7 years ago(edited)
When we talking about multple accounts, teams, environments...for me, terragrunt has been totally necessary to keep my terraform code organized and without so much boilerplate code
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
thx
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
one last question
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago(edited)
i used to work with 1 big tfstate per environment
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
is a best approach to be using multiple tfstates per resourcegroup?
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago(edited)
so we can manage VPCs individually, EC2s individually, etc....
loren
lorenabout 7 years ago
we like to split tfstate on multiple dimensions... such as team and stage and app and stateful/stateless...
loren
lorenabout 7 years ago
though, "individually" is a bit relative... for many actions, you can use -target to restrict the scope of an action... splitting tfstate helps reduce the blast radius of accidents better IMO though
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
nice
loren
lorenabout 7 years ago
also see the recent thread/posts by @Erik Osterman (Cloud Posse) in #geodesic for another approach... https://sweetops.slack.com/archives/CB84E9V54/p1567187759027700
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
each team has autonomy to apply without interfering in other team infrastructure
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
basically, i just started in a new company, nothing in IAC yet
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago
and i'm researching good strategies/architectures to start our environments
Marcio Rodrigues
Marcio Rodriguesabout 7 years ago(edited)
and i'm thinking about splitting into multiple tfstates, because we have a project to make a disaster recovery plan. We should be able to disaster recover only some portions of our infrastructure, into another region
loren
lorenabout 7 years ago(edited)
we use terragrunt because it is visual (hierarchy/tfstate by directory structure) and easy to comprehend. tf workspaces are less visible in that sense and IMO harder to "know" where you are working. geodesic is solving similar problems in another way entirely 🙂
C
Cloud Posseabout 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 Sep 18, 2019 11:30AM.

👉️ Register for Webinar

:slack: #office-hours (our channel)
Brij S
Brij Sabout 7 years ago
does anyone know how to get the function name of a created lambda?
resource "aws_lambda_function" "s3_metadata" , can this resource be accessed via aws_lambda_fuction.s3_metadata.id ?
Brij S
Brij Sabout 7 years ago
the docs dont make it apparent..
aaratn
aaratnabout 7 years ago
aws_lambda_fuction.s3_metadata.function_name
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago
since tomorrow is HashiConf
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago(edited)
I am giving my prediction that maybe they will officially announce packer 2.0 with HCL2?
rohit
rohitabout 7 years ago
how can i pass db_subnet_group_name to aws_rds_cluster resource using data object ?
rohit
rohitabout 7 years ago
currently i am trying to use
  db_subnet_group_name = "${element(data.my_state.networking.database_subnets,1)}"
rohit
rohitabout 7 years ago
does anyone know how to read subnet name from state file ?
sarkis
sarkisabout 7 years ago
@rohit doesn't look like there is a data source for this yet: https://github.com/terraform-providers/terraform-provider-aws/pull/9525
rohit
rohitabout 7 years ago
@sarkis thanks. I will try a different alternative then
sarkis
sarkisabout 7 years ago
sarkis
sarkisabout 7 years ago
terraform plan getting a cost estimation feature on TF Cloud 🤔 interesting...
Igor
Igorabout 7 years ago
I didn't find any references to ECS Service Discovery in CP modules. Is it because everyone is running an alternative solution?
Igor
Igorabout 7 years ago
For someone getting started with containers, and not having more than 3-4 services at the most, should I even bother with orchestration and/or sophisticated methods of service discovery?
Igor
Igorabout 7 years ago
Or will ALB/ECS combo get the job done?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
for that we usually deploy https://istio.io/docs/concepts/what-is-istio/ in the k8s cluster
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
don’t have anything in TF
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
Igor
Igorabout 7 years ago
That's what AWS AppMesh does, right? I wonder if that's an overkill for my use case though.
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
yes AppMesh should do similar things. we did not use it yet
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
for 3 static services might be an overkill 🙂 but at the same time, you get an experience and be able to use it with tens of services 🙂
Callum Robertson
Callum Robertsonabout 7 years ago
Has anyone played with the new Terraform SaaS offering?
Callum Robertson
Callum Robertsonabout 7 years ago
Looks like TF cloud has hit GA
oscar
oscarabout 7 years ago
Not yet but took a read. Keen to hear someone’s experience & comparison to local Geodesic workflow / CI tools using Geodesic workflow / Atlantis
Haydar Ciftci
Haydar Ciftciabout 7 years ago
I have a hard time getting the cloudposse modules to work with the recent terraform version (v0.12.8). I feel like I'm missing something, any ideas?
oscar
oscarabout 7 years ago
Try:

  on .terraform/modules/alb_magento2/main.tf line 33, in resource "aws_security_group_rule" "http_ingress":
  33:   cidr_blocks       = [var.http_ingress_cidr_blocks]
oscar
oscarabout 7 years ago
Change: removal of "${ and }"
oscar
oscarabout 7 years ago
If that doesn’t work, try:
cidr_blocks = var.http_ingress_cidr_blocks
.. since it is already a list
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
#office-hours starting now! ask questions, get answers. free for everyone. https://zoom.us/j/508587304
joshmyers
joshmyersabout 7 years ago
How are folks doing multi region as far as Terraform goes…?
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
Workspaces ? 😄
joshmyers
joshmyersabout 7 years ago
I’m more interested in things like what you do with the state file
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
@Mike Whiting can you share how you are invoking the module?
Mike Whiting
Mike Whitingabout 7 years ago
@Mike Whiting has joined the channel
Mike Whiting
Mike Whitingabout 7 years ago
@Nikola Velkovski yep that's the one
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
oh that woiuld be me
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
what a coincidence 😄
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
are you using terraform 0.12 by any chance ?
Mike Whiting
Mike Whitingabout 7 years ago
yeah
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
unfortunately it has not been ported yet
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
😞
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
but I can dedicate some time and do it
Mike Whiting
Mike Whitingabout 7 years ago
that would be awesome
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
cool
Mike Whiting
Mike Whitingabout 7 years ago
just to clarify...
Mike Whiting
Mike Whitingabout 7 years ago
this will enable ec2 instances to log to cloudwatch events
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
@Erik Osterman (Cloud Posse) what's the workflow in this case, should Mike create an issue ?
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
Ya if he needs it now, the best bet is to fork and run terraform upgrade
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
cool thanks
Hemanth
Hemanthabout 7 years ago
hey guys i am trying to create a ec2 (after taint'ing the existing ec2), attaching the ebs volume(using aws_volume_attachment), and using an user-data script in my tf to mount the volume (which is /home), and also trying to import some data from /home to the newly created instance, problem is many times the /home is not mounted, and the /var/log/cloud-init-output.log shows No such file or directory to the files i am trying to import, any thoughts on this ?
Brij S
Brij Sabout 7 years ago
hey all, all of a sudden i'm getting this error when running terraform apply
Error: error validating provider credentials: error calling sts:GetCallerIdentity: NoCredentialProviders: no valid providers in chain. Deprecated.


I have no idea why this is happening. The only thing I did was add some credentials to my .aws/credentials file.

My providers look like this

provider "aws" {
  version = "~> 2.25.0"
  region  = var.aws_region
  profile = "storesnonprod"
  alias   = "nonprod"
}

provider "aws" {
  version = "~> 2.25.0"
  region  = var.aws_region
  profile = "storesprod"
  alias   = "prod"
}
Brij S
Brij Sabout 7 years ago
does anyone know what might be causing this?
sarkis
sarkisabout 7 years ago
@Brij S is it possible you mucked up your .aws/credentials toml format so it's not being parsed correctly by the TF provider?
Brij S
Brij Sabout 7 years ago
@sarkis, it seems when I add some old profiles back to the credentials file it works. But when I remove them i get the error
sarkis
sarkisabout 7 years ago(edited)
do your profiles depend on each other? i think there was something like source_profile i can't remember the exact param
Brij S
Brij Sabout 7 years ago
no
Brij S
Brij Sabout 7 years ago
two seperate profiles as you see in the snippet above
sarkis
sarkisabout 7 years ago(edited)
can you share your ~/.aws/credentials file in DM and redact sensitive data
Brij S
Brij Sabout 7 years ago
sure
mpmsimo
mpmsimoabout 7 years ago(edited)
Anyone using a tool like drifter or terraform-monitor-lambda to detect state drift?
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
@Brij S you can verify if the profiles are properly set with aws cli
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
e.g. aws s3 ls --profile storesnonprod
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
because terraform uses that
Maciek Strömich
Maciek Strömichabout 7 years ago
or by
AWS_PROFILE=profilename aws s3 ls
ciastek
ciastekabout 7 years ago
I need something like "random_string" resource, but with a custom command. So, execute a command only if the resource isn't in the state yet (or was tainted), and use commands output as a value to put in the state.
Any idea what kind of magic to use to achieve such result?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
if you provide the param in var, use it
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
if not, use random string to generate it
oscar
oscarabout 7 years ago
Have you guys seen this before?

Error: Error creating S3 bucket: BucketAlreadyOwnedByYou: Your previous request to create the named bucket succeeded and you already own it.
	status code: 409, request id: aaaa, host id: aaaa//bbbb+cxxx=
oscar
oscarabout 7 years ago
It doesn’t exist on ANY of our accounts
oscar
oscarabout 7 years ago
its a very, very, specific and niche bucket name
oscar
oscarabout 7 years ago
the changes someone else owns it is extremely slim
oscar
oscarabout 7 years ago
I’m sure I saw this about 4-5 months ago, but it actually was created on one of our accounts
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
we saw that happens when you create a resource (e.g. bucket) not using the TF remote state. Then the state was lost on local machine. Then TF tries to create it again, but it does exist in AWS
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
check that you use remote state and not losing it
oscar
oscarabout 7 years ago
Yeh that adds up with what potentially happened
oscar
oscarabout 7 years ago
That local state file is long gone
oscar
oscarabout 7 years ago
How can I recover the S3 bucket? :S
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
you need to find it in AWS 🙂
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
and either destroy it manually in the console, or import it
oscar
oscarabout 7 years ago
It isn’t there
oscar
oscarabout 7 years ago
I’ve searched hte account (it has no buckets) - new account
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
make sure you have permissions to see it (maybe it was created under diff permissions)
oscar
oscarabout 7 years ago
Yeh I’ve checked sadly with Admin permissions in console
oscar
oscarabout 7 years ago
It genuinely isn’t there, even got one of the IT guys to look
oscar
oscarabout 7 years ago
I’ve opened a ticket with AWS but slow
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
S3 is global, so you need to check all your accounts, even those you don’t know about
oscar
oscarabout 7 years ago
Wait so, it could be on a different aws account to that on which I ran terraform?!
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
it could be. I don’t remember if AWS shows the error Error creating S3 bucket: BucketAlreadyOwnedByYou: Your previous request to create the named bucket succeeded and you already own it in this case
oscar
oscarabout 7 years ago
AWS console just shows name already in use
oscar
oscarabout 7 years ago
when attempting to replicate but in the console
oscar
oscarabout 7 years ago
aghhh
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
so yes, you created it before and lost the state (if you are saying that the chance is very slim that some other people used the same name)
oscar
oscarabout 7 years ago
But surely even if I lost the state file
oscar
oscarabout 7 years ago
the s3 bucket would be on the aws account
oscar
oscarabout 7 years ago
btw the context is the backend module
oscar
oscarabout 7 years ago
Weird it has happened again on another account
oscar
oscarabout 7 years ago
it is in my local state file
oscar
oscarabout 7 years ago
a resource
oscar
oscarabout 7 years ago
but it isn’t on the console
oscar
oscarabout 7 years ago
what is going on
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
you have to follow exact steps when provisioning the TF state backend because you don’t have the remote backend yet to store the state in
oscar
oscarabout 7 years ago
Yeh no I know
oscar
oscarabout 7 years ago
it was an accident
oscar
oscarabout 7 years ago
I’m familiar with it 😛
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
you have to provision it first with local state, then update TF code to use remote S3 backend, then import the state
oscar
oscarabout 7 years ago
Probably the 18th account I’ve used your module on.. just something weird happened this time
oscar
oscarabout 7 years ago
Ya, I do this:

run:
	# Apply Backend module using local State file
	direnv allow
	bash toggle-s3.sh local
	terraform init && terraform apply
	# Switch to S3 State storage
	bash toggle-s3.sh s3
	terraform init && terraform apply
oscar
oscarabout 7 years ago
and my toggle-s3.sh script basically comments out hte backend
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
ok
oscar
oscarabout 7 years ago
It’s worked plenty time
oscar
oscarabout 7 years ago
not sure what happened this time though
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
i guess the bucket with that name exists for any reason (you created it, other people created it on diff account, or other people from diff orgs created it). Try to use a diff name
oscar
oscarabout 7 years ago
No I think something weird is happening
oscar
oscarabout 7 years ago
on a second account I’m getting this
oscar
oscarabout 7 years ago

Error: Error in function call

  on .terraform/modules/terraform_state_backend/main.tf line 193, in data "template_file" "terraform_backend_config":
 193:       coalescelist(
 194:
 195:
 196:
    |----------------
    | aws_dynamodb_table.with_server_side_encryption is empty tuple
    | aws_dynamodb_table.without_server_side_encryption is empty tuple

Call to function "coalescelist" failed: no non-null arguments.
oscar
oscarabout 7 years ago
I’ve followed the same pattern and commands as many accounts previously
oscar
oscarabout 7 years ago
all version locked etc
oscar
oscarabout 7 years ago
No clue why it isn’t having it today
oscar
oscarabout 7 years ago
annnnnd its working again
oscar
oscarabout 7 years ago
what the ?
oscar
oscarabout 7 years ago
what theee
oscar
oscarabout 7 years ago
that magic bucket thats there but not there?
oscar
oscarabout 7 years ago
can see it on aws cli
oscar
oscarabout 7 years ago
but not console
oscar
oscarabout 7 years ago
whaat
oscar
oscarabout 7 years ago
same permissions (iam role)
Brij S
Brij Sabout 7 years ago
so I found out why my module was using different credentials. It was because i had a main.tf in my module with the following content:

provider "aws" {
  version = "~> 2.25.0"
  region  = var.aws_region
  profile = "ambassadorsnonprod"
  alias   = "nonprod"
}

provider "aws" {
  version = "~> 2.25.0"
  region  = var.aws_region
  profile = "ambassadorsprod"
  alias   = "prod"
}


However, when I remove this main.tf file from the module, and run tf plan with configuration that references this module I get the following error:

To work with
module.cicd-web.aws_iam_policy_attachment.cloudformation_policy_attachment its
original provider configuration at module.cicd-web.provider.aws.nonprod is
required, but it has been removed. This occurs when a provider configuration
is removed while objects created by that provider still exist in the state.
Re-add the provider configuration to destroy
module.cicd-web.aws_iam_policy_attachment.cloudformation_policy_attachment,
after which you can remove the provider configuration again.


I have a main.tf that is setup so I'm not sure why im getting this error
oscar
oscarabout 7 years ago
ominously similar to my situ
Todd Linnertz
Todd Linnertzabout 7 years ago
I am looking at using the SweetOps s3_bucket module but I am not sure how to enable server access logging using the module. Does the module support enabling server access logging?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
depending on the s3 module you want to use
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
PePe Amengual
PePe Amengualabout 7 years ago(edited)
I’m having some issues with Terraform and terraform-aws-rds-cluster module, I’m creating a Global cluster ( I forked the cloudposse module and added one line) but this is not just related to to global aurora clusters but the problem is that the cluster finish creating but terraform for some reason keeps pooling for status until it times out after 1 hour , this is what I see :
module.datamart_secondary_cluster.aws_rds_cluster.default[0]: Creation complete after 9m10s [id=example-stage-pepe1secondary]
module.datamart_secondary_cluster.aws_rds_cluster_instance.default[1]: Creating...
module.datamart_secondary_cluster.aws_rds_cluster_instance.default[0]: Creating...
module.datamart_secondary_cluster.aws_rds_cluster_instance.default[0]: Still creating... [10s elapsed]
module.datamart_secondary_cluster.aws_rds_cluster_instance.default[1]: Still creating... [10s elapsed]
module.datamart_secondary_cluster.aws_rds_cluster_instance.default[1]: Still creating... [20s elapsed]
module.datamart_secondary_cluster.aws_rds_cluster_instance.default[0]: Still creating... [20s elapsed]
PePe Amengual
PePe Amengualabout 7 years ago
that will continue for 1 hour…..
PePe Amengual
PePe Amengualabout 7 years ago
and the console will show it as available
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
you see that eveytime you provision or just saw one time?
PePe Amengual
PePe Amengualabout 7 years ago
pretty much every time
PePe Amengual
PePe Amengualabout 7 years ago
I mean I have not been able to successfully complete the creation the cluster
Brij S
Brij Sabout 7 years ago
has anyone used multiple providers for a module?
Brij S
Brij Sabout 7 years ago
Ive done this multiple times with success, but now I'm facing an issue where all resources are created in one account(provider) and not the other and i'm not sure why
davidvasandani
davidvasandaniabout 7 years ago
@Brij S you'll need to post some code or errors for us to help you diagnose.
PePe Amengual
PePe Amengualabout 7 years ago
I had an issue like that yesterday, the name of the resource needs to be different and you need to pass the provider alias to every resource
Brij S
Brij Sabout 7 years ago
in my /terraform/modules/cicd folder Ive got a main.tf file with the following:

provider "aws" {
  version = "~> 2.25.0"
  region  = var.aws_region
  alias   = "nonprod"
}

provider "aws" {
  version = "~> 2.25.0"
  region  = var.aws_region
  alias   = "prod"
}


in my /terraform/cicd/stores folder Ive got a main.tf with the following:

provider "aws" {
  version    = "~> 2.25.0"
  region     = var.aws_region
  profile    = "storesnonprod"
  alias      = "nonprod"
}

provider "aws" {
  version    = "~> 2.25.0"
  region     = var.aws_region
  profile    = "storesprod"
  alias      = "prod"
}


and ive got a /terraform/cicd/stores/web.tf file Ive got

module "cicd-web" {
  source = "../../modules/cicd-web"

  providers = {
    aws.nonprod = "aws.nonprod"
    aws.prod    = "aws.prod"
  }
........


in all of my resources ive got either a provider = "aws.nonprod" or provider = "aws.prod" but they all get created in aws.nonprod
Brij S
Brij Sabout 7 years ago
@davidvasandani ^
Brij S
Brij Sabout 7 years ago
However, I realized that if I put profiles in /terraform/modules/cicd/main/tf then it works! However, that defeats my purpose of the module since id want to use different profiles for different accounts
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
there is no difference between these providers
provider "aws" {
  version = "~> 2.25.0"
  region  = var.aws_region
  alias   = "nonprod"
}

provider "aws" {
  version = "~> 2.25.0"
  region  = var.aws_region
  alias   = "prod"
}
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
they are the same
Brij S
Brij Sabout 7 years ago
thats a good point.. didnt notice that
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
they need to have some diff, e.g. region
Brij S
Brij Sabout 7 years ago
but the region is the same as well
Brij S
Brij Sabout 7 years ago
if i remove that main.tf from the module I get an error saying it needs it
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
they have to be diff otherwise why do you need them
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
provider "aws" {
  region                  = "us-west-2"
  shared_credentials_file = "/Users/tf_user/.aws/creds"
  profile                 = "customprofile"
}
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
diff region, or diff profile, or diff shared_credentials_file
Brij S
Brij Sabout 7 years ago
right, I can add profile but if that lives in the module I cant reuse it
Brij S
Brij Sabout 7 years ago
for another set of accounts
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
which tells the provider to use diff credentials from diff profile to access diff account
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
you need to add that
Brij S
Brij Sabout 7 years ago
if I leave profile in the main.tf in the module, then I cant reuse the module
Brij S
Brij Sabout 7 years ago
because another account will have a different profile
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
whatever you are saying you can’t reuse, does not make any diff for terraform 🙂
Brij S
Brij Sabout 7 years ago
so in my module, `/terraform/modules/somemodule i have a main.tf which includes a profile which is used for account A
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
you create a set of providers (they should differ by region or profile)
Brij S
Brij Sabout 7 years ago
differ by profile, yes
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
then for each module, you send a set of required providers
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
and in each resource use the provider aliases
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
there is no other way of doing it
Brij S
Brij Sabout 7 years ago(edited)
wait, in the module, the main.tf if I put a profile in
Brij S
Brij Sabout 7 years ago
how does the module become reusable if the profile is hardcoded for a certain account
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
the module is reusable because you send it a list of providers (which can contain only one)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
and the module uses that provider
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
w/o knowing the provider details
Brij S
Brij Sabout 7 years ago
yes I understand that
Brij S
Brij Sabout 7 years ago
so that means, I remove main.tf from my module?
Brij S
Brij Sabout 7 years ago
(which causes errors)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
not sure I understand that 🙂
Brij S
Brij Sabout 7 years ago
ok let me explain
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
you fix the error in main.tf
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
not remove it
Brij S
Brij Sabout 7 years ago
in /terraform/modules/somemodule/main.tf I have:

provider "aws" {
  version = "~> 2.25.0"
  region  = var.aws_region
  alias   = "nonprod"
}

provider "aws" {
  version = "~> 2.25.0"
  region  = var.aws_region
  alias   = "prod"
}


In /terraform/folder/main.tf I have:

provider "aws" {
  version    = "~> 2.25.0"
  region     = var.aws_region
  profile    = "storesnonprod"
  alias      = "nonprod"
}

provider "aws" {
  version    = "~> 2.25.0"
  region     = var.aws_region
  profile    = "storesprod"
  alias      = "prod"
}


In /terraform/folder/web.tf I have:

module "cicd-web" {
  source = "../../modules/somemodule"

  providers = {
    aws.nonprod = "aws.nonprod"
    aws.prod    = "aws.prod"
  }
Brij S
Brij Sabout 7 years ago
that is how im using the providers
PePe Amengual
PePe Amengualabout 7 years ago
can you have multiple providers in a module ?
PePe Amengual
PePe Amengualabout 7 years ago
I think you can but should you do it ?
Brij S
Brij Sabout 7 years ago
if I remove /terraform/somemodule/main.tf I get this error:

Error: Provider configuration not present

To work with
module.somemodule.aws_iam_policy_attachment.codepipeline_policy_attachment its
original provider configuration at module.somemodule.provider.aws.nonprod is
required, but it has been removed. This occurs when a provider configuration
is removed while objects created by that provider still exist in the state.
Re-add the provider configuration to destroy
module.somemodule.aws_iam_policy_attachment.codepipeline_policy_attachment,
after which you can remove the provider configuration again.
PePe Amengual
PePe Amengualabout 7 years ago
in my case I instantiate the module twice one with one provider and one with the other
PePe Amengual
PePe Amengualabout 7 years ago(edited)
look at this example
PePe Amengual
PePe Amengualabout 7 years ago
they don’t create one resource within two providers
Brij S
Brij Sabout 7 years ago(edited)
in my module I have multiple resources that have either provider = "aws.nonprod" or provider = "aws.prod"
PePe Amengual
PePe Amengualabout 7 years ago
mmm, maybe moving to a module that can do do any provider and the pass one provider to the module
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
ok, we are mixing up at least 4-5 diff concepts here 🙂
PePe Amengual
PePe Amengualabout 7 years ago
sorry
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
1. @Brij S if you created resources using a provider, you can’t just remove it. Delete the resources, then remove the providers from main.tf, then re-apply again
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
2. @Brij S your providers must be different (that’s after you do #1). Otherwise TF uses just the first one since they are the same (that’s why eveything gots created in just one account)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
3. @PePe Amengual you create a module, but don’t hardcode any provider in it. You can send the provider(s) to it IF nessessary
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
4. But in (almost) all cases, it’s not necessary. The only use-case you need to send provider(s) to a module is when your module is designed in such a way so it creates resources in diff regions or in diff accounts (bad idea)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
5. Creating such a module that creates resources in diff region is OK (in this case you can send it a list of providers that differ by region)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
6. Creating such a module that creates resources in diff accounts is bad idea
Brij S
Brij Sabout 7 years ago(edited)
@Andriy Knysh (Cloud Posse) could I show you the problem Im having? I dont have any resources created but i'm still getting the error
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
regarding #6 above: instead of thinking of creating modules that uses providers for diff accounts, it’s better to create yourself an environment which will allow you to login into diff accounts (by using diff profiles in ~./aws, and eveb better by assuming roles)
S
SweetOpsabout 7 years ago
Are you using some of our terraform-modules in your projects? Maybe you could leave us a testimonial! It means a lot to us to hear from people like you.
James D. Bohrman
James D. Bohrmanabout 7 years ago(edited)
Hey guys! I'm looking for some advice on how to approach an issue. I'm trying to figure out a way to use Terraform to provision a Windows Server 2016 instance that will run this cloud prep tool once it's provisioned. I want to do something with Packer down the line but right now I'm just trying to make an easy way to spin up cloud gaming rigs on AWS for myself.

Prep tool:
https://github.com/jamesstringerparsec/Parsec-Cloud-Preparation-Tool
James D. Bohrman
James D. Bohrmanabout 7 years ago(edited)
Bruce
Bruceabout 7 years ago
Hi @James D. Bohrman this might help “Deploying a Windows 2016 server AMI on AWS with Packer and Terraform. Part 1” by Bruce Dominguez https://link.medium.com/8hIu8JaK1Z
Bruce
Bruceabout 7 years ago
Does anyone have a good suggestion on creating a snapshot from a Rds database (that's encrypted) and restoring it to a Dev/testing Env and doing some data scrubbing?
joshmyers
joshmyersabout 7 years ago
Suggestions yes, any of them any good? Not so sure
joshmyers
joshmyersabout 7 years ago
Have seen this done in several ways, none of which were particularly nice
joshmyers
joshmyersabout 7 years ago
@Bruce https://github.com/hellofresh/klepto looked interesting in this space last time I checked
joshmyers
joshmyersabout 7 years ago
(probably not a discussion for this particular channel)
Bruce
Bruceabout 7 years ago
Thanks @joshmyers I will check it out. 👍️
Mike Whiting
Mike Whitingabout 7 years ago
is anyone able to advise on aws_ecs_task_definition. If I specify multiple containers in the task definition file then neither of the containers come up.
Mike Whiting
Mike Whitingabout 7 years ago
but if I have just one it works
joshmyers
joshmyersabout 7 years ago(edited)
@Mike Whiting you are really going to need to post your instantiation of the Terraform resource or whatever. What you expected. What the actual error message is etc
Mike Whiting
Mike Whitingabout 7 years ago
did you mean to @ me?
Mike Whiting
Mike Whitingabout 7 years ago
🙂
Mike Whiting
Mike Whitingabout 7 years ago(edited)
these are the resources:

resource "aws_ecs_task_definition" "jenkins_simple_service" {

//  volume {
//    name      = "docker-socket"
//    host_path = "/var/run/docker.sock"
//  }

  volume {
    name      = "jenkins-data"
    host_path = "/home/ec2-user/data"
  }
  family                = "jenkins-simple-service"
  container_definitions = file("task-definitions/jenkins-gig.json")
}

resource "aws_ecs_service" "jenkins_simple_service" {
  name            = "jenkins-gig"
  cluster         = data.terraform_remote_state.ecs.outputs.staging_id
  task_definition = aws_ecs_task_definition.jenkins_simple_service.arn
  desired_count   = 1
  iam_role        = data.terraform_remote_state.ecs.outputs.service_role_id

  load_balancer {
    elb_name       = data.terraform_remote_state.ecs.outputs.simple_service_elb_id
    container_name = "jenkins-gig"
    container_port = 8080
  }
}
Mike Whiting
Mike Whitingabout 7 years ago(edited)

[
  {
    "name": "jenkins-gig",
    "image": "my-image",
    "cpu": 0,
    "memory": 512,
    "essential": true,
    "portMappings": [
      {
        "containerPort": 8080,
        "hostPort": 8000
      }
    ],
    "environment" : [
      {
        "name" : "VIRTUAL_HOST",
        "value" : "<host>"
      },
      {
        "name": "VIRTUAL_PORT",
        "value": "8080"
      }
    ],
    "mountPoints": [
      {
        "sourceVolume": "jenkins-data",
        "containerPath": "/var/jenkins_home",
        "readOnly": false
      }
    ]
  },
  {
    "name": "nginx-proxy",
    "image": "jwilder/nginx-proxy",
    "cpu": 0,
    "memory": 512,
    "essential": true,
    "portMappings": [
      {
        "containerPort": 80,
        "hostPort": 80
      }
    ]
  }
]
Mike Whiting
Mike Whitingabout 7 years ago
if I remove the nginx-proxy container from the definition then ecs-agent successfully pulls and launches the jenkins container but with it included nothing happens
Mike Whiting
Mike Whitingabout 7 years ago
nb: 'my-image' is from a private registry and nginx-proxy is public
joshmyers
joshmyersabout 7 years ago
Do you have any error events being logged?
joshmyers
joshmyersabout 7 years ago(edited)
Are there creds for the private repo?
Mike Whiting
Mike Whitingabout 7 years ago
I'm just observing the ecs-agent logs currently (within the instance)
Mike Whiting
Mike Whitingabout 7 years ago(edited)
Mike Whiting
Mike Whitingabout 7 years ago
as I say, the container from the private image launches fine when I don't specifiy the proxy container in the definition file.. i.e. one container object
joshmyers
joshmyersabout 7 years ago
You hadn’t specific which one you can bring up on it’s own, or that one is in a private registry at that point
joshmyers
joshmyersabout 7 years ago
ECS agent logs should give you an idea
Mike Whiting
Mike Whitingabout 7 years ago
I can bring up the jenkins container (private image) on it's own
Mike Whiting
Mike Whitingabout 7 years ago
when the nginx-proxy definition is present ecs-agent just sits idle
Mike Whiting
Mike Whitingabout 7 years ago
does that make sense?
joshmyers
joshmyersabout 7 years ago
yes
Mike Whiting
Mike Whitingabout 7 years ago
what do you think I should try?
Mike Whiting
Mike Whitingabout 7 years ago
starting to wonder if terraform is really for me if I can't get help
Mike Whiting
Mike Whitingabout 7 years ago
(from anywhere)
joshmyers
joshmyersabout 7 years ago
Terraform is just making API calls for you
Mike Whiting
Mike Whitingabout 7 years ago
yep
oscar
oscarabout 7 years ago
The tags for this module are so confusing:
https://github.com/cloudposse/terraform-aws-rds/releases
oscar
oscarabout 7 years ago
I’ve been using 0.11 by mistake as I took the ‘latest’ tag
oscar
oscarabout 7 years ago
but that’s actually just a hotfix
oscar
oscarabout 7 years ago
the latest .12 tag ios 0.10
oscar
oscarabout 7 years ago
true I could have read the list and lesson learned, but had me stumped for a while as to why it wasn’t working!
oscar
oscarabout 7 years ago
@Andriy Knysh (Cloud Posse) I think I was doing the PR as you commented! https://github.com/cloudposse/terraform-aws-rds/pull/38
oscar
oscarabout 7 years ago(edited)
Debate/Conversation:

“We should enable deletion_protection for production RDS”

https://www.terraform.io/docs/providers/aws/r/db_instance.html#deletion_protection
asmito
asmitoabout 7 years ago
better to enable it, but usually when you want to delete an RDS instance aws takes a snapshot of it as back up.
asmito
asmitoabout 7 years ago
guys do you know when we will have count enabled for module
asmito
asmitoabout 7 years ago
?
C
Cloud Posseabout 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 Sep 25, 2019 11:30AM.

👉️ Register for Webinar

:slack: #office-hours (our channel)
Mike Whiting
Mike Whitingabout 7 years ago
I've had a brainwave that perhaps I need to add another dedicated aws_ecs_service resource for the nginx-proxy - see my example code above. is this a possibility?
oscar
oscarabout 7 years ago
Is there a MKS/Kafka module anywhere?
Tehmasp Chaudhri
Tehmasp Chaudhriabout 7 years ago
Has anyone solved a solution for dynamically determining which subnets are free in a given VPC to then use for deploying some infrastructure into? Or know of some examples?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
what do you mean by are free? 🙂
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
you can use https://www.terraform.io/docs/providers/aws/d/subnet_ids.html to get all subnets for a VPC
Brij S
Brij Sabout 7 years ago
does TF support inline code for lambda functions like cloudformation?
Hemanth
Hemanthabout 7 years ago
Inside terraform(.tf) i can use assign dynamic stuff using variables like - key_name = "${var.box_key_name}" for different environments, how can i do the same inside the user-data scripts attached to tf, i am tyring to have unique values for sudo hostnamectl set-hostname jb-*environtmenthere* in the user-data script
PiotrP
PiotrPabout 7 years ago
hi gents, has any one of you succesfully created s3 bucket module with dynamic cors configuration?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
not sure what you mean by ‘dynamic configuration’, but take a look here https://github.com/cloudposse/terraform-root-modules/blob/master/aws/docs/main.tf#L79
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
that’s how we deploy https://docs.cloudposse.com/
James D. Bohrman
James D. Bohrmanabout 7 years ago(edited)
Here's a little tool I've been working on that the gamers here might like. I used a lot of Cloud Posse modules also 😉

https://github.com/jdbohrman/parsec-up
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago
@Andriy Knysh (Cloud Posse) finally 😃 😃 so apparently A) Terraform state loading is private to itself in the UI and Command code, so I will need to talk to either paul or terraform team about it, B) and good news 😃 finally find out that loading in terraform is implicit cascading
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago(edited)
so if you have two file , call it main.tf and data.tf, then you state ForceFileSource on main.tf to be "" then do LoadConfigDir
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago
terraform will declare main.tf to be empty
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago
and skip reading
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago
is useful, since I need it to do resource & data types gathering for error checking
oscar
oscarabout 7 years ago
Anyone seen the issue where you curl from an EKS worker node to the cluster and get SSL issues?
oscar
oscarabout 7 years ago
Using CP worker / cluster / asg modules.
oscar
oscarabout 7 years ago
curl: (60) SSL certificate problem: unable to get local issuer certificate
oscar
oscarabout 7 years ago
… this is curling the API endpoint as per EKS
oscar
oscarabout 7 years ago
@Addison Higham I’m using your branches from here https://sweetops.slack.com/archives/CB6GHNLG0/p1566415698381800

Error: Invalid count argument

  on .terraform/modules/eks_workers.autoscale_group/ec2-autoscale-group/main.tf line 120, in data "null_data_source" "tags_as_list_of_maps":
 120:   count = var.enabled ? length(keys(var.tags)) : 0

The "count" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the count depends on.
oscar
oscarabout 7 years ago
but getting the following error. Could you provide any guidance on what you think that might be?
Addison Higham
Addison Highamabout 7 years ago
yeah, that was an oopsie, a fix got merged... but maybe it didn't make it onto the branch I was trying to upstream
Addison Higham
Addison Highamabout 7 years ago
lemme find it
oscar
oscarabout 7 years ago
Thanks. If possible could you push it to your fork’s master? 🙂 I did try your inst-* branch but that didn’t seem to quite fix it
Addison Higham
Addison Highamabout 7 years ago
oh that is a different issue @oscar, what are you passing to tags? as the error message says, it can't have anything dynamic being passed in
oscar
oscarabout 7 years ago
tags is actually empty
oscar
oscarabout 7 years ago
I’m passing var.tags which is an empty {} in my terraform proejct that calls your eks_worker module
oscar
oscarabout 7 years ago
so am I correct in using your worker & cluster branches @master branch?
oscar
oscarabout 7 years ago
because I’m aware you also have the ASG one updated, but do the master branches of worker and cluster point to that?
Addison Higham
Addison Highamabout 7 years ago
oh yeah, so that is why we use the inst-version, which does this: https://github.com/instructure/terraform-aws-eks-cluster/pulls?utf8=%E2%9C%93&q=is%3Apr
Addison Higham
Addison Highamabout 7 years ago
to be safe, whenever I change refs, I also just delete .terraform directory and re-init
Addison Higham
Addison Highamabout 7 years ago
it is sorta weird, we didn't want to open a PR to our updated module, but they do need to merge them in order for these to work
oscar
oscarabout 7 years ago
Ya I understand the need for the branch. I'll give another go later on.
oscar
oscarabout 7 years ago
So worker inst
Cluster master
oscar
oscarabout 7 years ago
And that should fix my previous issue with count?
Addison Higham
Addison Highamabout 7 years ago
I think so? at least that is what we have and don't have any issues
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
public #office-hours starting now! join us to talk shop https://zoom.us/j/508587304
oscar
oscarabout 7 years ago
@Addison Higham - darn still got the same issue
oscar
oscarabout 7 years ago

module "eks_cluster" {

  source     = "git::<https://github.com/instructure/terraform-aws-eks-cluster.git?ref=master>"
...
}

module "eks_workers" {
  source = "git::<https://github.com/instructure/terraform-aws-eks-workers.git?ref=inst-version>"
...
Addison Higham
Addison Highamabout 7 years ago
same error?
oscar
oscarabout 7 years ago
Yeh
oscar
oscarabout 7 years ago(edited)

Error: Invalid count argument

  on .terraform/modules/eks_workers.autoscale_group/main.tf line 120, in data "null_data_source" "tags_as_list_of_maps":
 120:   count = var.enabled ? length(keys(var.tags)) : 0

The "count" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the count depends on.


module "eks_workers" {
  source = "git::<https://github.com/instructure/terraform-aws-eks-workers.git?ref=inst-version>"

  namespace     = var.namespace
  stage         = var.stage
  name          = var.name
  tags          = var.tags
...
}
oscar
oscarabout 7 years ago
var.tags is empty (defaulting to {})
Addison Higham
Addison Highamabout 7 years ago
is your cluster_name dynamic? see https://github.com/instructure/terraform-aws-eks-workers/blob/master/main.tf#L2, the workers module computes some tags, so your cluster_name needs to be known at plan time
oscar
oscarabout 7 years ago
Omg
oscar
oscarabout 7 years ago
that must be it
Addison Higham
Addison Highamabout 7 years ago
that is why in the example you see them use the label module to compute the name of the cluster in multiple distinct places
oscar
oscarabout 7 years ago

# mine
  cluster_name                       = "${module.eks_cluster.eks_cluster_id}"
oscar
oscarabout 7 years ago
Will hardcode to a string for now
oscar
oscarabout 7 years ago
Super thanks. Cluster and workers up now
oscar
oscarabout 7 years ago
But back to workers not connecting to cluster.
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago
@Andriy Knysh (Cloud Posse) XD XD XD XD XD, so I found the biggest issue that is causing vs code users for using the terraform lsp plugin, I forgot to omit the hover provider from the first release that I was trying out(so is very error prone), since I only use vim, so there is no hover that get activated
Julio Tain Sueiras
Julio Tain Sueirasabout 7 years ago
so now is alot more stable for any GUI based Editor that is going to use terraform-lsp
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
@Justin Grote btw, didn't realize you were on sweetops. We discussed your comment today #office-hours today 😃 https://github.com/hashicorp/terraform/issues/15966#issuecomment-520102463 (@sarkis had originally directed my attention to it)
Justin Grote
Justin Groteabout 7 years ago
@Justin Grote has joined the channel
rohit
rohitabout 7 years ago
i am facing issues with pre-commit when using in my terraform project
rohit
rohitabout 7 years ago
repos:
- repo: <git://github.com/antonbabenko/pre-commit-terraform>
  rev: v1.15.0
  hooks:
    - id: terraform_fmt
    - id: terraform_docs_replace
rohit
rohitabout 7 years ago
i receive the following error
rohit
rohitabout 7 years ago
 pkg_resources.DistributionNotFound: The 'pre-commit-terraform' distribution was not found and is required by the application
rohit
rohitabout 7 years ago
rohit
rohitabout 7 years ago
any ideas on what could be the problem ?
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
---
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
good read
Brij S
Brij Sabout 7 years ago(edited)
if ive got a module such as:
module "vpc_staging" {
  source = "./vpc_staging"
}


can I access a variable/output created in that module in another module like so?

module "security-group" {
  source  = "terraform-aws-modules/security-group/aws"
  version = "1.25.0"

  name = "sg"
  description = "Security group for n/w with needed ports open within VPC"
  vpc_id     = "${module.vpc_staging.vpc_id}"

}


Would I use the variable name, or output id? What do I reference basically?
Claudio Palmeira
Claudio Palmeiraabout 7 years ago
Hey guys, I do have a problem with the examples on the eks_cluster, more specifically on the subnets module
It has an unssoported argument there:
Claudio Palmeira
Claudio Palmeiraabout 7 years ago
An argument named "region" is not expected here.
Claudio Palmeira
Claudio Palmeiraabout 7 years ago
unsupported
Claudio Palmeira
Claudio Palmeiraabout 7 years ago
module subnets on main.tf:
this line -> region = "${var.region}"
Terraform complains about it not being an expected argument
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
the example is not actually correct since the EKS modules are TF 0.11, but the subnet module are pinned to master which is already 0.12
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
we are working on converting EKS modules to 0.12
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
for now, pin the subnet module to a TF 0,11 release
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
module "subnets" {
  source              = "git::<https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.12.0>"
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
pin to 0.4.1 which is TF 0.11
Claudio Palmeira
Claudio Palmeiraabout 7 years ago
Thank you mate
oscar
oscarabout 7 years ago
How come only the creator of the EKS cluster can connect using the CP moduels?
oscar
oscarabout 7 years ago
https://github.com/hashicorp/terraform/issues/22649 anyone experiencing this out of nowhere? (All devs using the state file are on 0.12.6)
PePe Amengual
PePe Amengualabout 7 years ago
stupid question I’m using
locals {
  availability_zones = slice(data.aws_availability_zones.available.names, 0, 2)
}
PePe Amengual
PePe Amengualabout 7 years ago
but sometimes my resources end up in the same AZ
PePe Amengual
PePe Amengualabout 7 years ago
better to just hardcode them ?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
@PePe Amengual what do you mean by sometimes? When in diff regions?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
the code above is ok and should work
PePe Amengual
PePe Amengualabout 7 years ago
same region
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
no need to hardcode anything
PePe Amengual
PePe Amengualabout 7 years ago
PePe Amengual
PePe Amengualabout 7 years ago(edited)
I’m using the terraform terraform-aws-rds-cluster module
PePe Amengual
PePe Amengualabout 7 years ago
which I’m going to send a PR to support global clusters
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
that example worked many times
PePe Amengual
PePe Amengualabout 7 years ago
I know is weird because if I recreate the cluster then it will work
PePe Amengual
PePe Amengualabout 7 years ago
I wonder now….maybe I just have a problem in one region
PePe Amengual
PePe Amengualabout 7 years ago
PePe Amengual
PePe Amengualabout 7 years ago
we use TF to create the accounts so in every region we subnets for every AZ
PePe Amengual
PePe Amengualabout 7 years ago
I was wondering if for some reason we made a mistake or something
PePe Amengual
PePe Amengualabout 7 years ago
but I’m using a data lookup to find them base on tags
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
yea check the data lookup if it returns the correct result
PePe Amengual
PePe Amengualabout 7 years ago
exactly what I’m doing
PePe Amengual
PePe Amengualabout 7 years ago
I’m gettin 3 subnet ids in us-east-1 and 4 in us-west-2
PePe Amengual
PePe Amengualabout 7 years ago
so the data lookups are good
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
PePe Amengual
PePe Amengualabout 7 years ago
cluster_size = 2 and I pass 4 subnets, then it should be ok
Brandon Wilson
Brandon Wilsonabout 7 years ago
Has anyone else run into the issue where you can’t pass variables via the command line when using the remote backend since last week when they released terraform cloud?
Brandon Wilson
Brandon Wilsonabout 7 years ago
Error: Run variables are currently not supported

The "remote" backend does not support setting run variables at this time.
Currently the only to way to pass variables to the remote backend is by
creating a '*.auto.tfvars' variables file. This file will automatically be
loaded by the "remote" backend when the workspace is configured to use
Terraform v0.10.0 or later.

Additionally you can also set variables on the workspace in the web UI:
<https://app.terraform.io/app/Boulevard/sched-dev-feature-branch-environments/variables>
PePe Amengual
PePe Amengualabout 7 years ago
Global cluster support PR @Andriy Knysh (Cloud Posse) https://github.com/cloudposse/terraform-aws-rds-cluster/pull/56
Szymon
Szymonabout 7 years ago
Azure
Hi everyone, I'm about to move my big terraform configuration into separate modules, but I have a question about best practice regarding resource-groups.
If I will create resource-group resource in every of my modules, it will be fine, because it will be created once, but when for some reason I will remove entire module or I will try to redeploy it, wouldn't Terraform want to delete my resource group (and all other resources-modules)? Should I rather use data resource to make reference to resource group created in another module or what are your ideas?
Thanks
gyoza
gyozaabout 7 years ago(edited)
hey guys… not sure whats going on but it looks like the 0.9.0 - terraform-aws-cloudfront-s3-cdn module is creating ARN IDs like

“arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity XXXXXXXXXXXXXXXX”

for S3 policies to allow Cloudfront access
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
ah that's a new issue
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
I just encountered it today
gyoza
gyozaabout 7 years ago
oh thank god.
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
AWS changed how the API behaves
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
in the background
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
if you need a quick fix
gyoza
gyozaabout 7 years ago
I literally thought i was going crazyh
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
hahah it happened to me as well 😄
gyoza
gyozaabout 7 years ago
i do ,. please 🙂
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
sec
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
the glorious fix is
gyoza
gyozaabout 7 years ago
aaaaah
gyoza
gyozaabout 7 years ago
can i just downgrade my provider version?
gyoza
gyozaabout 7 years ago
lets take a peak
Nikola Velkovski
Nikola Velkovskiabout 7 years ago

    principals {
      type        = "AWS"
      identifiers = [replace("${aws_cloudfront_origin_access_identity.this.iam_arn}", " ", "_")]
    }
gyoza
gyozaabout 7 years ago
Thank you!
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
for now you should be able to patch it until
@Andriy Knysh (Cloud Posse) or @Erik Osterman (Cloud Posse) wake up and officialy fix it 🙂
gyoza
gyozaabout 7 years ago
haha Erik is a long time friend of mine, i can hold something over him i think to get it fixed
gyoza
gyozaabout 7 years ago
😄
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
😄
gyoza
gyozaabout 7 years ago
although, I was the one who was usually embarrassing themselves…
gyoza
gyozaabout 7 years ago
I think using the replacements only works for current state files, if you’re doing new policies you have to use type CanonicalUser and identifier s3_canonical_user_id
gyoza
gyozaabout 7 years ago
aaaah
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
nope that's not going to work
gyoza
gyozaabout 7 years ago
It just applied for me.
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
even though CanonicalUser and identifier s3_canonical_user_id will pass tf apply
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
try it again 🙂
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
aws is changing it in the background
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
you'll get a change on every apply
gyoza
gyozaabout 7 years ago
really
gyoza
gyozaabout 7 years ago
ugh
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
at least that's what happened to me 🙂
gyoza
gyozaabout 7 years ago
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
gyoza
gyozaabout 7 years ago
damn
gyoza
gyozaabout 7 years ago
It wont take the replace suggestion, keeps telling me bad
gyoza
gyozaabout 7 years ago
Error: Error putting S3 policy: MalformedPolicy: Invalid principal in policy
gyoza
gyozaabout 7 years ago
gonna try something
gyoza
gyozaabout 7 years ago
it was too early, i was using dashes lol….
gyoza
gyozaabout 7 years ago
underscores work
gyoza
gyozaabout 7 years ago
thanks for the help Nikola!
gyoza
gyozaabout 7 years ago
gonna lurk here now….
gyoza
gyozaabout 7 years ago
😄
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
you are welcome 🙂
guigo2k
guigo2kabout 7 years ago
guys, any update on this https://sweetops.slack.com/archives/CB6GHNLG0/p1566415698381800 ? Really looking forward to use these modules with TF 0.12
Dan
Danabout 7 years ago
If I create NATs in one module, is there a way to get a list of NAT GW and pass it to a new sg with TF?
oscar
oscarabout 7 years ago
C
Cloud Posseabout 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 Oct 02, 2019 11:30AM.

👉️ Register for Webinar

:slack: #office-hours (our channel)
Szymon
Szymonabout 7 years ago(edited)
Hi guys,
Any of you has experience with maintenance of SaaS environments? What I mean is some dev, test, prod environments separate for every Customer?
In my case, those environments are very similar, at least the core part, which includes, vnet, web apps in Azure, VM, storage… All those components are currently written as modules, but what I’m thinking about is to create one more module on top of it, called e.g. myplatform-core. The reason why I want to do that is instead of copying and pasting puzzles of modules between environments, I could simply create env just by creating/importing my myplatform-core module and passing some vars like name, location, some scaling properties.
Any thoughts about it, is it good or bad idea in your opinion?

I appreciate your input.
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
the idea is good. That’s how we create terraform environments (prod, staging, dev, etc.). We have a catalog of terraform modules (just code without settings/configs). Then for each env, we have a separate GitHub repo where we import the modules we need (using semantic versioning so we know exactly which version we are using in which env) and provide all the required config/settings for that environment, e.g. AWS region, stage (prod, staging, etc.), and security keys (from ENV vars or AWS SSM)
Szymon
Szymonabout 7 years ago
As I understand, you’re actually not creating a Terraform Module of your core/base infra, but instead you have catalogs/repos per environment with versioned “module puzzles”?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
for example, we have a catalog of TF modules - reusable code which we can use in any env (prod, staging, dev, testing) https://github.com/cloudposse/terraform-root-modules/tree/master/aws
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
the code does not have any identity, it could be deployed anywhere after providing the required config/settings
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
then for example, in testing env, we create projects for the modules we need (e.g. eks), https://github.com/cloudposse/testing.cloudposse.co/blob/master/conf/eks
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
and load the module code from the catalog https://github.com/cloudposse/testing.cloudposse.co/blob/master/conf/eks/.envrc (uisng semantic versioning)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
but all the config/settings are provided from a few places:
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
2. Dockerfile (in which we have settings common for all modules in the project) https://github.com/cloudposse/testing.cloudposse.co/blob/master/Dockerfile
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
3. Secrets are from ENV vars (which get populated from diff sources, e.g. AWS SSM, Secrets Manager, Vault, etc.) when the CI/CD deployment pipeline runs, or on dev machine by executing some commands)
Szymon
Szymonabout 7 years ago
I see, thank you very much 🙂 I started with different approach, I keep all my environments in one Terraform Repository with projects and I include modules from external git repositories (each module in separate git repository)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
that’s what we do too
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
https://github.com/cloudposse/terraform-root-modules is a (super)-catalog of top level modules which are aggregations of low-level modules
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
each projects in there connects low-level modules together into a reusable top-level module https://github.com/cloudposse/terraform-root-modules/blob/master/aws/eks/eks.tf#L31
Szymon
Szymonabout 7 years ago
ah, right
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
those aggregations are opionated since you can have many diff ways to connect low-level modules to create a top-level module you need
Szymon
Szymonabout 7 years ago
Interesting approach. I was reading quite a lot recently, best practices with Terraform,TF Up & Running etc. and in most cases people don’t recommend using nested modules, but it looks really reasonable in your case.
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
they are not nested (in that sense)
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
those are module instantiation and connecting them together into a bigger module
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
that’s why we have modules in TF - to reuse them
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
in other modules
Szymon
Szymonabout 7 years ago
Actually that was my understanding of nested word, sorry. English is not my first language 😄
joshmyers
joshmyersabout 7 years ago
By nested modules, they mean modules of modules. Cloudposse stuff does use modules of modules e.g. module A may use module B, and module B may use module C
joshmyers
joshmyersabout 7 years ago
It works fine, but can be interesting to debug several layers down
joshmyers
joshmyersabout 7 years ago
If you want composable modules, there isn't much of a way around that
joshmyers
joshmyersabout 7 years ago
And by they, I mean folks behind tf up and running etc
Vlady Veselinov
Vlady Veselinovabout 7 years ago
hi y'all :bananadance:
Hemanth
Hemanthabout 7 years ago
Any samples/examples for implementing Cloudwatch events>create new rule>Ec2 Instance State-Change Notification > Target > SNS > email, currently going through official docs
Igor
Igorabout 7 years ago(edited)
@Hemanth you cannot create email subscription to an SNS topic with terraform, because they require a confirmation
Callum Robertson
Callum Robertsonabout 7 years ago
Hey All, has anyone had issues creating azure resources with an s3 backend?
Igor
Igorabout 7 years ago
Otherwise, you just want to create the following resources: aws_cloudwatch_metric_alarm, aws_sns_topic, and aws_sns_topic_subscription
gyoza
gyozaabout 7 years ago
re: https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn/pull/51 @Andriy Knysh (Cloud Posse) if you make this change every terraform plan will produce a change
gyoza
gyozaabout 7 years ago
you just need to replace ” “, “_” on the old value
cabrinha
cabrinhaabout 7 years ago
You guys using terraform cloud at all yet?
leonawood
leonawoodabout 7 years ago
Can you use terraform_remote_state data source as an input attribute for subnet in the cloudposse aws ec2 module?
leonawood
leonawoodabout 7 years ago
I am using the terraform approved aws vpc module to create my VPC, and have correctly setup all my outputs, one specific being a public_subnet ID
and I am trying to reference said subnet ID as a terraform_remote_state data source as the subnet attribute but am not sure of the proper syntax
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
leonawood
leonawoodabout 7 years ago
hey @Andriy Knysh (Cloud Posse) that helped me
leonawood
leonawoodabout 7 years ago
thank you!
Brij S
Brij Sabout 7 years ago
I have a terraform module in which we use to setup new AWS accounts with certain resources. So this module is generic enough to use on 'dev' aws account, 'qa' account and 'prod' account for say. However, I need to only create some resources based on the environment. How can I achieve this with a module? I saw this online: https://github.com/hashicorp/terraform/issues/2831
Brij S
Brij Sabout 7 years ago
is this still the best way?
Brij S
Brij Sabout 7 years ago
was about to try that out but read that if the count is set to 0, it would destroy the resource ?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
for all resources in the module, you could use count = var.environment == "prod" ? 1 : 0 or count = var.environment == "qa" ? 1 : 0 etc.
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
or any combination of the conditions
Brij S
Brij Sabout 7 years ago
so adding count = var.environment == "prod" ? 1 : 0 would ensure the resource is only created in prod?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
it will ensure that if var.environment == "prod" then the resource will be created. If you run it in prod, it will be in prod.
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
at the same time, you could make a mistake and set var.environment == "prod" and run it in dev, then it will be created as well in dev 🙂
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
@Brij S you need some kind of container (or separate repo) where you set all configs for let’s say prod (e.g. region and AWS prod account ID) and where you set var.environment == "prod"
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
when you run it, it will be used only in the prod account and since var.environment == "prod", the resource will be created
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
so a better strategy would be not to create a super-giant module with many conditions to create resources or not
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
divide the big module into small modules
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
then use some tools to combine only the required modules into each account repo
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
the tool could be terragrant or what we do using geodesic and remote module loading https://www.reddit.com/r/Terraform/comments/afznb2/terraform_without_wrappers_is_awesome/
leonawood
leonawoodabout 7 years ago
anyone here split up state files? we use tf workspaces and it works quite nicely. I am interested if theres a way to combine all the outputs into one file tho for reference?
leonawood
leonawoodabout 7 years ago
so I can just send to our sys admin and it contain all the relevant details
Brij S
Brij Sabout 7 years ago
@Andriy Knysh (Cloud Posse) i will look into terragrunt, as for now Id like to use the above suggestion with TF11, but having some issue with syntax:
${var.aws_env} == "prod" ? "1" : "0" doesnt work - what am i missing?
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago(edited)
"${var.aws_env == "prod" ? 1 : 0}"
Brij S
Brij Sabout 7 years ago(edited)
what about the closing }
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
need it too 🙂
Brij S
Brij Sabout 7 years ago
🙂 cool let me try that
johncblandii
johncblandiiabout 7 years ago
Brij S
Brij Sabout 7 years ago
is there a way to create an IAM user, generate access keys and plug them into paramstore with terraform?
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 ?
kj22594
kj22594about 7 years ago
Hi all,

I’ve been using terraform (0.10 & 0.11) for close to three years now and as terraform 0.12 gets more support/becomes more of the industry standard, my team is looking to adopt it in a way where we can rearchitect our terraform structure, and reduce the general number of pain points across the team.

Currently we are a multi-region AWS shop that has single terraform repos for every service we deploy, with modules at the root of the repo, and directories representing each of our environments (qa-us-east-1, qa-eu-west-1). We run terraform from within those environment specific directories and push remote state to S3 to maintain completely separate state.

We’re thinking about how we can merge all of this into a single repo where:
- There are modules that can be reused across all of our different services (they’d either live at the root of the base terraform repo or in a separate terraform modules repo that we can reference from within our base repo)
- We duplicate as little code as possible (probably obvious but still worth mentioning)
- We continue to keep all state separate on a per environment basis
- Follow terraform best practices to make sure that upgrade paths continue to be easy/straightforward


We also want to keep in mind that we are shifting to a multi account AWS organization where our terraform will be deploying into different AWS accounts as well.

The team so far has demoed both Terragrunt and Terraform Workspaces. We are also considering not using workspaces or Terragrunt but still migrating to the single repo structure. There have been mixed opinions about all options considered. I’d love to get feedback from the community if anyone has opinions based on current or previous experiences with either.
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
@kj22594 take a look here, similar conversation https://sweetops.slack.com/archives/CB6GHNLG0/p1569261528160800
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
public #office-hours starting now! join us to talk shop https://zoom.us/j/508587304
Robert
Robertabout 7 years ago
Hey does anyone have a terraform party slackmoji?
Robert
Robertabout 7 years ago
I will trade you one terraform-unicorn-dab slackmoji.
Robert
Robertabout 7 years ago
Maarten van der Hoef
Maarten van der Hoefabout 7 years ago
lol 😄
Robert
Robertabout 7 years ago
I was hoping for something like my kubernetes party:
Robert
Robertabout 7 years ago
I stole that form kubernetes.slack.com
Robert
Robertabout 7 years ago
I just made it!
Robert
Robertabout 7 years ago
Robert
Robertabout 7 years ago
Probably not my best work, but not bad for a first gif
Robert
Robertabout 7 years ago
¯\(ツ)/¯
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
I've added :terraform-party: :k8s-party: and :terraform-unicorn:
Joan Hermida
Joan Hermidaabout 7 years ago
Niiice!
Joan Hermida
Joan Hermidaabout 7 years ago
Where do I get that unicorn 🦄 XD
Joan Hermida
Joan Hermidaabout 7 years ago
I really need it in my workspace
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 7 years ago
1) download the icons above
2) go here https://$<http://team.slack.com/customize/emoji|team.slack.com/customize/emoji> where $team is your slack team
Joan Hermida
Joan Hermidaabout 7 years ago
Ohhh it is above
Joan Hermida
Joan Hermidaabout 7 years ago
XD
Rajesh Babu Gangula
Rajesh Babu Gangulaabout 7 years ago
@here I am trying to upgrade from v.11.14 to v.12 and after going through the upgrade steps and fixing some code changes ... now I am seeing following issue

Error: Missing resource instance key

  on .terraform/modules/public_subnets.public_label/outputs.tf line 29, in output "tags":
  29:         "Stage", "${null_resource.default.triggers.stage}"

Because null_resource.default has "count" set, its attributes must be accessed
on specific instances.

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

did anyone faced similar issue and was able to fix it
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
you have to provide values for all variables
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
or to use the .tfvar files, use :
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
terraform plan -var-file="fixtures.us-west-1.tfvars"
terraform apply -var-file="fixtures.us-west-1.tfvars"
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
but don’t use out values
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
change them
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
you can provide values for the vars from many diff places https://www.terraform.io/docs/configuration/variables.html
rohit
rohitabout 7 years ago(edited)
how do you provide credentials to private terraform github repository module ?
Bruce
Bruceabout 7 years ago
Hey guys, I am looking for the best way to roll back a change to an ASG to the previous known working ami as part of CICD pipeline with Terraform. Thinking of using a script to tag the previous AMI and using that to identify last known config. Has anyone else solved this problem?
Andrew Roth
Andrew Rothabout 7 years ago
I've been asked to provision 3 EKS clusters: Dev, Staging, and Prod. What is the way that you guys do this? Currently, I'm thinking of

- Having 3 branches in my git repo called "dev", "staging", and "prod"
- Having 3 .tfvars files called dev.tfvars, staging.tfvars, prod.tfvars
- If I commit to dev, My CICD runs terraform apply using a workspace called dev, using dev.tfvars
Nikola Velkovski
Nikola Velkovskiabout 7 years ago
Hi @Andrew Roth, personally I am a fan of workspaces. We used to have to have this setup but without the fixed branches, CI/CD automaticaly deployed a branch to staging and for prod it was a interactive apply ( if tests passed )
C
Cloud Posseabout 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 Oct 09, 2019 11:30AM.

👉️ Register for Webinar

:slack: #office-hours (our channel)
Milos Backonja
Milos Backonjaabout 7 years ago(edited)
Guys,
i've been using https://github.com/cloudposse/terraform-aws-vpc-peering to peer two vpcs and it works awesome.
On current project I need to peer N numbers of VPC's all with each other. As number of VPCs grows it become pretty hard to manage everything even with terraform. Is there any way to dynamically create peering mesh? CIDRs are carefully chosen so there will be no overlapping and I can fetch all vpcs with single data source. This shot from AWS describes my setup perfectly
PePe Amengual
PePe Amengualabout 7 years ago
Stephane Minisini
Stephane Minisiniabout 7 years ago
@Milos Backonja I would look into Transit Gateway. This allows you to have a hub and spoke type of network and manage the routing tables centrally.
rbadillo
rbadilloabout 7 years ago
Hi Guys, does anyone here using Terraform Enterprise ?
Joan Hermida
Joan Hermidaabout 7 years ago
Hub n' Spoke with VPC Transit Gateway
Brij S
Brij Sabout 7 years ago
does anyone know how to add private subnets to the default vpc using terraform?
PePe Amengual
PePe Amengualabout 7 years ago
Don’t use the default pvc, it is bad practice…
Brij S
Brij Sabout 7 years ago
is there a module that creates a vpc with private subnet?
PePe Amengual
PePe Amengualabout 7 years ago
yes, just go to clousposse github and search for vpc and subnets
PePe Amengual
PePe Amengualabout 7 years ago
we use their modules and they work great
Andriy Knysh (Cloud Posse)
Andriy Knysh (Cloud Posse)about 7 years ago
Brij S
Brij Sabout 7 years ago
specifically lines 5-24, right?
PePe Amengual
PePe Amengualabout 7 years ago
yes