Is there an existing issue for this?
Description of the bug
When attempting to assign a kms key as the default ebs encryption key in the ap-southeast-4 region, I get the following error:
Error: Invalid index
on outputs.tf line 8, in output "code":
8: value = local.region_codes[data.aws_region.this.id]
โโโโโโโโโโโโโโโโโ
โ data.aws_region.this.id is "ap-southeast-4"
โ local.region_codes is object with 25 attributes
it appears to be due to the referenced locals not including the region provided:
locals {
region = data.aws_region.this.name
region_codes = {
"us-east-1" = "use1"
"us-east-2" = "use2"
"us-west-1" = "usw1"
"us-west-2" = "usw2"
"af-south-1" = "afs1"
"ap-east-1" = "ape1"
"ap-northeast-1" = "apne1"
"ap-northeast-2" = "apne2"
"ap-northeast-3" = "apne3"
"ap-southeast-1" = "apse1"
"ap-southeast-2" = "apse2"
"ap-southeast-3" = "apse3"
"ap-south-1" = "aps1"
"ca-central-1" = "cac1"
"eu-central-1" = "euc1"
"eu-west-1" = "euw1"
"eu-west-2" = "euw2"
"eu-west-3" = "euw3"
"eu-north-1" = "eun1"
"eu-south-1" = "eus1"
"me-south-1" = "mes1"
"sa-east-1" = "sae1"
"cn-north-1" = "cn1"
"us-gov-west-1" = "usgw1"
"us-gov-east-1" = "usge1"
}
}
the output "code" then fails due to the current region not being included in the locals.
output "code" {
description = "The short code of the current region."
value = local.region_codes[data.aws_region.this.id]
}
Steps To Reproduce
Using terragrunt:
terraform {
source = "tfr:///tedilabs/account/aws//modules/region?version=0.30.4"
}
inputs = {
ebs_default_encryption = {
enabled = true
kms_key = ""
}
}
terragrunt run-all plan --terragrunt-non-interactive
data.aws_region.this: Reading...
data.aws_region.this: Read complete after 0s [id=ap-southeast-4]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
Terraform planned the following actions, but then encountered a problem:
aws_ebs_default_kms_key.this[0] will be created
- resource "aws_ebs_default_kms_key" "this" {
- id = (known after apply)
- key_arn = "arn:aws:kms:ap-southeast-4:000000000000:key/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
}
aws_ebs_encryption_by_default.this will be created
- resource "aws_ebs_encryption_by_default" "this" {
- enabled = true
- id = (known after apply)
}
aws_ec2_image_block_public_access.this will be created
- resource "aws_ec2_image_block_public_access" "this" {
- id = (known after apply)
- state = "block-new-sharing"
}
aws_ec2_instance_metadata_defaults.this[0] will be created
- resource "aws_ec2_instance_metadata_defaults" "this" {
- http_endpoint = "enabled"
- http_put_response_hop_limit = 1
- http_tokens = "required"
- id = (known after apply)
- instance_metadata_tags = "no-preference"
}
aws_ec2_serial_console_access.this will be created
- resource "aws_ec2_serial_console_access" "this" {
- enabled = false
- id = (known after apply)
}
aws_resourceexplorer2_index.this[0] will be created
- resource "aws_resourceexplorer2_index" "this" {
- arn = (known after apply)
- id = (known after apply)
- tags = {
- "Name" = "ap-southeast-4"
- "module.terraform.io/full-name" = "terraform-aws-account/."
- "module.terraform.io/instance" = "ap-southeast-4"
- "module.terraform.io/name" = "."
- "module.terraform.io/package" = "terraform-aws-account"
- "module.terraform.io/version" = "0.30.4"
}
- tags_all = {
- "Name" = "ap-southeast-4"
- "module.terraform.io/full-name" = "terraform-aws-account/."
- "module.terraform.io/instance" = "ap-southeast-4"
- "module.terraform.io/name" = "."
- "module.terraform.io/package" = "terraform-aws-account"
- "module.terraform.io/version" = "0.30.4"
}
- type = "LOCAL"
}
module.resource_group[0].aws_resourcegroups_group.this will be created
- resource "aws_resourcegroups_group" "this" {
-
arn = (known after apply)
-
description = "Managed by Terraform."
-
id = (known after apply)
-
name = "terraform-aws-account...ap-southeast-4"
-
tags = {
- "Name" = "terraform-aws-account...ap-southeast-4"
- "module.terraform.io/full-name" = "terraform-aws-account/."
- "module.terraform.io/instance" = "ap-southeast-4"
- "module.terraform.io/name" = "."
- "module.terraform.io/package" = "terraform-aws-account"
- "module.terraform.io/version" = "0.30.4"
}
-
tags_all = {
- "Name" = "terraform-aws-account...ap-southeast-4"
- "module.terraform.io/full-name" = "terraform-aws-account/."
- "module.terraform.io/instance" = "ap-southeast-4"
- "module.terraform.io/name" = "."
- "module.terraform.io/package" = "terraform-aws-account"
- "module.terraform.io/version" = "0.30.4"
}
-
resource_query {
- query = jsonencode(
{
+ ResourceTypeFilters = [
+ "AWS::AllSupported",
]
+ TagFilters = [
+ {
+ Key = "module.terraform.io/full-name"
+ Values = [
+ "terraform-aws-account/.",
]
},
+ {
+ Key = "module.terraform.io/instance"
+ Values = [
+ "ap-southeast-4",
]
},
+ {
+ Key = "module.terraform.io/name"
+ Values = [
+ ".",
]
},
+ {
+ Key = "module.terraform.io/package"
+ Values = [
+ "terraform-aws-account",
]
},
+ {
+ Key = "module.terraform.io/version"
+ Values = [
+ "0.30.4",
]
},
]
}
)
- type = "TAG_FILTERS_1_0"
}
}
Plan: 7 to add, 0 to change, 0 to destroy.
Changes to Outputs:
- cloudwdatch = {
- description = "Asia Pacific (Melbourne)"
- ebs = {
- default_encryption = {
- enabled = true
- kms_key = "arn:aws:kms:ap-southeast-4:000000000000:key/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
}
}
- ec2 = {
- ami_public_access_enabled = false
- instance_metadata_defaults = {
- http_enabled = true
- http_put_response_hop_limit = 1
- http_token_required = true
- instance_tags_enabled = null
}
- serial_console_enabled = false
}
- guardduty = {
- delegated_administrator = null
}
- id = "ap-southeast-4"
- inspector = {
- delegated_administrator = null
}
- macie = {
- delegated_administrator = null
}
- name = "ap-southeast-4"
- resource_explorer = {
- enabled = true
- index_arn = (known after apply)
- index_type = "LOCAL"
- views = {}
}
- service_quotas = {}
- vpc = {
- availability_zone_groups = {}
}
ERRO[0072] Module has finished with an error: 1 error occurred:
INFO[0072]
Error: Invalid index
on outputs.tf line 8, in output "code":
8: value = local.region_codes[data.aws_region.this.id]
โโโโโโโโโโโโโโโโโ
โ data.aws_region.this.id is "ap-southeast-4"
โ local.region_codes is object with 25 attributes
The given key does not identify an element in this collection value.
We have two deployment regions (ap-southeast-2 and ap-southeast-4). The ap-southeast-2 region deployments complete successfully.
Which version of the app are you using?
1.0.0