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..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,8 +14,8 @@ 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 @@ -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 "", "" ] @@ -95,9 +98,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 +106,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 +202,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 with the `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 +217,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..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,8 +14,8 @@ 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 @@ -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 "", "" ] @@ -95,9 +98,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 +106,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 +202,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 +217,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 +326,4 @@ import { resource "aws_instance" "web" { # ... -} +} \ No newline at end of file