- To get started you should first create an account with Amazon Web Services if you haven't got one already. You can do it here.
- The Terraform CLI (1.2.0+) installed.
- The AWS CLI installed.
- Terraform Basics
- Configure a AWS CLI and recommend using named configured profile
When using Terraform it needs to keep track of the infrastructure it's creating. It does this by means of a statefile. This file is just a simple JSON file (though its extension is terraform.tfstate) that defines the infrastructure that has been created by Terraform and any proposed changes. By default, this file is stored on the local machine where terraform commands are run and should be checked into git or any other source code management system used. More of the purpose of the state file can be explained here. Terraform compares your configuration with the state file and your existing infrastructure to create plans and make changes to your infrastructure. When you run terraform apply or terraform destroy against your initialized configuration, Terraform writes metadata about your configuration to the state file and updates your infrastructure resources accordingly.
If the state file is deleted terraform will lose track of the infrastructure it has created, so it is important to keep state file in safe place where it wont be deleted, like Terraform backends. Also since it is just a simple file, it can actually be edited by anyone that has access to it and this might cause unwanted behaviors in the state of your infrastructure. This is not ideal for collaboration as git conflicts may arise if multiple developers are modifying their own local copy of the file. Terraform introduce multiple online storage locations for this file called backends, and AWS S3 can be used as a backend to safely store your state file.
The state file can handle sensitive data, if creating IAM_USER with access and secret key this will be stored in plain text in the state file. So recommend keeping state file secure.
Updated 3 months ago