Difference between revisions of "Backend.tf"

From wikieduonline
Jump to navigation Jump to search
Line 20: Line 20:
 
== [[Terraform S3 backend|S3]] Example with [[DynamoDB]] ==
 
== [[Terraform S3 backend|S3]] Example with [[DynamoDB]] ==
 
  terraform {
 
  terraform {
   backend "s3" {
+
   [[backend]] "s3" {
 
     [[bucket]] = "your-terraform-states"
 
     [[bucket]] = "your-terraform-states"
 
     [[key]]<ref>https://www.terraform.io/docs/language/settings/backends/s3.html#key</ref>    = "[[terraform.tfstate]]"
 
     [[key]]<ref>https://www.terraform.io/docs/language/settings/backends/s3.html#key</ref>    = "[[terraform.tfstate]]"
Line 41: Line 41:
 
   }
 
   }
 
  }
 
  }
 
 
 
 
  
 
== See also ==
 
== See also ==

Revision as of 07:23, 20 September 2022

Terraform Cloud

 terraform {
  backend "remote" {
    organization = "{{ORGANIZATION_NAME}}"

    workspaces {
      name = "{{WORKSPACE_NAME}}"
    }
  }

  required_version = ">= 0.14.0"
 }

S3 Example with DynamoDB

terraform {
  backend "s3" {
    bucket = "your-terraform-states"
    key[1]    = "terraform.tfstate"
    region = "us-west-2"
    dynamodb_table = "your-terraform-states"
    profile = "your-profile"
    workspace_key_prefix = "your-workspace"
  }
}

Example using variables:

terraform {
  backend "s3" {
    bucket         =  "$(aws-backend-bucket)"
    key            =  "yourkeyname/$(AWS_ACCOUNTNAME)/$(AWS_MYREGION)"
    region         =  "$(AWS_MYREGION)"
    dynamodb_table =  "$(aws-backend-dynamoDbTable)"
    encrypt        =  true
    role_arn       =  "$(aws-cicd-role-arn)"
  }
}

See also

  • https://www.terraform.io/docs/language/settings/backends/s3.html#key
  • Advertising: