docs/ai-agent-guides/parameterized-resource-identity.md
You are working on the Terraform AWS Provider, specifically focused on adding resource identity to Plugin SDKV2 resources whose identity is composed from multiple parameters (parameterized). This Github meta issue contains details and sub-issues related to adding resource identity support.
When adding resource identity, a pull request may include all resources in a service or a single resource. Follow the steps below to complete this task.
f-ri and be suffixed with the name of the service being updated, e.g. f-ri-elbv2. If the current branch does not match this convention, create one.main branch.The changes for each individual resource should be done in its own commit. Use the following steps to add resource identity to an existing resource:
d.SetId(<value>)) and infer the relevant parameters.@IdentityAttribute("<argument_name>") annotation to the target resource. For resources where the ID is composed from multiple arguments, add one annotation for each argument.id attribute is set to the same value as an identity attribute, add an @Testing(idAttrDuplicates="<argument_name>") annotation.CheckExists helper function that accepts 3 parameters rather than 2 (you can check this in the resource's test file), add another annotation to the resource file in the format // @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types;types.TrustStore"), but replacing the type with the correct one for the resource in question. The type should match the third parameter of the CheckExists function.@Testing(preIdentityVersion="v6.3.0"). Use CHANGELOG.md at the project root to determine the most recently released version (which will be the last before identity is added).schema.ImportStatePassthroughContext as StateContext value then remove that importer function declaration as it is no longer necessary.// @CustomImport annotation and include the following at the beginning the custom StateContext function: identitySpec := importer.IdentitySpec(ctx)
if err := importer.RegionalSingleParameterized(ctx, d, identitySpec, meta.(importer.AWSClient)); err != nil {
return nil, err
}
testdata/tmpl directory. For each resource, create a file named <resource>_basic.gtpl (e.g., trust_store_basic.gtpl)._basic test. If populating from the _basic configuration, be sure to replace any string format directives (e.g. name = %[1]q) with a corresponding reference to a variable (e.g. name = var.rName).testdata directory for the service. Do not manually create test directories or files as they will be generated.resource "aws_service_thing" "test" {
{{- template "region" }}
name = var.rName
{{- template "tags" . }}
}
{{- template "tags" . }}, leave it unchanged.aws_region data source, the region template should also be embedded here.data "aws_region" "current" {
{{- template "region" }}
}
go generate ./internal/service/elbv2/.... This will generate tests for Resource Identity and any required test files.make testacc PKG=<service> TESTS=TestAcc<Resource>_Identity_Basicmake testacc PKG=<service> TESTS=TestAcc<Resource>_Identitymake testacc PKG=<service> TESTS=TestAcc<Resource>_. Always include the PKG parameter to properly scope the tests to the intended service package.terraform fmt. To verify, run terraform fmt -recursive -check, and confirm there is no output.r/aws_lb_target_group: add resource identity. Ensure the commit message body includes the results of the acceptance test run in the previous step.Repeat steps 2 and 3 for each resource in the service. When all resources are complete, proceed to the next section.
In Terraform v1.12.0 and later, the [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used with the `identity` attribute. For example:
```terraform
import {
to = <resource-name>.example
identity = {
<required key/value pairs here>
}
}
resource "<resource-name>" "example" {
### Configuration omitted for brevity ###
}
```
### Identity Schema
#### Required
<required attributes here>
#### Optional
* `account_id` (String) AWS Account where this resource is managed.
* `region` (String) Region where this resource is managed.
identity, including the identity schema, should appear before instructions for import blocks with an id argument or importing via the CLI.website/docs/r/kms_key.html.markdown for a reference implementation.!!!Important!!!: Ask for confirmation before proceeding with this step.
<service-name>", e.g. "Add parameterized resource identity to elbv2". If only a single resource is included, replace service-name with the full Terraform resource name.### Description
Add resource identity to parameterized resources in `<service-name>`. This includes:
<list Terraform resource names here>
### Relations
Relates #42983
Relates #42988
### Output from Acceptance Testing
<insert acceptance test results here>
.changelog/<pr-number>.txt, and include one enhancement entry per resource. Refer to .changelog/43503.txt for the appropriate formatting.PKG parameter is included in test commands<resource>_basic.gtpl)testAccCheck*Exists helper function has incorrect arguments, add a @Testing(existsType="") annotation. NEVER modify the function signature of an existing "exists" helper functiontestdata/tmpl)identitytests generator is being called within the service's generate.go file. If it isn't, add the following line to generate.go next to the existing go:generate directives.var.rName variable, add an // @Testing(generator=false) annotation to remove it from the generated configuration.//go:generate go run ../../generate/identitytests/main.go
existsType annotationImportStatePassthroughContext// @Testing(plannableImportAction="NoOp") annotation and re-generate the test files._basic test implementation for the presence of an ImportStateVerifyIgnore field in the import test step. If present, add an // @Testing(importIgnore="arg1") annotation where arg1 is replaced with the argument name(s) from the verify ignore slice. If mutiple fields are ignored, separate field names with a ;, e.g. arg1;arg2.importer package is used.
RegionalSingleParameterized - regional resources whose identity is made up of a single parameter.GlobalSingleParameterized - global resources whose identity is made up of a single parameter.RegionalMultipleParameterized - regional resources whose identity is made up of multiple parameters.GlobalMultipleParameterized - global resources whose identity is made up of multiple parameters.