title: provision EC2 in an existing VPC by providing an AWS Region using Terraform
body: <p>I'm trying to provision an EC2 instance in an existing and specific VPC by providing an AWS region to Terraform.</p>
  
  <p>I want to be able to automatically choose a specific vpc using regex or some other method, this is my tf file.</p>
  
  <p>can anybody help me?</p>
  
  <p>the VPC I want to be chosen automatically has a prefix "digital".
  so instead of providing its name in here ->  <code>name = "tag:${local.env_profile}-vpc"</code></p>
  
  <p>I want to provide only the region and then to get this specific VPC using regex.</p>
  
  <pre><code>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"
    }
  }
  </code></pre>