Repository for terraform workshop given by Anuj Jain @ajain-ee.
- Run terraform version on the command line and verify it is 0.12.16.
- Get your AWS account access key and access secret ready.
- Fork repository https://github.com/ajain-ee/101-terraform-workshop.git .
- Checkout branch “step-1”.
- Replace aws key and aws secret variable
- Run terraform init
- Run terraform plan
- Commit your changes on branch step-1.
- Merge step-1 branch into master
-
Checkout branch "step-2" and rebase with master.
-
Extract hardcode access_key into variables like this:
variable "aws_access_key" { default = "" } access_key = var.aws_access_key
-
Replace all other hardcoded values as well with variables.
-
Set ami value to appropriate ami available in choice of region. I am setting public ubuntu available in eu-east-1 "ami-04b9e92b5572fa0d1"
-
Set keyname and public_key value is your any open-ssh formatted public key. Using this key you can ssh into ec2 box.
-
Set subnet id from default vpc in your aws region.
-
Run terraform plan
-
Run terraform apply
-
Verify ec2 instance by doing ssh into ec2-instance using command.
ssh -i <path-to-private-key> ubuntu@public-ip-address-of-ec2-instance
-
Commit and Merge step-2 branch into master.
-
Checkout branch "step-3" and rebase with master.
-
Create a bucket "terraform-workshop" in you account.
-
Set the following variables in terraform backend configuration
backend "s3" { bucket = "terraform-workshop" region = "" key = "workshopstate/terraform.tfstate" }
-
Run terraform init, terraform will prompt your for state migration from local to remote location. press yes for migration.
-
Run terraform plan
-
Run terraform apply
-
Commit and Merge step-3 branch into master.
- Checkout branch "step-4" and rebase with master.
- Run terraform destroy and approve the destruction and start fresh.
- update the key value pairs with your openssh public key, this will be used to ssh into ec2 instance launch in public subnet.
- Run terraform plan
- Run terraform apply
- Go to AWS Console and verify your vpc and subnets are created.
- Go EC2 service and verify 2 instance are running.
- SSH into public ec2 instance with ssh key.
- Commit and Merge step-4 branch into master.
- Checkout branch "step-5" and rebase with master.
- Check the install-apache.tpl and see it usage in ec2 instance first instance user data.
- Run terraform plan
- Run terraform apply
- Get the public ip and terrform output and open ip in browser. You should greeting message from install apache file in browser.
- Commit and Merge step-5 branch into master.