hcl Flashcards
terraform
required_providers {
aws = {
source =
“hashicorp/aws”
version = “~> 3.0”
}
}
provider
region = “us-west-2”
aws_vpc
cidr_block = var.vpc_cidr
aws_subnet
vpc_id = aws_vpc.main.id
availability_zone = var.az
map_public_ip_on_launch = true
cidr_block = var.subnet_cidr
tags = {
Name = “${var.env}-subnet” }
aws_internet_gateway
vpc_id = aws_vpc.main.id
aws_default_route_table
default_route_table_id = aws_vpc.main.default_route_table_id
route {
cidr_block = “0.0.0.0/0”
gateway_id =
aws_internet_gateway.main_gw.id
}
tags = {
Name = “${var.env}-default-rt”
}
aws_default_security_group
vpc_id = aws_vpc.main.id
egress {
from_port = 0
to_port = 0
protocol = “-1”
cidr_blocks = [“0.0.0.0/0”]
}
ingress {
from_port = 0
to_port = 0
protocol = “-1”
cidr_blocks = [“0.0.0.0/0”]
}
aws_key_pair
key_name = “my_key”
public_key = file(var.public_key)
data “aws_ami”
most_recent = true
owners = [“amazon”]
filter {
name = “name”
values = [var.ami_image]
}
var.ami_image
amzn2-ami-kernel-*-x86_64-gp2
aws_instance
ami = data.aws_ami.ubuntu_ami.id
instance_type = “t2.micro”
key_name = aws_key_pair.my_key_pair.key_name
vpc_security_group_ids = [aws_default_security_group.my_security_group.id]
subnet_id = aws_subnet.my_subnet.id
associate_public_ip_address = true
tags = {
Name = “my_instance”
}