cloudposse / terraform-aws-ec2-instance

Terraform module for provisioning a general purpose EC2 host
https://cloudposse.com/accelerate
Apache License 2.0
166 stars 220 forks source link

fix: Make able apply module in one run when aws_iam_instance_profile created in the same state #193

Closed MaxymVlasov closed 5 months ago

MaxymVlasov commented 5 months ago

what

Bypassing call to data "aws_iam_instance_profile" "given".

Prevent module fails here: https://github.com/cloudposse/terraform-aws-ec2-instance/blob/596216fbdec0f1a9246c24cf1bd51e23e5734a15/main.tf#L84-L87

when you run terraform plan and when you create an instance profile in the same root module

resource "aws_iam_instance_profile" "default" {
  count = module.this.enabled ? 1 : 0
  name  = module.this.id
  role  = aws_iam_role.default[0].name
}

module "mongodb_ec2" {
  source  = "cloudposse/ec2-instance/aws"
  version = "1.2.1"

  instance_profile = aws_iam_instance_profile.default[0].name
  ...

why

Currently, you need to create IAM somewhere else or in 2 applies, otherwise you'' face next error:

325991566-fab9934f-c4a3-411a-8a18-dd0cb5aa2830

P.S. I don't get how to run terraform-docs in this repo, so some additional polishing could be needed. Plus var name probably could be better

MaxymVlasov commented 5 months ago

nwm, we just need to unset instance_profile