From 98492c3f87fa8a54f224ac8103112100102ed393 Mon Sep 17 00:00:00 2001 From: trujillo-adam Date: Mon, 8 Sep 2025 11:26:26 -0700 Subject: [PATCH 1/3] add details about identity arg in import ref --- .../v1.12.x/docs/language/block/import.mdx | 45 +++++++++++++----- .../v1.13.x/docs/language/block/import.mdx | 47 ++++++++++++++----- 2 files changed, 67 insertions(+), 25 deletions(-) diff --git a/content/terraform/v1.12.x/docs/language/block/import.mdx b/content/terraform/v1.12.x/docs/language/block/import.mdx index e7e1706a6b..cb3a28fd60 100644 --- a/content/terraform/v1.12.x/docs/language/block/import.mdx +++ b/content/terraform/v1.12.x/docs/language/block/import.mdx @@ -14,8 +14,8 @@ An `import` block supports the following configuration: - [`import`](#import)   block - [`to`](#to)   address | required - - [`id`](#id)   string - + - [`id`](#id)   string + - [`identity`](#identity)   map | mutually exclusive with `id` - [`for_each`](#for_each)   map or set of strings - [`provider`](#provider)   reference @@ -95,9 +95,7 @@ You must specify a string or an expression that evaluates to a string. The ID mu The value of the `id` argument depends on the type of resource you are importing. You can only import resources that are supported by the provider. For information on how to import a resource, refer to the provider documentation. - #### Summary @@ -105,10 +103,10 @@ You cannot use the `id` argument and [`identity` argument](#identity) in the sam - Default: None - Example: [Import a single resource](#import-a-single-resource) - ### `for_each` @@ -204,8 +199,13 @@ The following examples show how to write configuration for common use cases. ### Import a single resource -In the following example, Terraform imports `example-bucket` into a resource at `aws_s3_bucket.this`: +You can import an individual resource by specifying its ID in `id` argument or by specifying the set of identifying attributes in the `identity` argument. + + + + +In the following example, Terraform imports `example-bucket` into a resource at `aws_s3_bucket.this`: ```hcl import { @@ -214,13 +214,34 @@ import { } resource "aws_s3_bucket" "this" { -} # … } ``` Refer to the [AWS provider documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#import) in the Terraform registry for more information about importing AWS instances. + + + + +In the following example, Terraform imports an S3 bucket using its `account_id`, `bucket`, and `region` attributes: + +```hcl +import { + to = aws_s3_bucket.bucket + identity = { + account_id = "622801496880" + bucket = "hjarui4t89efuh" + region = "us-east-1" + } +} +``` + + + + + + ### Import multiple resources In the following example, the `for_each` argument loops through the key-value pairs defined in the `buckets` map. For each pair, Terraform imports the S3 bucket into the `aws_s3_bucket.this` resource. The `[each.key]` index maps to the keys in `locals` block, such as `aws_s3_bucket.this["staging"]`. diff --git a/content/terraform/v1.13.x/docs/language/block/import.mdx b/content/terraform/v1.13.x/docs/language/block/import.mdx index e7e1706a6b..2ad3d7c9d5 100644 --- a/content/terraform/v1.13.x/docs/language/block/import.mdx +++ b/content/terraform/v1.13.x/docs/language/block/import.mdx @@ -14,8 +14,8 @@ An `import` block supports the following configuration: - [`import`](#import)   block - [`to`](#to)   address | required - - [`id`](#id)   string - + - [`id`](#id)   string + - [`identity`](#identity)   map | mutually exclusive with `id` - [`for_each`](#for_each)   map or set of strings - [`provider`](#provider)   reference @@ -95,9 +95,7 @@ You must specify a string or an expression that evaluates to a string. The ID mu The value of the `id` argument depends on the type of resource you are importing. You can only import resources that are supported by the provider. For information on how to import a resource, refer to the provider documentation. - #### Summary @@ -105,10 +103,10 @@ You cannot use the `id` argument and [`identity` argument](#identity) in the sam - Default: None - Example: [Import a single resource](#import-a-single-resource) - ### `for_each` @@ -204,8 +199,13 @@ The following examples show how to write configuration for common use cases. ### Import a single resource -In the following example, Terraform imports `example-bucket` into a resource at `aws_s3_bucket.this`: +You can import an individual resource by specifying its ID in `id` argument or by specifying the set of identifying attributes in the `identity` argument. + + + + +In the following example, Terraform imports `example-bucket` into a resource at `aws_s3_bucket.this`: ```hcl import { @@ -214,13 +214,34 @@ import { } resource "aws_s3_bucket" "this" { -} # … } ``` Refer to the [AWS provider documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#import) in the Terraform registry for more information about importing AWS instances. + + + + +In the following example, Terraform imports an S3 bucket using its `account_id`, `bucket`, and `region` attributes: + +```hcl +import { + to = aws_s3_bucket.bucket + identity = { + account_id = "622801496880" + bucket = "hjarui4t89efuh" + region = "us-east-1" + } +} +``` + + + + + + ### Import multiple resources In the following example, the `for_each` argument loops through the key-value pairs defined in the `buckets` map. For each pair, Terraform imports the S3 bucket into the `aws_s3_bucket.this` resource. The `[each.key]` index maps to the keys in `locals` block, such as `aws_s3_bucket.this["staging"]`. @@ -302,4 +323,4 @@ import { resource "aws_instance" "web" { # ... -} +} \ No newline at end of file From d458f10b8221d2b42d00ccd9185deb3e472832b6 Mon Sep 17 00:00:00 2001 From: trujillo-adam Date: Mon, 8 Sep 2025 12:56:42 -0700 Subject: [PATCH 2/3] update 'Complete configuration' section --- content/terraform/v1.12.x/docs/language/block/import.mdx | 9 ++++++--- content/terraform/v1.13.x/docs/language/block/import.mdx | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/content/terraform/v1.12.x/docs/language/block/import.mdx b/content/terraform/v1.12.x/docs/language/block/import.mdx index cb3a28fd60..d8292a8bbd 100644 --- a/content/terraform/v1.12.x/docs/language/block/import.mdx +++ b/content/terraform/v1.12.x/docs/language/block/import.mdx @@ -26,11 +26,14 @@ The following `module` block includes all built-in arguments: ```hcl import { to = resource.type.address - id = "cloud-provider-id" - for_each = { # `for_each` accepts a map or a set of strings + id = "cloud-provider-id" # `id` is mutually exclusive with `identity` + identity = { # `identity` is mutually exclusive with `id` + = + } + for_each = { # `for_each` accepts a map or a set of strings = } - for_each = [ # `for_each` accepts a map or a set of strings + for_each = [ # `for_each` accepts a map or a set of strings "", "" ] diff --git a/content/terraform/v1.13.x/docs/language/block/import.mdx b/content/terraform/v1.13.x/docs/language/block/import.mdx index 2ad3d7c9d5..13a612f3f9 100644 --- a/content/terraform/v1.13.x/docs/language/block/import.mdx +++ b/content/terraform/v1.13.x/docs/language/block/import.mdx @@ -26,11 +26,14 @@ The following `module` block includes all built-in arguments: ```hcl import { to = resource.type.address - id = "cloud-provider-id" - for_each = { # `for_each` accepts a map or a set of strings + id = "cloud-provider-id" # `id` is mutually exclusive with `identity` + identity = { # `identity` is mutually exclusive with `id` + = + } + for_each = { # `for_each` accepts a map or a set of strings = } - for_each = [ # `for_each` accepts a map or a set of strings + for_each = [ # `for_each` accepts a map or a set of strings "", "" ] From f95e96c3e58d9e22476a0c73e473e08854e5a0ad Mon Sep 17 00:00:00 2001 From: trujillo-adam <47586768+trujillo-adam@users.noreply.github.com> Date: Thu, 11 Sep 2025 08:03:14 -0700 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Robin Norwood --- content/terraform/v1.12.x/docs/language/block/import.mdx | 6 +++--- content/terraform/v1.13.x/docs/language/block/import.mdx | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/content/terraform/v1.12.x/docs/language/block/import.mdx b/content/terraform/v1.12.x/docs/language/block/import.mdx index d8292a8bbd..6409ec5e69 100644 --- a/content/terraform/v1.12.x/docs/language/block/import.mdx +++ b/content/terraform/v1.12.x/docs/language/block/import.mdx @@ -14,7 +14,7 @@ An `import` block supports the following configuration: - [`import`](#import)   block - [`to`](#to)   address | required - - [`id`](#id)   string + - [`id`](#id)   string | mutually exclusive with `identity` - [`identity`](#identity)   map | mutually exclusive with `id` - [`for_each`](#for_each)   map or set of strings - [`provider`](#provider)   reference @@ -119,7 +119,7 @@ import { } ``` -The specific attributes are specific to the resource type and provider. You can only import resources that are supported by the provider. Refer to your provider documentation for details. +The keys of the `identity` argument are specific to the resource type and provider. You can only import resources that are supported by the provider. Refer to your provider documentation for details. You cannot use the `identity` argument and [`id` argument](#id) in the same `import` block. @@ -202,7 +202,7 @@ The following examples show how to write configuration for common use cases. ### Import a single resource -You can import an individual resource by specifying its ID in `id` argument or by specifying the set of identifying attributes in the `identity` argument. +You can import an individual resource by specifying its ID with the `id` argument or by specifying the set of identifying attributes in the `identity` argument. diff --git a/content/terraform/v1.13.x/docs/language/block/import.mdx b/content/terraform/v1.13.x/docs/language/block/import.mdx index 13a612f3f9..b7bf0277a5 100644 --- a/content/terraform/v1.13.x/docs/language/block/import.mdx +++ b/content/terraform/v1.13.x/docs/language/block/import.mdx @@ -14,7 +14,7 @@ An `import` block supports the following configuration: - [`import`](#import)   block - [`to`](#to)   address | required - - [`id`](#id)   string + - [`id`](#id)   string | mutually exclusive with `identity` - [`identity`](#identity)   map | mutually exclusive with `id` - [`for_each`](#for_each)   map or set of strings - [`provider`](#provider)   reference @@ -119,7 +119,7 @@ import { } ``` -The specific attributes are specific to the resource type and provider. You can only import resources that are supported by the provider. Refer to your provider documentation for details. +The keys of the `identity` argument are specific to the resource type and provider. You can only import resources that are supported by the provider. Refer to your provider documentation for details. You cannot use the `identity` argument and [`id` argument](#id) in the same `import` block.