Ec2 instance creation using terraform assigns public IP

I am super new to terraform, I tried creating a ec2 instance, a elb and cname record using terraform. There is main.tf file with config supporting this and a separate variable file.

I haven't defined to create a public ip for ec2 instance anywhere in the config but it still creates one. Kindly advice how to prevent this.

Upvotes: 7

Views: 26954

Answers (1)

BMW
BMW

Reputation: 45223

There is an Boolean option to disable to assign public ip address with an instance.

https://www.terraform.io/docs/providers/aws/r/instance.html#associate_public_ip_address

associate_public_ip_address - (Optional) Associate a public ip address with an instance in a VPC. Boolean value.

So your code can be updated to

resource "aws_instance" "foo" {
  ...
  ecs_associate_public_ip_address = "false"
}

Upvotes: 10

Related Questions