Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create multiple resources using same terragrunt.hcl file #3426

Open
mjohn7421 opened this issue Sep 20, 2024 · 1 comment
Open

Create multiple resources using same terragrunt.hcl file #3426

mjohn7421 opened this issue Sep 20, 2024 · 1 comment

Comments

@mjohn7421
Copy link

Below is the input section for one of my terragrunt.hcl file. This one will create 1 vpc endpoint resource, suppose if i have 5 vpc endpoints to create, should we create 5 terragrunt.hcl file to provide inputs for those 5? can we achieve this via single terragrunt.hcl file by providing multiple inputs?

inputs = { eks_cluster_name = env_vars.cluster_name tags = local.tags vpc_id = local.vpc_outputs.vpc_id.value route_table_ids = var.vpc_outputs.private_route_table_ids. name = "vault" endpoint_type = "Interface" interface_endpoint_service_name = vault_endpoint_service_name subnet_ids = try(local.vpc_outputs.private_subnets.value, ["subnet-123456", "subnet-123456", "subnet-123456"]) create_vpc_endpoint = include.env_vars.locals.create_cog_infra }

@denis256
Copy link
Member

denis256 commented Sep 20, 2024

Hi,
I think bhis can be achieved by changing Terraform code to support list of inputs...

# terraform
variable "endpoints" {
  type = list(object({
    name                            = string
    endpoint_type                   = string
    interface_endpoint_service_name = string
    subnet_ids                      = optional(list(string), [])
  }))
}

...
resource "aws_vpc_endpoint" "this" {
  for_each = { for idx, endpoint in var.endpoints : idx => endpoint }

  vpc_id              = var.vpc_id
  service_name        = each.value.interface_endpoint_service_name
  vpc_endpoint_type   = each.value.endpoint_type
  subnet_ids          = each.value.subnet_ids
  private_dns_enabled = true

  tags = merge(
    var.tags,
    {
      Name = each.value.name
    }
  )
}


# terraform.hcl

inputs = {
...
  endpoints = [
    {
      name                            = "vault"
      endpoint_type                   = "Interface"
      interface_endpoint_service_name = vault_endpoint_service_name
      subnet_ids                      = ["subnet-123456", "subnet-123456", "subnet-123456"]
    },
    {
      name                            = "s3"
      endpoint_type                   = "Gateway"
      interface_endpoint_service_name = s3_endpoint_service_name
      subnet_ids                      = ["subnet-234567", "subnet-234567", "subnet-234567"]
    }
...
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants