Lab Activity
Lab Activity
13. For the second exercise, you need to add a backend block in the existing configuration file
14. Edit the file using nano main.tf command.
13. Go to the properties tab of the bucket, scroll down and check the versioning feature, it is in
disable mode now.
14. Go to the Terraform configuration file and edit it. Add the following data (versioning part only)
provider "aws" {
access_key = "AKIAWLISMY5ORMPD6FGP"
secret_key = "6gw3zGb7IIGmtRM7cTDFVmVkgwtIrQTOJevE97W/"
region = "us-west-2"
}
resource "aws_s3_bucket" "example" {
bucket = "testing-env-2023"
versioning {
enabled = true
}
}
15. Run the terraform plan and terraform apply commands one after another.
16. After Terraform apply command, Check the properties tab of S3 bucket in the AWS
console you can see the versioning is enable now.
17. Do not forget to run the terraform destroy command.
Lab Activity 3:
1. Create a directory using mkdir ec2_inst command.
2. Create 3 files in it main.tf, variable.tf and output.tf
3. Contents of main.tf
ami = var.ami_id
instance_type = var.instance_type
subnet_id = var.subnet_id
# Add any other resources required for your use case (e.g., security groups, key pairs, etc.)
4. Contents of variables.tf
variable "ami_id" {
variable "instance_type" {
variable "subnet_id" {
5. Contents of outputs.tf
output "ec2_instance_id" {
value = aws_instance.ec2_instance.id
provider "aws" {
access_key = "AKIAWLISMY5OXIWKTXQ6"
secret_key = "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"
region = "us-west-2"
module "my_ec2_instance" {
ami_id = "ami-04e914639d0cca79a"
instance_type = "t2.micro"
# key_name = "my-key-pair"
subnet_id = "subnet-0045214a773d5e406"
provider "aws" {
access_key = "AKIAWLISMY5ORMPD6FGP"
secret_key = "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"
# Create VPC
tags = {
Name = "MyVPC"
vpc_id = aws_vpc.my_vpc.id
tags = {
Name = "MyIGW"
tags = {
Name = "PublicSubnet"
vpc_id = aws_vpc.my_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.my_igw.id
tags = {
Name = "PublicRouteTable"
subnet_id = aws_subnet.public_subnet.id
route_table_id = aws_route_table.public_route_table.id
}
# Output the VPC ID and Subnet ID
output "vpc_id" {
value = aws_vpc.my_vpc.id
output "public_subnet_id" {
value = aws_subnet.public_subnet.id
Final Output:
VPC Dashboard:
4. Now, if the administrator does not want to delete VPC, but want to delete other components
like IGW, subnet, route table etc. let’s see how to do it.
5. Run terraform state list command
6. Copy the my_vpc resource name from the list and run terraform state rm
aws_vpc.my_vpc command
7. Run the terraform destroy command. Review the plan before answering Yes.
8. The plan will show the deletion of other components:
Terraform Workspace:
2. Provide your details and click on create account. Server will send you a verification link on the
email you have provided. Click on it to verify your mail ID.
3. When you click the link to confirm your email address, the Terraform Cloud UI will ask which
setup workflow you would like use. Select Start from scratch.
4. Create an Organization: Creating organizations of up to 5 users is free. Provide the name and
email address then click on Create organization button.
5. Create a new workspace. Select CLI-driven workflow. provide a name for the workspace and
click on create workspace.
6. Your workspace on Terraform cloud is been created. You can use example code in your code file
to use this workspace.