Terraform v0.11.8
+ provider.aws v1.34.0
I want to create a peering connection and I would like to avoid hard coding the VPC IDs or using variables.
I don't use data "aws_vpcs" instead I just put the value directly.
Allow the following configuration block
# my region for development is "us-west-1"
# but I want to get the production VPC_ID for peer connections so I need something like this
# to avoid hard coding the VPC
data "aws_vpcs" "production_vpcs" {
region = "ca-central-1" # <-- this is what I am looking for
tags {
service = "production"
}
}
resource "aws_vpc_peering_connection" "dev-to-prod" {
peer_vpc_id = "${aws_vpcs.production_vpcs[0].id}"
region = "${aws_vpcs.production_vpcs[0].region}"
vpc_id = "${aws_vpc.dev.id}"
}
Hi @trajano -
Can you please update this issue with more information? It is not clear to me if you are reporting a feature request or bug, or asking a question.
Please note that we use GitHub issues for tracking bugs and enhancements rather than for questions. While we may be able to help with certain simple problems here it's generally better to use one of the community forums where there are far more people ready to help, whereas the GitHub issues here are generally monitored only by our few core maintainers.
Here is the documentation for the aws vpc data source. If you are trying to use this data source and getting an error or crash, please update this issue with more information, including your terraform configuration files and the output of the terraform commands.
Thanks!
hi @trajano
It's possible to have multiple versions of a Terraform Provider by defining the Provider block multiple times (documentation) - for example:
provider "aws" {
alias = "prod"
region = "ca-central-1"
}
provider "aws" {
alias = "dev"
region = "us-west-1"
}
Once multiple Provider blocks exist (and have unique aliases) - it's then possible to use the aliased Providers from within Data Sources and Resources to look things up dynamically, for example:
# .. assuming the provider blocks from above exist
data "aws_vpcs" "production_vpcs" {
provider = "aws.prod"
tags {
service = "production"
}
}
data "aws_vpcs" "dev" {
provider = "aws.dev"
tags {
service = "dev"
}
}
resource "aws_vpc_peering_connection" "dev-to-prod" {
peer_vpc_id = "${data.aws_vpcs.production_vpcs[0].id}"
region = "${data.aws_vpcs.production_vpcs[0].region}"
vpc_id = "${aws_vpc.dev.id}"
provider = "aws.dev"
}
Would you be able to take a look and see if that's what you're looking for?
Thanks!
Most helpful comment
hi @trajano
It's possible to have multiple versions of a Terraform Provider by defining the Provider block multiple times (documentation) - for example:
Once multiple Provider blocks exist (and have unique aliases) - it's then possible to use the aliased Providers from within Data Sources and Resources to look things up dynamically, for example:
Would you be able to take a look and see if that's what you're looking for?
Thanks!