Skip to content
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

Resource azurerm_federated_identity_credential - Fix generation of parent User Assigned Identity ID field #20219

Merged
merged 1 commit into from
Jan 30, 2023

Conversation

AndresRCB
Copy link
Contributor

@AndresRCB AndresRCB commented Jan 30, 2023

Resource azurerm_federated_identity_credential - Fix generation of parent User Assigned Identity ID field

When the provider read the state of existing azurerm_federated_identity_credential resources, it constructed the resource ID for its parent_id attribute using the wrong resource ID (its own name instead of the parent UserAssignedidentity name). Updating the call to construct the ID with the right parameter fixes the issue.

Issues

Fixes #20217

Acceptance tests

Didn't add more tests because current tests catch the bug.

Output before fix

~/go/src/github.com/hashicorp/terraform-provider-azurerm (fed-identity-id-parentid-bug ✗) make acctests SERVICE='managedidentity' TESTARGS='-run=TestAccFederatedIdentityCredential_' TESTTIMEOUT='60m'
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test -v ./internal/services/managedidentity -run=TestAccFederatedIdentityCredential_ -timeout 60m -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccFederatedIdentityCredential_basic
=== PAUSE TestAccFederatedIdentityCredential_basic
=== RUN   TestAccFederatedIdentityCredential_requiresImport
=== PAUSE TestAccFederatedIdentityCredential_requiresImport
=== CONT  TestAccFederatedIdentityCredential_basic
=== CONT  TestAccFederatedIdentityCredential_requiresImport
    testcase.go:110: Step 1/2 error: After applying this test step, the plan was not empty.
        stdout:
        
        
        Terraform used the selected providers to generate the following execution
        plan. Resource actions are indicated with the following symbols:
        -/+ destroy and then create replacement
        
        Terraform will perform the following actions:
        
          # azurerm_federated_identity_credential.test must be replaced
        -/+ resource "azurerm_federated_identity_credential" "test" {
              ~ id                  = "/subscriptions/redacted/resourceGroups/acctestrg-230130095343561802/providers/Microsoft.ManagedIdentity/userAssignedIdentities/acctestuai-230130095343561802/federatedIdentityCredentials/acctest-230130095343561802" -> (known after apply)
                name                = "acctest-230130095343561802"
              ~ parent_id           = "/subscriptions/redacted/resourceGroups/acctestrg-230130095343561802/providers/Microsoft.ManagedIdentity/userAssignedIdentities/acctest-230130095343561802" -> "/subscriptions/redacted/resourceGroups/acctestrg-230130095343561802/providers/Microsoft.ManagedIdentity/userAssignedIdentities/acctestuai-230130095343561802" # forces replacement
                # (4 unchanged attributes hidden)
            }
        
        Plan: 1 to add, 0 to change, 1 to destroy.
=== CONT  TestAccFederatedIdentityCredential_basic
    testcase.go:110: Step 1/2 error: After applying this test step, the plan was not empty.
        stdout:
        
        
        Terraform used the selected providers to generate the following execution
        plan. Resource actions are indicated with the following symbols:
        -/+ destroy and then create replacement
        
        Terraform will perform the following actions:
        
          # azurerm_federated_identity_credential.test must be replaced
        -/+ resource "azurerm_federated_identity_credential" "test" {
              ~ id                  = "/subscriptions/redacted/resourceGroups/acctestrg-230130095343565984/providers/Microsoft.ManagedIdentity/userAssignedIdentities/acctestuai-230130095343565984/federatedIdentityCredentials/acctest-230130095343565984" -> (known after apply)
                name                = "acctest-230130095343565984"
              ~ parent_id           = "/subscriptions/redacted/resourceGroups/acctestrg-230130095343565984/providers/Microsoft.ManagedIdentity/userAssignedIdentities/acctest-230130095343565984" -> "/subscriptions/redacted/resourceGroups/acctestrg-230130095343565984/providers/Microsoft.ManagedIdentity/userAssignedIdentities/acctestuai-230130095343565984" # forces replacement
                # (4 unchanged attributes hidden)
            }
        
        Plan: 1 to add, 0 to change, 1 to destroy.
--- FAIL: TestAccFederatedIdentityCredential_requiresImport (162.81s)
--- FAIL: TestAccFederatedIdentityCredential_basic (165.10s)
FAIL
FAIL	github.com/hashicorp/terraform-provider-azurerm/internal/services/managedidentity	167.745s
FAIL
make: *** [acctests] Error 1

Output after fix

~/go/src/github.com/hashicorp/terraform-provider-azurerm (fed-identity-id-parentid-bug ✗) make acctests SERVICE='managedidentity' TESTARGS='-run=TestAccFederatedIdentityCredential_' TESTTIMEOUT='60m'
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test -v ./internal/services/managedidentity -run=TestAccFederatedIdentityCredential_ -timeout 60m -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccFederatedIdentityCredential_basic
=== PAUSE TestAccFederatedIdentityCredential_basic
=== RUN   TestAccFederatedIdentityCredential_requiresImport
=== PAUSE TestAccFederatedIdentityCredential_requiresImport
=== CONT  TestAccFederatedIdentityCredential_basic
=== CONT  TestAccFederatedIdentityCredential_requiresImport
--- PASS: TestAccFederatedIdentityCredential_requiresImport (198.81s)
--- PASS: TestAccFederatedIdentityCredential_basic (238.94s)
PASS
ok  	github.com/hashicorp/terraform-provider-azurerm/internal/services/managedidentity	240.128s

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for this @AndresRCB

@katbyte katbyte merged commit 1c3b780 into hashicorp:main Jan 30, 2023
@github-actions github-actions bot added this to the v3.42.0 milestone Jan 30, 2023
katbyte added a commit that referenced this pull request Jan 30, 2023
@AndresRCB AndresRCB deleted the fed-identity-id-parentid-bug branch January 30, 2023 17:42
@github-actions
Copy link

github-actions bot commented Feb 3, 2023

This functionality has been released in v3.42.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

github-actions bot commented Mar 6, 2023

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants