Terraform config for a simple 2 instance EC2 setup in AWS for Linux Foundation Kubernetes for Developers (LFD259) course labs.
- AWS CLI Credentials File
- Terraform 11.13
- An AWS VPC set up in your AWS account
- A subnet set up on that VPC.
cp terraform.tfvars.example terraform.tfvars
- Edit
terraform.tfvars
and fill out the variables specific to your environment. They are as follows:ingress_cidr_blocks
- the ip blocks you would like the instances to be accessible from.egress_cidr_blocks
- the ip blocks you would like the instances to be able to access.public_key
- the ssh public key you would like to use for connecting to the instanceregion
- the AWS region you would like to create the instances insubnet_id
- A subnet that you have previously set up in your VPC that you want to connect the instances to.username
- a unique username to identify resources as having been set up by you. This is useful for accounts where multiple people will be using this config to set up test environments.vpc_id
- the id of a VPC you've set up beforehand to deploy the instances to
terraform init
to intialize the Terraform providerterraform plan
to see what will be createdterraform apply
, then typeyes
to send it on up!
You can store the Terraform state remotely in an S3 bucket if you wish,
but it is not necessary unless you expect you'll be collaborating with
others on the same state. Do do this, create a remote.tf
file in the
root of the repo. Be aware that this file is gitignored, so you can be
sure that your s3 bucket name and/or credentials you may decide to use
with it are not committed to repo.
terraform {
backend "s3" {
bucket = "terraform.mysite.private"
key = "k8s_practice_austin.tfstate"
region = "us-east-1"
encrypt = true
}
}