Skip to content

Fix bound_claims not getting unset for vault_jwt_auth_backend_role - #1469

Merged
benashz merged 3 commits into
hashicorp:mainfrom
lawliet89:rm-boundclaims
May 31, 2022
Merged

Fix bound_claims not getting unset for vault_jwt_auth_backend_role#1469
benashz merged 3 commits into
hashicorp:mainfrom
lawliet89:rm-boundclaims

Conversation

@lawliet89

@lawliet89 lawliet89 commented May 30, 2022

Copy link
Copy Markdown
Member

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

When bound_claims in vault_jwt_auth_backend_role is unset, it does not get removed from the role, resulting in a permanent diff and unexpected results.

Release note for CHANGELOG:

Fix `bound_claims` not getting removed for `vault_jwt_auth_backend_role`

Output from acceptance testing:

$ $ VAULT_ADDR=http://127.0.0.1:8200 VAULT_TOKEN=12345 TESTARGS="--run TestAccJWTAuthBackendRole" make testacc
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test -v --run TestAccJWTAuthBackendRole -timeout 30m ./...
?       github.com/hashicorp/terraform-provider-vault   [no test files]
?       github.com/hashicorp/terraform-provider-vault/cmd/coverage      [no test files]
?       github.com/hashicorp/terraform-provider-vault/cmd/generate      [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/codegen   (cached) [no tests to run]
?       github.com/hashicorp/terraform-provider-vault/generated [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/datasources/transform/decode    (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/datasources/transform/encode    (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/alphabet    (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/role        (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/template    (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/transformation      (cached) [no tests to run]
?       github.com/hashicorp/terraform-provider-vault/helper    [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/internal/identity/entity  (cached) [no tests to run]
?       github.com/hashicorp/terraform-provider-vault/schema    [no test files]
?       github.com/hashicorp/terraform-provider-vault/testutil  [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/util      (cached) [no tests to run]
=== RUN   TestAccJWTAuthBackendRole_import
--- PASS: TestAccJWTAuthBackendRole_import (0.66s)
=== RUN   TestAccJWTAuthBackendRole_basic
--- PASS: TestAccJWTAuthBackendRole_basic (0.55s)
=== RUN   TestAccJWTAuthBackendRole_update
--- PASS: TestAccJWTAuthBackendRole_update (0.96s)
=== RUN   TestAccJWTAuthBackendRole_full
--- PASS: TestAccJWTAuthBackendRole_full (0.70s)
=== RUN   TestAccJWTAuthBackendRoleOIDC_full
--- PASS: TestAccJWTAuthBackendRoleOIDC_full (1.19s)
=== RUN   TestAccJWTAuthBackendRoleOIDC_disableParsing
--- PASS: TestAccJWTAuthBackendRoleOIDC_disableParsing (1.19s)
=== RUN   TestAccJWTAuthBackendRole_fullUpdate
--- PASS: TestAccJWTAuthBackendRole_fullUpdate (1.77s)
PASS
ok      github.com/hashicorp/terraform-provider-vault/vault     7.042s

If the else clause I added in the resource is removed, the test above fails with

=== RUN   TestAccJWTAuthBackendRole_fullUpdate
    resource_jwt_auth_backend_role_test.go:371: Step 3/3 error: Check failed: 1 error occurred:
                * Check 23/23 error: vault_jwt_auth_backend_role.role: Attribute 'bound_claims.%' expected "0", got "2"

thereby confirming the bug.

@lawliet89 lawliet89 changed the title Fix bound_claims not getting removed for vault_jwt_auth_backend_role Fix bound_claims not getting unset for vault_jwt_auth_backend_role May 30, 2022
Comment thread vault/resource_jwt_auth_backend_role.go Outdated
}
data["bound_claims"] = boundClaims
} else {
data["bound_claims"] = make(map[string]interface{}, 0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The empty map is defined on line 396 above. If we move that before the conditional we can drop the else{} and always set bound_claims

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've done this.

"verbose_oidc_logging", "false"),
),
},
// Repeat test case again to remove attributes like `bound_claims`

@benashz benashz May 30, 2022

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would you mind moving these test check funcs to a common set that can be shared between the various steps. Please use

Check: resource.ComposeTestCheckFunc(
as an example.

The resource name/path should also be factored out to a test variable called resourceName, e.g.

resourceName := "vault_pki_secret_backend_role.test"

Thanks

@lawliet89 lawliet89 May 31, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I reduced a bit of code repetition but I did not refactor out the test steps into a separate function yet. This seems like more of a refactoring effort that might make the size of this PR bigger than necessary.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ok, we will take care of that after merge. Thanks!

@benashz benashz added this to the 3.7.0 milestone May 30, 2022
@benashz benashz added the bug label May 30, 2022
@github-actions github-actions Bot added size/M and removed size/S labels May 31, 2022

@benashz benashz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank for your contribution to HashiCorp!

@benashz
benashz merged commit 3833607 into hashicorp:main May 31, 2022
@lawliet89
lawliet89 deleted the rm-boundclaims branch June 1, 2022 12:09
marcboudreau pushed a commit to marcboudreau/terraform-provider-vault that referenced this pull request Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants