Difference between revisions of "Terraform S3 backend"

From wikieduonline
Jump to navigation Jump to search
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Terraform]] [[S3]] backend.  
+
[[Terraform]] [[S3]] [[backend]].  
 
* https://www.terraform.io/docs/language/settings/backends/s3.html
 
* https://www.terraform.io/docs/language/settings/backends/s3.html
  
== Basic S3 example in [[backend.tf]] ==
+
== Basic S3 examples in [[backend.tf]] ==
 
  terraform {
 
  terraform {
 
   backend "s3" {
 
   backend "s3" {
 
     [[bucket]] = "[[aws s3 ls|your-terraform-states]]"
 
     [[bucket]] = "[[aws s3 ls|your-terraform-states]]"
 
     [[Terraform S3 backend|key]]<ref>https://www.terraform.io/docs/language/settings/backends/s3.html#key</ref>    = "[[terraform.tfstate]]"
 
     [[Terraform S3 backend|key]]<ref>https://www.terraform.io/docs/language/settings/backends/s3.html#key</ref>    = "[[terraform.tfstate]]"
     [[profile]] = "your-profile"
+
     [[Terraform S3 backend: profile|profile]] = "your-profile"
 
   }
 
   }
 
  }
 
  }
Line 20: Line 20:
 
  }
 
  }
  
== Example including [[DynamoDB]] table ==
+
 
 +
#This simple example will prompt you for bucket name once you executed [[terraform init]]
 
  terraform {
 
  terraform {
 
   backend "s3" {
 
   backend "s3" {
    [[bucket]] = "your-terraform-states"
 
    [[key]]<ref>https://www.terraform.io/docs/language/settings/backends/s3.html#key</ref>    = "[[terraform.tfstate]]"
 
    region = "[[us-west-2]]"
 
    [[dynamodb_table]] = "your-terraform-states"
 
    [[profile]] = "your-profile"
 
    [[workspace_key_prefix]] = "your-workspace"
 
 
   }
 
   }
 
  }
 
  }
 +
 +
== Example including [[DynamoDB]] table ==
 +
 +
{{tf dynamo s3 ex}}
 +
  
 
* <code>[[profile]]</code>: https://www.terraform.io/docs/language/settings/backends/s3.html#profile
 
* <code>[[profile]]</code>: https://www.terraform.io/docs/language/settings/backends/s3.html#profile
Line 40: Line 40:
  
 
== S3 backend errors ==
 
== S3 backend errors ==
* [[Error: Backend configuration changed]]
+
* <code>[[Error: Backend configuration changed]]</code>
* [[Error: Failed to get existing workspaces: S3 bucket does not exist.]]: <code>[[aws s3 mb]]</code>
+
* <code>[[Error: Failed to get existing workspaces: S3 bucket does not exist.]]</code>: <code>[[aws s3 mb]]</code>
 +
* <code>[[Error: no valid credential sources for S3 Backend found]]</code>
 +
 
 +
== Changelog ==
 +
* [[Terraform versions|1.6.0]] (Oct 2023) https://github.com/hashicorp/terraform/blob/v1.6/CHANGELOG.md#160-october-4-2023
  
 
== Related terms ==
 
== Related terms ==
Line 51: Line 55:
 
* <code>[[aws s3 ls]]</code>
 
* <code>[[aws s3 ls]]</code>
 
* <code>[[provider.tf]]</code>
 
* <code>[[provider.tf]]</code>
 +
* [[Terraform backend: gcs]]
  
 
== See also ==
 
== See also ==

Latest revision as of 11:07, 29 August 2024

Terraform S3 backend.

Basic S3 examples in backend.tf[edit]

terraform {
  backend "s3" {
    bucket = "your-terraform-states"
    key[1]    = "terraform.tfstate"
    profile = "your-profile"
  }
}

https://www.terraform.io/docs/language/settings/backends/s3.html#example-configuration

terraform {
  backend "s3" {
    bucket = "mybucket"
    key    = "path/to/my/key"
    region = "us-east-1"
  }
}


#This simple example will prompt you for bucket name once you executed terraform init
terraform {
  backend "s3" {
  }
}

Example including DynamoDB table[edit]

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


Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.
Error refreshing state: AccessDenied: Access Denied status code: 403, request id: JDK297FD1E5GY3TT, host id: JJJ1ThvIKmNSYOO3h2IZFECn9l8DnsofwXWk4F6a9/nzrqgNNbOzyw9d2PcAXSb4DDYwkr/VNWZ0

S3 backend errors[edit]

Changelog[edit]

Related terms[edit]

See also[edit]

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