Skip to content

Instantly share code, notes, and snippets.

@sshastri
Created May 11, 2021 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sshastri/70fa2f46c4d8f36b4aba764762536371 to your computer and use it in GitHub Desktop.
Save sshastri/70fa2f46c4d8f36b4aba764762536371 to your computer and use it in GitHub Desktop.
terraform import example
  1. Setup a .tf file

# main.tf

provider "aws" {
    region = "us-east-1"
}

resource "aws_s3_bucket" "bucket" {}
  1. From command line run:

terraform import aws_s3_bucket.bucket hashi-implementation-svc-tools

  1. Run terraform show
# aws_s3_bucket.bucket:
resource "aws_s3_bucket" "bucket" {
    arn                         = "arn:aws:s3:::hashi-implementation-svc-tools"
    bucket                      = "hashi-implementation-svc-tools"
    bucket_domain_name          = "hashi-implementation-svc-tools.s3.amazonaws.com"
 ...
  1. Copy and paste the output from terraform show into the .tf file and run terraform plan
terraform plan

Error: Computed attributes cannot be set

  on test.tf line 9, in resource "aws_s3_bucket" "bucket":
   9:     bucket_domain_name          = "hashi-implementation-svc-tools.s3.amazonaws.com"

Computed attributes cannot be set, but a value was set for
"bucket_domain_name".


Error: Computed attributes cannot be set

  on test.tf line 10, in resource "aws_s3_bucket" "bucket":
  10:     bucket_regional_domain_name = "hashi-implementation-svc-tools.s3.amazonaws.com"

Computed attributes cannot be set, but a value was set for
"bucket_regional_domain_name".


Error: Invalid or unknown key

  on test.tf line 12, in resource "aws_s3_bucket" "bucket":
  12:     id                          = "hashi-implementation-svc-tools"
  1. Modify the terraform code until the plan passes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment