Skip to content

Commit

Permalink
chore: remove subject keys which are not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
grace-rehn committed Dec 2, 2024
1 parent 0ad741a commit 633ad4b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
resource "octopusdeploy_azure_openid_connect" "example" {
name = "Generic OpenID Connect Account (OK to Delete)"
execution_subject_keys = ["space", "project"]
health_subject_keys = ["space", "target", "type"]
account_test_subject_keys = ["space", "type"]
audience = "api://Default"
audience = "api://default"
}
14 changes: 4 additions & 10 deletions octopusdeploy/resource_generic_oidc_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ func TestAccOctopusDeployGenericOpenIDConnectAccountBasic(t *testing.T) {
tenantedDeploymentMode := core.TenantedDeploymentModeTenantedOrUntenanted

executionKeys := []string{"space"}
healthKeys := []string{"target"}
accountKeys := []string{"type"}
audience := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)

newDescription := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
Expand All @@ -38,11 +36,9 @@ func TestAccOctopusDeployGenericOpenIDConnectAccountBasic(t *testing.T) {
resource.TestCheckResourceAttr(prefix, "name", name),
resource.TestCheckResourceAttr(prefix, "tenanted_deployment_participation", string(tenantedDeploymentMode)),
resource.TestCheckResourceAttr(prefix, "execution_subject_keys.0", executionKeys[0]),
resource.TestCheckResourceAttr(prefix, "health_subject_keys.0", healthKeys[0]),
resource.TestCheckResourceAttr(prefix, "account_test_subject_keys.0", accountKeys[0]),
resource.TestCheckResourceAttr(prefix, "audience", audience),
),
Config: testGenericOpenIDConnectAccountBasic(localName, name, description, tenantedDeploymentMode, executionKeys, healthKeys, accountKeys, audience),
Config: testGenericOpenIDConnectAccountBasic(localName, name, description, tenantedDeploymentMode, executionKeys, audience),
},
{
Check: resource.ComposeTestCheckFunc(
Expand All @@ -51,17 +47,15 @@ func TestAccOctopusDeployGenericOpenIDConnectAccountBasic(t *testing.T) {
resource.TestCheckResourceAttr(prefix, "name", name),
resource.TestCheckResourceAttr(prefix, "tenanted_deployment_participation", string(tenantedDeploymentMode)),
resource.TestCheckResourceAttr(prefix, "execution_subject_keys.0", executionKeys[0]),
resource.TestCheckResourceAttr(prefix, "health_subject_keys.0", healthKeys[0]),
resource.TestCheckResourceAttr(prefix, "account_test_subject_keys.0", accountKeys[0]),
resource.TestCheckResourceAttr(prefix, "audience", audience),
),
Config: testGenericOpenIDConnectAccountBasic(localName, name, newDescription, tenantedDeploymentMode, executionKeys, healthKeys, accountKeys, audience),
Config: testGenericOpenIDConnectAccountBasic(localName, name, newDescription, tenantedDeploymentMode, executionKeys, audience),
},
},
})
}

func testGenericOpenIDConnectAccountBasic(localName string, name string, description string, tenantedDeploymentParticipation core.TenantedDeploymentMode, execution_subject_keys []string, health_subject_keys []string, account_test_subject_keys []string, audience string) string {
func testGenericOpenIDConnectAccountBasic(localName string, name string, description string, tenantedDeploymentParticipation core.TenantedDeploymentMode, execution_subject_keys []string, audience string) string {
return fmt.Sprintf(`resource "octopusdeploy_generic_openid_connect_account" "%s" {
description = "%s"
name = "%s"
Expand All @@ -74,5 +68,5 @@ func testGenericOpenIDConnectAccountBasic(localName string, name string, descrip
data "octopusdeploy_accounts" "test" {
ids = [octopusdeploy_generic_openid_connect_account.%s.id]
}`, localName, description, name, tenantedDeploymentParticipation, StringArrayToTerraformArrayFormat(execution_subject_keys), StringArrayToTerraformArrayFormat(health_subject_keys), StringArrayToTerraformArrayFormat(account_test_subject_keys), audience, localName)
}`, localName, description, name, tenantedDeploymentParticipation, StringArrayToTerraformArrayFormat(execution_subject_keys), audience, localName)
}
22 changes: 4 additions & 18 deletions octopusdeploy/schema_generic_oidc_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@ func expandGenericOpenIDConnectAccount(d *schema.ResourceData) *accounts.Generic
account.TenantIDs = getSliceFromTerraformTypeList(v)
}

if v, ok := d.GetOk("execution_subject_keys"); ok {
account.DeploymentSubjectKeys = getSliceFromTerraformTypeList(v)
if v, ok := d.GetOk("audience"); ok {
account.Audience = v.(string)
}

if v, ok := d.GetOk("health_subject_keys"); ok {
account.HealthCheckSubjectKeys = getSliceFromTerraformTypeList(v)
}

if v, ok := d.GetOk("account_test_subject_keys"); ok {
account.AccountTestSubjectKeys = getSliceFromTerraformTypeList(v)
if v, ok := d.GetOk("execution_subject_keys"); ok {
account.DeploymentSubjectKeys = getSliceFromTerraformTypeList(v)
}

return account
Expand All @@ -68,8 +64,6 @@ func getGenericOpenIdConnectAccountSchema() map[string]*schema.Schema {
"tenants": getTenantsSchema(),
"tenant_tags": getTenantTagsSchema(),
"execution_subject_keys": getSubjectKeysSchema(SchemaSubjectKeysDescriptionExecution),
"health_subject_keys": getSubjectKeysSchema(SchemaSubjectKeysDescriptionHealth),
"account_test_subject_keys": getSubjectKeysSchema(SchemaSubjectKeysDescriptionAccountTest),
"audience": getOidcAudienceSchema(),
}
}
Expand Down Expand Up @@ -98,13 +92,5 @@ func setGenericOpenIDConnectAccount(ctx context.Context, d *schema.ResourceData,
return fmt.Errorf("error setting execution_subject_keys: %s", err)
}

if err := d.Set("health_subject_keys", account.HealthCheckSubjectKeys); err != nil {
return fmt.Errorf("error setting health_subject_keys: %s", err)
}

if err := d.Set("account_test_subject_keys", account.AccountTestSubjectKeys); err != nil {
return fmt.Errorf("error setting account_test_subject_keys: %s", err)
}

return nil
}

0 comments on commit 633ad4b

Please sign in to comment.