Day-12-Terraform-AWS

Mokadi Surya Prasad
3 min readOct 19, 2024

--

WorkSpace-S3 Versioning-Conflicts

WorkSpace: Suppose we are working with Terraform and need to provision infrastructure in three different environments. Using the workspace concept is crucial because, without it, managing and provisioning separate environments would be challenging.

We can perform a lab on Terraform workspaces to develop a better understanding of how they work.

After applying the terraform apply -var-file=./dev.tfvars command, the resources for the development environment were created. However, when we applied terraform apply -var-file=./uat.tfvars, the previously created development infrastructure was destroyed, and the UAT infrastructure started to be created.

Now, we can create dev, uat, and prod infrastructure using the workspace concept in Terraform.

Now, we can select the dev workspace to provision the infrastructure.

Now, we can select the uat workspace to provision the infrastructure.

Now we can destroy the infrastructure. We need to choose the correct workspace first. This way, we only remove the right environment and do not affect the others.

Now we can delete the three workspaces by switching to the default workspace first.

S3 Versioning:

Suppose we are creating the Terraform dev infrastructure and storing it in an S3 backend with versioning enabled. Unexpectedly, the bucket was deleted from the CLI. Now, as we are ready to create the infrastructure with additional services, the state file is not capturing the previous state. We can simply go to the AWS console, where we see a file named ‘statefile delete marker.’ By deleting this marker, the original state file will be restored to its main position.

Conflicts:

We need to create a DynamoDB table first before using this setup. For example, if one engineer is creating infrastructure from their local computer and another is doing it from an EC2 server, the second engineer won’t be able to proceed if the first one is already working. This happens because the state file is locked in the DynamoDB table, which stops both from making changes at the same time.

--

--

Mokadi Surya Prasad
Mokadi Surya Prasad

No responses yet