You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add details about identity arg in import ref (#924)
We commented out the `identity` argument when we rewrote the `import`
block reference because it hadn't yet been adopted by provider
developers, which was leading to confusion. This PR re-adds the argument
and provides an example.
-[`id`](#id)   string | mutually exclusive with `identity`
18
+
-[`identity`](#identity)   map | mutually exclusive with `id`
19
19
-[`for_each`](#for_each)   map or set of strings
20
20
-[`provider`](#provider)   reference
21
21
@@ -26,11 +26,14 @@ The following `module` block includes all built-in arguments:
26
26
```hcl
27
27
import {
28
28
to = resource.type.address
29
-
id="cloud-provider-id"
30
-
for_each= { # `for_each` accepts a map or a set of strings
29
+
id = "cloud-provider-id" # `id` is mutually exclusive with `identity`
30
+
identity = { # `identity` is mutually exclusive with `id`
31
+
<ATTRIBUTE> = <VALUE>
32
+
}
33
+
for_each = { # `for_each` accepts a map or a set of strings
31
34
<KEY> = <VALUE>
32
35
}
33
-
for_each = [ # `for_each` accepts a map or a set of strings
36
+
for_each = [ # `for_each` accepts a map or a set of strings
34
37
"<VALUE>",
35
38
"<VALUE>"
36
39
]
@@ -95,20 +98,18 @@ You must specify a string or an expression that evaluates to a string. The ID mu
95
98
96
99
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.
97
100
98
-
<!--// HIDING INFO ABOUT IDENTITY FOR NOW //
99
101
You cannot use the `id` argument and [`identity` argument](#identity) in the same `import` block.
100
-
-->
101
102
102
103
#### Summary
103
104
104
105
- Data type: String
105
106
- Default: None
106
107
- Example: [Import a single resource](#import-a-single-resource)
107
108
108
-
<!-- leave out for now - providers are not using this yet
109
+
109
110
### `identity`
110
111
111
-
The `identity` argument specifies a resource identity object that uniquely identifies a resource.
112
+
The `identity` argument specifies a set of attributes that uniquely identifies a resource.
112
113
113
114
```hcl
114
115
import {
@@ -118,9 +119,7 @@ import {
118
119
}
119
120
```
120
121
121
-
The `identity` argument is an object of key-value pairs that uniquely identify a resource. The keys and values are specific to the resource type and provider.
122
-
123
-
The key-value pair for the `identity` object depends on the type of resource you are importing. You can only import resources that are supported by the provider. Refer to the provider documentation for information about how to retrieve the `identity`.
122
+
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.
124
123
125
124
You cannot use the `identity` argument and [`id` argument](#id) in the same `import` block.
126
125
@@ -130,7 +129,6 @@ You cannot use the `identity` argument and [`id` argument](#id) in the same `imp
130
129
- Default: None
131
130
- Example: [Import a single resource](#import-a-single-resource)
132
131
133
-
-->
134
132
135
133
### `for_each`
136
134
@@ -204,8 +202,13 @@ The following examples show how to write configuration for common use cases.
204
202
205
203
### Import a single resource
206
204
207
-
In the following example, Terraform imports `example-bucket` into a resource at `aws_s3_bucket.this`:
205
+
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.
206
+
207
+
<Tabs>
208
+
209
+
<Tabheading="Import using ID">
208
210
211
+
In the following example, Terraform imports `example-bucket` into a resource at `aws_s3_bucket.this`:
209
212
210
213
```hcl
211
214
import {
@@ -214,13 +217,34 @@ import {
214
217
}
215
218
216
219
resource "aws_s3_bucket" "this" {
217
-
}
218
220
# …
219
221
}
220
222
```
221
223
222
224
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.
223
225
226
+
</Tab>
227
+
228
+
<Tabheading="Import using identity attributes">
229
+
230
+
In the following example, Terraform imports an S3 bucket using its `account_id`, `bucket`, and `region` attributes:
231
+
232
+
```hcl
233
+
import {
234
+
to = aws_s3_bucket.bucket
235
+
identity = {
236
+
account_id = "622801496880"
237
+
bucket = "hjarui4t89efuh"
238
+
region = "us-east-1"
239
+
}
240
+
}
241
+
```
242
+
243
+
244
+
</Tab>
245
+
246
+
</Tabs>
247
+
224
248
### Import multiple resources
225
249
226
250
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"]`.
-[`id`](#id)   string | mutually exclusive with `identity`
18
+
-[`identity`](#identity)   map | mutually exclusive with `id`
19
19
-[`for_each`](#for_each)   map or set of strings
20
20
-[`provider`](#provider)   reference
21
21
@@ -26,11 +26,14 @@ The following `module` block includes all built-in arguments:
26
26
```hcl
27
27
import {
28
28
to = resource.type.address
29
-
id="cloud-provider-id"
30
-
for_each= { # `for_each` accepts a map or a set of strings
29
+
id = "cloud-provider-id" # `id` is mutually exclusive with `identity`
30
+
identity = { # `identity` is mutually exclusive with `id`
31
+
<ATTRIBUTE> = <VALUE>
32
+
}
33
+
for_each = { # `for_each` accepts a map or a set of strings
31
34
<KEY> = <VALUE>
32
35
}
33
-
for_each = [ # `for_each` accepts a map or a set of strings
36
+
for_each = [ # `for_each` accepts a map or a set of strings
34
37
"<VALUE>",
35
38
"<VALUE>"
36
39
]
@@ -95,20 +98,18 @@ You must specify a string or an expression that evaluates to a string. The ID mu
95
98
96
99
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.
97
100
98
-
<!--// HIDING INFO ABOUT IDENTITY FOR NOW //
99
101
You cannot use the `id` argument and [`identity` argument](#identity) in the same `import` block.
100
-
-->
101
102
102
103
#### Summary
103
104
104
105
- Data type: String
105
106
- Default: None
106
107
- Example: [Import a single resource](#import-a-single-resource)
107
108
108
-
<!-- leave out for now - providers are not using this yet
109
+
109
110
### `identity`
110
111
111
-
The `identity` argument specifies a resource identity object that uniquely identifies a resource.
112
+
The `identity` argument specifies a set of attributes that uniquely identifies a resource.
112
113
113
114
```hcl
114
115
import {
@@ -118,9 +119,7 @@ import {
118
119
}
119
120
```
120
121
121
-
The `identity` argument is an object of key-value pairs that uniquely identify a resource. The keys and values are specific to the resource type and provider.
122
-
123
-
The key-value pair for the `identity` object depends on the type of resource you are importing. You can only import resources that are supported by the provider. Refer to the provider documentation for information about how to retrieve the `identity`.
122
+
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.
124
123
125
124
You cannot use the `identity` argument and [`id` argument](#id) in the same `import` block.
126
125
@@ -130,7 +129,6 @@ You cannot use the `identity` argument and [`id` argument](#id) in the same `imp
130
129
- Default: None
131
130
- Example: [Import a single resource](#import-a-single-resource)
132
131
133
-
-->
134
132
135
133
### `for_each`
136
134
@@ -204,8 +202,13 @@ The following examples show how to write configuration for common use cases.
204
202
205
203
### Import a single resource
206
204
207
-
In the following example, Terraform imports `example-bucket` into a resource at `aws_s3_bucket.this`:
205
+
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.
208
206
207
+
<Tabs>
208
+
209
+
<Tabheading="Import using ID">
210
+
211
+
In the following example, Terraform imports `example-bucket` into a resource at `aws_s3_bucket.this`:
209
212
210
213
```hcl
211
214
import {
@@ -214,13 +217,34 @@ import {
214
217
}
215
218
216
219
resource "aws_s3_bucket" "this" {
217
-
}
218
220
# …
219
221
}
220
222
```
221
223
222
224
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.
223
225
226
+
</Tab>
227
+
228
+
<Tabheading="Import using identity attributes">
229
+
230
+
In the following example, Terraform imports an S3 bucket using its `account_id`, `bucket`, and `region` attributes:
231
+
232
+
```hcl
233
+
import {
234
+
to = aws_s3_bucket.bucket
235
+
identity = {
236
+
account_id = "622801496880"
237
+
bucket = "hjarui4t89efuh"
238
+
region = "us-east-1"
239
+
}
240
+
}
241
+
```
242
+
243
+
244
+
</Tab>
245
+
246
+
</Tabs>
247
+
224
248
### Import multiple resources
225
249
226
250
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"]`.
0 commit comments