How provisioning of resource works internally
Devops engineer writes terraform script and it calls the resource provider and upon calling the corresponding resource will be created/modified/removed accordingly.
Prerequisites for running terraform script
- AWS Account
- Aws CLI installed
- Connect to AWS using aws configure command
Syntax for terraform code for provisioning S3 bucket
For a resource to be provisioned, syntax is:
resource "resource_type" "variable_name"{
bucket = "unique_bucket_name"
tags = {
Name = "My bucket"
Environment = "Dev"
}
}
Steps to run the terraform script for S3 bucket creation
- tf init
- tf plan --> shows the blueprint/summary about the resources that are going to be created/modified/deleted
- tf validate --> this validates the script
- tf apply --auto-approve --> this doesn't wait for the consent in the CLI
After running this commands the S3 bucket will be created in the AWS
To delete the S3 bucket run the command
- tf destroy --auto-approve --> this destroys the resources
After running this command the S3 bucket will be deleted in the AWS
This is how we will automate the creation and deletion of S3 bucket in AWS
Resources
Video : https://www.youtube.com/watch?v=09HQ_R1P7Lw
Top comments (0)