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

vault_approle_auth_backend_role: Fix perpetual diff when upgrading from policies to token_policies #744

Merged
merged 2 commits into from
May 7, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add regression test for #533
  • Loading branch information
catsby committed May 7, 2020

Verified

This commit was signed with the committer’s verified signature.
catsby Clint
commit efac989b319f1cac1cb9f2e7f3bb03e9129b833c
87 changes: 85 additions & 2 deletions vault/resource_approle_auth_backend_role_test.go
Original file line number Diff line number Diff line change
@@ -348,7 +348,7 @@ func TestAccAppRoleAuthBackendRole_deprecatedFullUpdate(t *testing.T) {
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"secret_id_num_uses", "5"),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"period", "0"),
"token_period", "0"),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"bind_secret_id", "false"),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
@@ -377,7 +377,7 @@ func TestAccAppRoleAuthBackendRole_deprecatedFullUpdate(t *testing.T) {
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"secret_id_num_uses", "10"),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"period", "0"),
"token_period", "0"),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"bind_secret_id", "true"),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
@@ -520,3 +520,86 @@ resource "vault_approle_auth_backend_role" "role" {
token_max_ttl = 10800
}`, backend, role, roleID)
}

// TestAccAppRoleAuthBackendRole_token_policy_update is a regression test for
// https://github.com/terraform-providers/terraform-provider-vault/issues/533
func TestAccAppRoleAuthBackendRole_token_policy_update(t *testing.T) {
backend := acctest.RandomWithPrefix("approle")
role := acctest.RandomWithPrefix("test-role")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testProviders,
CheckDestroy: testAccCheckAppRoleAuthBackendRoleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAppRoleAuthBackendRole_policy(backend, role),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"backend", backend),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"role_name", role),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"policies.#", "3"),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"period", "86400"),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"token_policies.#", "0"),
resource.TestCheckResourceAttrSet("vault_approle_auth_backend_role.role",
"role_id"),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"token_period", "0"),
),
},
{
Config: testAccAppRoleAuthBackendRole_token_policy(backend, role),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"backend", backend),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"role_name", role),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"policies.#", "0"),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"period", "0"),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"token_policies.#", "3"),
resource.TestCheckResourceAttrSet("vault_approle_auth_backend_role.role",
"role_id"),
resource.TestCheckResourceAttr("vault_approle_auth_backend_role.role",
"token_period", "86400"),
),
},
},
})
}

func testAccAppRoleAuthBackendRole_policy(backend, role string) string {
return fmt.Sprintf(`
resource "vault_auth_backend" "approle" {
type = "approle"
path = "%s"
}

resource "vault_approle_auth_backend_role" "role" {
backend = "${vault_auth_backend.approle.path}"
role_name = "%s"
policies = ["default", "dev", "prod"]
period = 86400
}`, backend, role)
}

func testAccAppRoleAuthBackendRole_token_policy(backend, role string) string {
return fmt.Sprintf(`
resource "vault_auth_backend" "approle" {
type = "approle"
path = "%s"
}

resource "vault_approle_auth_backend_role" "role" {
backend = "${vault_auth_backend.approle.path}"
role_name = "%s"
token_policies = ["default", "dev", "prod"]
token_period = 86400
}`, backend, role)
}