-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Convert SingleNestedBlocks to ListNestedBlocks and fix arg required states for aws_paymentcryptography_key #41379
Conversation
Community NoteVoting for Prioritization
For Submitters
|
…red states for aws_paymentcryptography_key
e9425c7
to
dbc4fc6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
% make testacc PKG=paymentcryptography TESTS=TestAccPaymentCryptographyKey_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.5 test ./internal/service/paymentcryptography/... -v -count 1 -parallel 20 -run='TestAccPaymentCryptographyKey_' -timeout 360m -vet=off
2025/02/14 11:23:46 Initializing Terraform AWS Provider...
--- PASS: TestAccPaymentCryptographyKey_disappears (13.42s)
--- PASS: TestAccPaymentCryptographyKey_basic (15.72s)
--- PASS: TestAccPaymentCryptographyKey_tags (23.99s)
--- PASS: TestAccPaymentCryptographyKey_update (32.08s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/paymentcryptography 38.771s
@@ -0,0 +1,3 @@ | |||
```release-note:bug | |||
resource/aws_paymentcryptography_key: Set `key_attributes` and `key_attributes.*.key_modes_of_use` arguments to required |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed these are required by the AWS API.
Thanks for the clean up, @acwwat! 👍 |
After additional review from the team, this will need to be reverted as changing from For example, and upgrade test fails as follows. func TestAccPaymentCryptographyKey_v5_87_0_upgrade(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}
var key paymentcryptography.GetKeyOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_paymentcryptography_key.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.PaymentCryptographyServiceID),
CheckDestroy: testAccCheckKeyDestroy(ctx),
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
Source: "hashicorp/aws",
VersionConstraint: "5.87.0",
},
},
Config: testAccKeyConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckKeyExists(ctx, resourceName, &key),
),
},
{
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Config: testAccKeyConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckKeyExists(ctx, resourceName, &key),
resource.TestCheckResourceAttr(resourceName, names.AttrEnabled, acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "exportable", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "key_attributes.#", "1"),
resource.TestCheckResourceAttr(resourceName, "key_attributes.0.key_algorithm", "TDES_3KEY"),
resource.TestCheckResourceAttr(resourceName, "key_attributes.0.key_class", "SYMMETRIC_KEY"),
resource.TestCheckResourceAttr(resourceName, "key_attributes.0.key_usage", "TR31_P0_PIN_ENCRYPTION_KEY"),
resource.TestCheckResourceAttr(resourceName, "key_attributes.0.key_modes_of_use.#", "1"),
resource.TestCheckResourceAttr(resourceName, "key_attributes.0.key_modes_of_use.0.decrypt", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "key_attributes.0.key_modes_of_use.0.encrypt", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "key_attributes.0.key_modes_of_use.0.wrap", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "key_attributes.0.key_modes_of_use.0.unwrap", acctest.CtTrue),
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "payment-cryptography", regexache.MustCompile(`key/.+`)),
),
},
},
})
} % make testacc PKG=paymentcryptography TESTS=TestAccPaymentCryptographyKey_v5_87_0_upgrade
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.5 test ./internal/service/paymentcryptography/... -v -count 1 -parallel 20 -run='TestAccPaymentCryptographyKey_v5_87_0_upgrade' -timeout 360m -vet=off
2025/02/14 13:49:10 Initializing Terraform AWS Provider...
=== RUN TestAccPaymentCryptographyKey_v5_87_0_upgrade
=== PAUSE TestAccPaymentCryptographyKey_v5_87_0_upgrade
=== CONT TestAccPaymentCryptographyKey_v5_87_0_upgrade
key_test.go:37: Step 2/2 error: Error running pre-apply plan: exit status 1
Error: Unable to Read Previously Saved State for UpgradeResourceState
with aws_paymentcryptography_key.test,
on terraform_plugin_test.tf line 12, in resource "aws_paymentcryptography_key" "test":
12: resource "aws_paymentcryptography_key" "test" {
There was an error reading the saved resource state using the current
resource schema.
If this resource state was last refreshed with Terraform CLI 0.11 and
earlier, it must be refreshed or applied with an older provider version
first. If you manually modified the resource state, you will need to manually
modify it to match the current resource schema. Otherwise, please report this
to the provider developer:
AttributeName("key_attributes"): invalid JSON, expected "[", got "{"
panic.go:629: Error retrieving state, there may be dangling resources: exit status 1
Failed to marshal state to json: missing expected [
--- FAIL: TestAccPaymentCryptographyKey_v5_87_0_upgrade (29.76s)
FAIL
FAIL github.com/hashicorp/terraform-provider-aws/internal/service/paymentcryptography 36.457s I'll open a PR shortly to revert this. We can open a new PR with this same change that includes a state upgrader and slot if for inclusion as part of the |
…rg required states for aws_paymentcryptography_key (#41379)" This reverts commit 44e7b1b. After additional review from the team, this will need to be reverted as changing from `SingleNestedBlock` to `ListNestedBlock` causes changes to the underlying schema which must be accounted for via a state upgrader. See [this comment](#41379 (comment)) for additional details.
…rg required states for aws_paymentcryptography_key (#41379)" (#41402) This reverts commit 44e7b1b. After additional review from the team, this will need to be reverted as changing from `SingleNestedBlock` to `ListNestedBlock` causes changes to the underlying schema which must be accounted for via a state upgrader. See [this comment](#41379 (comment)) for additional details.
Description
This PR is to converted all
SingleNestedBlock
s toListNestedBlock
s and properly set the required states for affected arguments in theaws_paymentcryptography_key
resource.Relations
Relates #35813
References
n/a
Output from Acceptance Testing