Skip to content

Commit

Permalink
added tests, plus support for audience
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 committed Nov 27, 2023
1 parent ac5cfe0 commit 5363241
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 7 deletions.
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy

go 1.20

replace (
github.com/OctopusDeploy/go-octopusdeploy/v2 => ../go-octopusdeploy
)

require (
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.33.3
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.34.0
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20230705105638-f5ef7c07973b
github.com/google/uuid v1.3.0
github.com/gruntwork-io/terratest v0.41.11
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugX
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
github.com/Microsoft/hcsshim v0.9.7 h1:mKNHW/Xvv1aFH87Jb6ERDzXTJTLPlmzfZ28VBFD/bfg=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.33.3 h1:5+ChMTskACIVLKj8YX45XAQfAjVnfm6ftL+n6Kc7dTY=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.33.3/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.34.0 h1:S8h21VdVSHC8yfAk0Te8eHU/gkJ+3w2pv7Q/0kooK8I=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.34.0/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E=
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20230705105638-f5ef7c07973b h1:XOBPcVHeDUYIpcag0yI8IYKiBL+5LLL8suysvlavQwI=
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20230705105638-f5ef7c07973b/go.mod h1:E0hYVpZd61fXhzTozkxjiWEy+/yTRxAnr2SIE7k8ZSM=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
Expand Down
89 changes: 89 additions & 0 deletions octopusdeploy/resource_azure_oidc_account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package octopusdeploy

import (
"fmt"
"testing"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
uuid "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccOctopusDeployAzureOpenIDConnectAccountBasic(t *testing.T) {
localName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
prefix := "octopusdeploy_azure_openid_connect." + localName

applicationID := uuid.New()
description := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
name := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
subscriptionID := uuid.New()
tenantedDeploymentMode := core.TenantedDeploymentModeTenantedOrUntenanted
tenantID := uuid.New()

execution_keys := []string{"space"}
health_keys := []string{"target"}
account_keys := []string{"type"}
audience := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)

newDescription := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)

resource.Test(t, resource.TestCase{
CheckDestroy: testAccountCheckDestroy,
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Check: resource.ComposeTestCheckFunc(
testAccountExists(prefix),
resource.TestCheckResourceAttr(prefix, "application_id", applicationID.String()),
resource.TestCheckResourceAttr(prefix, "description", description),
resource.TestCheckResourceAttr(prefix, "name", name),
resource.TestCheckResourceAttr(prefix, "subscription_id", subscriptionID.String()),
resource.TestCheckResourceAttr(prefix, "tenant_id", tenantID.String()),
resource.TestCheckResourceAttr(prefix, "tenanted_deployment_participation", string(tenantedDeploymentMode)),
resource.TestCheckResourceAttr(prefix, "execution_subject_keys", execution_keys[0]),
resource.TestCheckResourceAttr(prefix, "health_subject_keys", health_keys[0]),
resource.TestCheckResourceAttr(prefix, "account_test_subject_keys", account_keys[0]),
resource.TestCheckResourceAttr(prefix, "audience", audience),
),
Config: testAzureOpenIDConnectAccountBasic(localName, name, description, applicationID, tenantID, subscriptionID, tenantedDeploymentMode, execution_keys, health_keys, account_keys, audience),
},
{
Check: resource.ComposeTestCheckFunc(
testAccountExists(prefix),
resource.TestCheckResourceAttr(prefix, "application_id", applicationID.String()),
resource.TestCheckResourceAttr(prefix, "description", newDescription),
resource.TestCheckResourceAttr(prefix, "name", name),
resource.TestCheckResourceAttr(prefix, "subscription_id", subscriptionID.String()),
resource.TestCheckResourceAttr(prefix, "tenant_id", tenantID.String()),
resource.TestCheckResourceAttr(prefix, "tenanted_deployment_participation", string(tenantedDeploymentMode)),
resource.TestCheckResourceAttr(prefix, "execution_subject_keys", execution_keys[0]),
resource.TestCheckResourceAttr(prefix, "health_subject_keys", health_keys[0]),
resource.TestCheckResourceAttr(prefix, "account_test_subject_keys", account_keys[0]),
resource.TestCheckResourceAttr(prefix, "audience", audience),
),
Config: testAzureOpenIDConnectAccountBasic(localName, name, newDescription, applicationID, tenantID, subscriptionID, tenantedDeploymentMode, execution_keys, health_keys, account_keys, audience),
},
},
})
}

func testAzureOpenIDConnectAccountBasic(localName string, name string, description string, applicationID uuid.UUID, tenantID uuid.UUID, subscriptionID uuid.UUID, tenantedDeploymentParticipation core.TenantedDeploymentMode, execution_subject_keys []string, health_subject_keys []string, account_test_subject_keys []string, audience string) string {
return fmt.Sprintf(`resource "octopusdeploy_azure_openid_connect" "%s" {
application_id = "%s"
description = "%s"
name = "%s"
subscription_id = "%s"
tenant_id = "%s"
tenanted_deployment_participation = "%s"
execution_subject_keys = "%s"
health_subject_keys = "%s"
account_test_subject_keys = "%s"
audience = "%s"
}
data "octopusdeploy_accounts" "test" {
ids = [octopusdeploy_azure_openid_connect.%s.id]
}`, localName, applicationID, description, name, subscriptionID, tenantID, tenantedDeploymentParticipation, execution_subject_keys, health_subject_keys, account_test_subject_keys, audience, localName)
}
6 changes: 6 additions & 0 deletions octopusdeploy/schema_azure_oidc_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func expandAzureOpenIDConnectAccount(d *schema.ResourceData) *accounts.AzureOIDC
account.AccountTestSubjectKeys = getSliceFromTerraformTypeList(v)
}

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

return account
}

Expand All @@ -90,6 +94,7 @@ func getAzureOpenIdConnectAccountSchema() map[string]*schema.Schema {
"execution_subject_keys": getSubjectKeysSchema(),
"health_subject_keys": getSubjectKeysSchema(),
"account_test_subject_keys": getSubjectKeysSchema(),
"audience": getOidcAudienceSchema(),
}
}

Expand All @@ -105,6 +110,7 @@ func setAzureOpenIDConnectAccount(ctx context.Context, d *schema.ResourceData, a
d.Set("subscription_id", account.SubscriptionID.String())
d.Set("tenanted_deployment_participation", account.GetTenantedDeploymentMode())
d.Set("tenant_id", account.TenantID.String())
d.Set("audience", account.Audience)

if err := d.Set("environments", account.GetEnvironmentIDs()); err != nil {
return fmt.Errorf("error setting environments: %s", err)
Expand Down
7 changes: 7 additions & 0 deletions octopusdeploy/schema_utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,10 @@ func getSubjectKeysSchema() *schema.Schema {
Elem: &schema.Schema{Type: schema.TypeString},
}
}

func getOidcAudienceSchema() *schema.Schema {
return &schema.Schema{
Optional: true,
Type: schema.TypeString,
}
}

0 comments on commit 5363241

Please sign in to comment.