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

Add iam_tags to vault_aws_secret_backend_role resource #2087

Closed
wants to merge 4 commits into from

Conversation

pporee
Copy link

@pporee pporee commented Nov 15, 2023

Description

Fix #1073

Relates OR Closes #0000

Checklist

  • Added CHANGELOG entry (only for user-facing changes)
  • Acceptance tests where run against all supported Vault Versions

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccXXX'

...

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

@hashicorp-cla
Copy link

hashicorp-cla commented Nov 15, 2023

CLA assistant check
All committers have signed the CLA.

@thyton thyton self-requested a review November 15, 2023 22:32
Copy link
Contributor

@thyton thyton left a comment

Choose a reason for hiding this comment

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

Hi @pporee, this PR seems to break some of the acceptance tests (see below for an example). Local test setup guides can be found at https://github.com/hashicorp/terraform-provider-vault/blob/main/README.md#developing-the-provider. Could you take a look and drop your acceptance tests' output in the description like #781's?

~/go/src/github.com/community/pporee/terraform-provider-vault (main) $ make testacc TESTARGS='-run=TestAccAWSSecretBackendRole'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test -run=TestAccAWSSecretBackendRole -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]
?   	github.com/hashicorp/terraform-provider-vault/helper	[no test files]
?   	github.com/hashicorp/terraform-provider-vault/internal/consts	[no test files]
?   	github.com/hashicorp/terraform-provider-vault/internal/identity/group	[no test files]
?   	github.com/hashicorp/terraform-provider-vault/internal/identity/mfa	[no test files]
?   	github.com/hashicorp/terraform-provider-vault/internal/pki	[no test files]
ok  	github.com/hashicorp/terraform-provider-vault/codegen	(cached) [no tests to run]
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]
ok  	github.com/hashicorp/terraform-provider-vault/internal/provider	(cached) [no tests to run]
ok  	github.com/hashicorp/terraform-provider-vault/testutil	(cached) [no tests to run]
ok  	github.com/hashicorp/terraform-provider-vault/util	(cached) [no tests to run]
--- FAIL: TestAccAWSSecretBackendRole_import (2.63s)
    resource_aws_secret_backend_role_test.go:61: Step 2/6 error running import: ImportStateVerify attributes not equivalent. Difference is shown below. The - symbol indicates attributes missing after import.
        
          map[string]string{
        - 	"iam_tags.%":    "2",
        - 	"iam_tags.key1": "value1",
        - 	"iam_tags.key2": "value2",
          }
FAIL
FAIL	github.com/hashicorp/terraform-provider-vault/vault	12.007s
FAIL
make: *** [testacc] Error 1

Please let us know if you need any help.

Thanks,
Thy

@@ -145,6 +145,8 @@ func testAccAWSSecretBackendRoleCheckBasicAttributes(name, backend string) resou
resource.TestCheckResourceAttr("vault_aws_secret_backend_role.test_policy_inline", "backend", backend),
testutil.TestCheckResourceAttrJSON("vault_aws_secret_backend_role.test_policy_inline", "policy_document", testAccAWSSecretBackendRolePolicyInline_basic),
resource.TestCheckResourceAttr("vault_aws_secret_backend_role.test_policy_inline", "iam_groups.#", "0"),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think another test for the map's key length can ensure the map value.

Suggested change
resource.TestCheckResourceAttr("vault_aws_secret_backend_role.test_policy_inline", "iam_groups.#", "0"),
resource.TestCheckResourceAttr("vault_aws_secret_backend_role.test_policy_inline", "iam_groups.#", "0"),
resource.TestCheckResourceAttr("vault_aws_secret_backend_role.test_policy_inline", "iam_tags.%", "2"),

