Skip to content

Instantly share code, notes, and snippets.

@cornet
Last active July 1, 2016 08:10
Show Gist options
  • Save cornet/d51adfd0ec503a48e8e8 to your computer and use it in GitHub Desktop.
Save cornet/d51adfd0ec503a48e8e8 to your computer and use it in GitHub Desktop.
So what happens if you nuke your terraform state or have buckets that you want to manage using terraform ?
#
# Bucket doesn't exist yet, run terraform plan
#
$ terraform plan
Refreshing Terraform state prior to plan...
The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed.
Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.
+ aws_s3_bucket.my-terraform-test-bucket
acl: "" => "public-read"
bucket: "" => "my-terraform-test-bucket"
force_destroy: "" => "0"
hosted_zone_id: "" => "<computed>"
region: "" => "<computed>"
website_domain: "" => "<computed>"
website_endpoint: "" => "<computed>"
Plan: 1 to add, 0 to change, 0 to destroy.
#
# Looks good, lets apply
#
$ terraform apply
aws_s3_bucket.my-terraform-test-bucket: Creating...
acl: "" => "public-read"
bucket: "" => "my-terraform-test-bucket"
force_destroy: "" => "0"
hosted_zone_id: "" => "<computed>"
region: "" => "<computed>"
website_domain: "" => "<computed>"
website_endpoint: "" => "<computed>"
aws_s3_bucket.my-terraform-test-bucket: Creation complete
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.
State path: terraform.tfstate
#
# If we plan again it says nothing todo, as expected.
#
$ terraform plan
Refreshing Terraform state prior to plan...
aws_s3_bucket.my-terraform-test-bucket: Refreshing state... (ID: my-terraform-test-bucket)
No changes. Infrastructure is up-to-date. This means that Terraform
could not detect any differences between your configuration and
the real physical resources that exist. As a result, Terraform
doesn't need to do anything.
#
# As a test to see what happens, lets nuke the state files
#
$ rm terraform.tfstate*
rm: remove regular file ‘terraform.tfstate’? y
rm: remove regular file ‘terraform.tfstate.backup’? y
#
# Terraform plan seems to think it wants to create it again..
#
$ terraform plan
Refreshing Terraform state prior to plan...
The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed.
Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.
+ aws_s3_bucket.my-terraform-test-bucket
acl: "" => "public-read"
bucket: "" => "my-terraform-test-bucket"
force_destroy: "" => "0"
hosted_zone_id: "" => "<computed>"
region: "" => "<computed>"
website_domain: "" => "<computed>"
website_endpoint: "" => "<computed>"
Plan: 1 to add, 0 to change, 0 to destroy.
#
# Blindly continuing lets apply anyway...
#
$ terraform apply
aws_s3_bucket.my-terraform-test-bucket: Creating...
acl: "" => "public-read"
bucket: "" => "my-terraform-test-bucket"
force_destroy: "" => "0"
hosted_zone_id: "" => "<computed>"
region: "" => "<computed>"
website_domain: "" => "<computed>"
website_endpoint: "" => "<computed>"
Error applying plan:
1 error(s) occurred:
* aws_s3_bucket.my-terraform-test-bucket: Error creating S3 bucket: BucketAlreadyOwnedByYou: Your previous request to create the named bucket succeeded and you already own it.
status code: 409, request id:
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
provider "aws" {
region = "eu-west-1"
alias = "eu-west-1"
access_key = "xxxxxxxxxxx"
secret_key = "xxxxxxxxxxx"
}
resource "aws_s3_bucket" "my-terraform-test-bucket" {
provider = "aws.eu-west-1"
bucket = "my-terraform-test-bucket"
acl = "public-read"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment