Rammina / terraform-aws-multi-repo-s3-remote-state

This is a module to be used for storing Terraform remote state.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Terraform Remote State example

This folder contains an example of a Terraform configuration that creates an S3 bucket that can be used for remote state storage.

Requirements

Using the code

  • Configure your AWS access keys.

  • Initialize working directory.

    The first command that should be run after writing a new Terraform configuration is the terraform init command in order to initialize a working directory containing Terraform configuration files. It is safe to run this command multiple times.

    terraform init
  • Modify configuration.

    You must modify the S3 bucket name, which is defined as an input variable bucket_name in vars.tf file.

    You can modify the S3 bucket name in several ways:

    • Loading variables from command line flags.

      Run Terraform commands in this way:

      terraform plan -var 'bucket_name=<YOUR_BUCKET_NAME>'
      terraform apply -var 'bucket_name=<YOUR_BUCKET_NAME>'
    • Loading variables from a file.

      When Terraform runs it will look for a file called terraform.tfvars. You can populate this file with variable values that will be loaded when Terraform runs. An example for the content of the terraform.tfvars file:

      bucket_name = "<YOUR_BUCKET_NAME>"
    • Loading variables from environment variables.

      Terraform will also parse any environment variables that are prefixed with TF_VAR. You can create an environment variable TF_VAR_bucket_name:

      TF_VAR_bucket_name=<YOUR_BUCKET_NAME>
    • Variable defaults.

      Change the value of the default attribute of bucket_name input variable in vars.tf file.

      variable "bucket_name" {
        description = "The name of the S3 bucket. Must be globally unique."
        default = "<YOUR_BUCKET_NAME>"
      }
  • Validate the changes.

    Run command:

    terraform plan
  • Deploy the changes.

    Run command:

    terraform apply
  • Clean up the resources created.

    When you have finished, run command:

    terraform destroy

About

This is a module to be used for storing Terraform remote state.


Languages

Language:HCL 100.0%