@@ -177,6 +179,8 @@ func testAccAWSSecretBackendRoleCheckUpdatedAttributes(name, backend string) res
resource.TestCheckResourceAttr("vault_aws_secret_backend_role.test_policy_inline", "default_sts_ttl", "3600"),
resource.TestCheckResourceAttr("vault_aws_secret_backend_role.test_policy_inline", "max_sts_ttl", "21600"),
resource.TestCheckResourceAttr("vault_aws_secret_backend_role.test_policy_inline", "iam_groups.#", "2"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
resource.TestCheckResourceAttr("vault_aws_secret_backend_role.test_policy_inline", "iam_groups.#", "2"),
resource.TestCheckResourceAttr("vault_aws_secret_backend_role.test_policy_inline", "iam_groups.#", "2"),
resource.TestCheckResourceAttr("vault_aws_secret_backend_role.test_policy_inline", "iam_tags.%", "2"),

@@ -123,6 +131,8 @@ func awsSecretBackendRoleWrite(d *schema.ResourceData, meta interface{}) error {

iamGroups := d.Get("iam_groups").(*schema.Set).List()

iamTags, iamTagsOk := d.GetOk("iam_tags")
Copy link
Contributor

Choose a reason for hiding this comment

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

Get will return the data for the given key, or nil if the key doesn't exist in the schema.

Suggested change
iamTags, iamTagsOk := d.GetOk("iam_tags")
iamTags := d.Get("iam_tags")

@@ -155,6 +165,9 @@ func awsSecretBackendRoleWrite(d *schema.ResourceData, meta interface{}) error {
if d.HasChange("iam_groups") {
data["iam_groups"] = iamGroups
}
if iamTagsOk {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also check if the value has changed, following the current practice from other fields/keys.

Suggested change
if iamTagsOk {
if d.HasChange("iam_tags") {

@@ -233,6 +241,10 @@ resource "vault_aws_secret_backend_role" "test_policy_arns" {
policy_arns = ["%s"]
credential_type = "iam_user"
backend = vault_aws_secret_backend.test.path
iam_tags = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like resource.TestCheckResourceAttr(...) tests for iam_tags of resource "vault_aws_secret_backend_role.test_policy_arns" are missing.

Could you please enhance its test coverage like how you did for resource "vault_aws_secret_backend_role.test_policy_inline"?

Comment on lines +331 to +334
iam_tags = {
"key1" = "value1"
"key2" = "value2"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment to the above to enhance test coverage.

Comment on lines +299 to +302
iam_tags = {
"key1" = "value1"
"key2" = "value2"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment to the above to enhance test coverage.

Comment on lines +286 to +289
iam_tags = {
"key1" = "value1"
"key2" = "value2"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment to the above to enhance test coverage.

Comment on lines +387 to +390
iam_tags = {
"key1" = "value1"
"key2" = "value2"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
iam_tags = {
"key1" = "value1"
"key2" = "value2"
}
iam_tags = {
"key1" = "value1"
"key2" = "value2"
}

Comment on lines +374 to +377
iam_tags = {
"key1" = "value1"
"key2" = "value2"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
iam_tags = {
"key1" = "value1"
"key2" = "value2"
}
iam_tags = {
"key1" = "value1"
"key2" = "value2"
}

@Shocktrooper
Copy link

Hello! I am interested in this because it will allow us to use AWS policy variables in our IAM policies. Without this we cannot do that and thus cannot use AWS Policy variables based off of tags

@Shocktrooper
Copy link

@thyton Can you check this code again and see if there are any other changes needed other than what you have reviewed since its a few months old now. if @pporee cannot complete this I can go ahead and try to finish it with a new MR

@thyton
Copy link
Contributor

thyton commented Apr 30, 2024

@Shocktrooper Thank you for your patience! I've created a WIP #2231 to finish the remaining work and close this PR.
I'm expecting to close #2231 within 2 weeks.

@thyton thyton closed this Apr 30, 2024
@Shocktrooper
Copy link

Thank you for picking this up! @thyton Let me know if there is anything I can do

@thyton
Copy link
Contributor

thyton commented May 1, 2024

@pporee @Shocktrooper This feature will be out in release 4.3.0. Thank you again for your patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vault_aws_secret_backend_role doesn't support specifying iam_tags
4 participants