shamon shamsudeen
shamon shamsudeen

Reputation: 5858

Terraform : Import existing internet gateway and attach to vpc

In terraform, we have an option to import the existing resources and we can manage through terraform.

I already have an IG in my region and I want to attach this to newly created VPC, what I have tried is

  1. Imported the IG using terraform import aws_internet_gateway.my_gw igw-c0a643a9

2.In my configuration

resource "aws_internet_gateway" "my_gw" {
   vpc_id = module.vpc_dev.vpc_id
}

But this still try to create the new internet gateway so my question how to attach the existing IG into the newly created VPC

Upvotes: 1

Views: 1035

Answers (1)

user1297406
user1297406

Reputation: 1341

You can also simply use a data source to use the Internet Gateway :

data "aws_internet_gateway" "default" {
  internet_gateway_id = <the-id-of-your-internetgateway>
}

Upvotes: 1

Related Questions