I'm trying to provision an EC2 instance in an existing and specific VPC by providing an AWS region to Terraform.
I want to be able to automatically choose a specific vpc using regex or some other method, this is my tf file.
can anybody help me?
the VPC I want to be chosen automatically has a prefix "digital".
so instead of providing its name in here -> name = "tag:${local.env_profile}-vpc"
I want to provide only the region and then to get this specific VPC using regex.
provider "aws" {
region = "eu-west-3"
shared_credentials_file = "${var.shared_credentials_file}"
profile = "${var.profile}"
}
data "aws_vpc" "selected" {
filter {
name = "tag:${local.env_profile}-vpc"
values = ["${local.env_profile}-vpc"]
}
}
resource "aws_instance" "general" {
ami = "ami-00035f41c82244dab"
instance_type = "${var.type}"
vpc = "${data.aws_vpc.selected.id}"
key_name = "${var.key_name}"
tags {
Name = "empty"
}
}
aws ec2 describe-vpcs
or if you created them via Terraform the code used to create them (in a separate code block). – ydaetskcoR