Summary: Create a Cloud Formation template that provisions a VPC with its necessary components and an EC2 instance within the VPC.
Point to note: I used Terraform instead of AWS cloud formation as my infrastructure as code tool for provisioning the networking and security for instance.
- AWS Account with IAM user credentials (Access and Secret Key)
- Terraform setup
- AWS CLI
-
To make terraform accessible for your terraform provisioning you set up your credentials using either aws configure or environment variable $ export SECRET_ACCESS_KEY and $export AWS ACCESS_KEY
-
Once you have terraform.tf files for your VPC and ec2 instance. You first this command to initialize.
terraform init
- Terraform plan: Is used to create execution changes, in simple it shows the desired resources that will be provisioned.
- Terraform apply: This command reads the configuration files and creates the necessary resources
terraform plan terraform plan -var-file=tfvars/dev.tfvars && terraform apply -var-file=tfvars/dev.tfvars
The tfvars file is used to define environment variables, which makes it easy to provide different values depending on environment, configuration and deployment