Create an EC2 Instance with Terraform: Difference between revisions
Jump to navigation
Jump to search
Line 15: | Line 15: | ||
profile = "default" | profile = "default" | ||
region = "us-west-2" | region = "us-west-2" | ||
} | } | ||
resource "aws_instance" "terraform- | resource "aws_instance" "terraform-experiment-01" { | ||
ami | ami = "ami-000000000000000" | ||
instance_type = " | instance_type = "t2.small" | ||
} | subnet_id = "subnet-0000000000000000" | ||
</syntaxhighlight> | key_name = "sbox-ml-kp-01" | ||
security_groups = ["sg-0000000000000000"] | |||
associate_public_ip_address = false | |||
tags = { | |||
Name = "terraform-experiment-01" | |||
} | |||
}</syntaxhighlight> | |||
=Configuration Details= | =Configuration Details= |
Revision as of 22:27, 13 November 2019
External
Internal
Overview
EC2 instances can be created, updated and deleted. Instances also support provisioning.
Configuration
provider "aws" {
profile = "default"
region = "us-west-2"
}
resource "aws_instance" "terraform-experiment-01" {
ami = "ami-000000000000000"
instance_type = "t2.small"
subnet_id = "subnet-0000000000000000"
key_name = "sbox-ml-kp-01"
security_groups = ["sg-0000000000000000"]
associate_public_ip_address = false
tags = {
Name = "terraform-experiment-01"
}
}
Configuration Details
Public IP
If nothing is specified, the instance will get a public IP. To disable allocation of a public address specify:
resource "aws_instance" ... {
...
associate_public_ip_address = false
...
}
Note that even if associate_public_ip_address
is explicitly set to "true", if the associated subnet has a map_public_ip_on_launch
= true, a public IP will be associated anyway.