Creating EC2 instance with Terraform
Resources are components of your infrastructure. It can be something as complex as a complete virtual server, or something as simple as a DNS record. Each resource belongs to a provider, and the type of the resource is suffixed with the provider name. The configuration of a resource takes the following form:
resource "provider-name_resource-type" "resource-name" { parameter_name = parameter_value }
The combination of resource type and resource name must be unique in your template; otherwise Terraform will complain.
There are three types of things you can configure inside resource block: resource-specific parameters, meta-parameters, and provisioners. For now, let's focus on resource-specific parameters. They are unique to each resource type.
We will create an EC2 instance. The aws_instance
resource is responsible for this job. To create an instance, we need to set at least two parameters: ami
and instance_type
. Some parameters are required...