terraform-provider-aws: data source aws_ec2_transit_gateway_route_table doesn't feed data properly in plan phase to resource "aws_ec2_transit_gateway_route"
Community Note
- Please vote on this issue by adding a π reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave β+1β or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform Version
Terraform v0.12.19
- provider.aws v2.44.0
- provider.random v2.2.1
Affected Resource(s)
- aws_ec2_transit_gateway_route
- data source: aws_ec2_transit_gateway_route_table
Terraform Configuration Files
provider "random" {
}
resource "random_id" "id" {
byte_length = 4
}
locals {
id = random_id.id.hex
}
locals {
name = "tgw-test"
}
resource "aws_ec2_transit_gateway" "tgw-private" {
tags = {
Name = "${local.name}-private-${local.id}"
}
}
resource "aws_ec2_transit_gateway" "tgw-public" {
tags = {
Name = "${local.name}-public-${local.id}"
}
}
###############################################
# Maintain private Route Table of TGWA Routes #
###############################################
data "aws_ec2_transit_gateway_route_table" "tgwrtb" {
filter {
name = "transit-gateway-id"
values = [aws_ec2_transit_gateway.tgw-private.id]
}
}
resource "aws_ec2_transit_gateway_route" "add_private_route_1" {
destination_cidr_block = "192.168.1.0/27"
transit_gateway_attachment_id = "tgw-1111111111"
transit_gateway_route_table_id = data.aws_ec2_transit_gateway_route_table.tgwrtb.id
}
Debug Output
Panic Output
Expected Behavior
Terraform should start creating the resources and querying the data source once needed before creating the resource.
Actual Behavior
terraform analyzes the code and cannot resolve the data source properly so it fails.
$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
------------------------------------------------------------------------
Error: "transit_gateway_route_table_id": required field is not set
on main.tf line 38, in resource "aws_ec2_transit_gateway_route" "add_private_route_1":
38: resource "aws_ec2_transit_gateway_route" "add_private_route_1" {
Steps to Reproduce
terraform plan
Important Factoids
References
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 25 (23 by maintainers)
The fix for the noted data sources above has been merged and will release with version 3.21.0 of the Terraform AWS Provider, likely tomorrow. Thank you @apparentlymart and @tbugfinder. π
From some quick searching, some affected data sources:
Adding
Computed: trueto theseidattributes certainly seems like a good update for these. Then again, it would probably be best if the Terraform Plugin SDK either failed schema validation when this attribute behavior is missing or automatically added it, since theidattribute is implicitly required to have a value (https://github.com/hashicorp/terraform-plugin-sdk/issues/541). I will followup upstream there as well.The sample code fails already in planning stage. So this isnβt dependent on eventual consistency. It doesnβt honor input of
data.aws_ec2_transit_gateway_route_table.tgwrtb.id.