-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ea9396
commit 0503d4c
Showing
12 changed files
with
350 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package octopusdeploy | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/accounts" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" | ||
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func resourceAmazonWebServicesOpenIDConnectAccount() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceAmazonWebServicesOpenIDConnectAccountCreate, | ||
DeleteContext: resourceAmazonWebServicesOpenIDConnectAccountDelete, | ||
Description: "This resource manages AWS OIDC accounts in Octopus Deploy.", | ||
Importer: getImporter(), | ||
ReadContext: resourceAmazonWebServicesOpenIDConnectAccountRead, | ||
Schema: getAmazonWebServicesOpenIDConnectAccountSchema(), | ||
UpdateContext: resourceAmazonWebServicesOpenIDConnectAccountUpdate, | ||
} | ||
} | ||
|
||
func resourceAmazonWebServicesOpenIDConnectAccountCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
account := expandAmazonWebServicesOpenIDConnectAccount(d) | ||
|
||
log.Printf("[INFO] creating AWS OIDC account") | ||
|
||
client := m.(*client.Client) | ||
createdAccount, err := client.Accounts.Add(account) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if err := setAmazonWebServicesOpenIDConnectAccount(ctx, d, createdAccount.(*accounts.AwsOIDCAccount)); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(createdAccount.GetID()) | ||
|
||
log.Printf("[INFO] AWS OIDC account created (%s)", d.Id()) | ||
return nil | ||
} | ||
|
||
func resourceAmazonWebServicesOpenIDConnectAccountDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
log.Printf("[INFO] deleting AWS OIDC account (%s)", d.Id()) | ||
|
||
client := m.(*client.Client) | ||
if err := client.Accounts.DeleteByID(d.Id()); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId("") | ||
|
||
log.Printf("[INFO] AWS OIDC account deleted") | ||
return nil | ||
} | ||
|
||
func resourceAmazonWebServicesOpenIDConnectAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
log.Printf("[INFO] reading AWS OIDC account (%s)", d.Id()) | ||
|
||
client := m.(*client.Client) | ||
accountResource, err := client.Accounts.GetByID(d.Id()) | ||
if err != nil { | ||
return errors.ProcessApiError(ctx, d, err, "AWS OIDC account") | ||
} | ||
|
||
awsOIDCAccount := accountResource.(*accounts.AwsOIDCAccount) | ||
if err := setAmazonWebServicesOpenIDConnectAccount(ctx, d, awsOIDCAccount); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
log.Printf("[INFO] AWS OIDC account read: %#v", awsOIDCAccount) | ||
return nil | ||
} | ||
|
||
func resourceAmazonWebServicesOpenIDConnectAccountUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
account := expandAmazonWebServicesOpenIDConnectAccount(d) | ||
|
||
log.Printf("[INFO] updating AWS OIDC account: %#v", account) | ||
|
||
client := m.(*client.Client) | ||
updatedAccount, err := client.Accounts.Update(account) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if err := setAmazonWebServicesOpenIDConnectAccount(ctx, d, updatedAccount.(*accounts.AwsOIDCAccount)); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
log.Printf("[INFO] AWS OIDC account updated (%s)", d.Id()) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package octopusdeploy | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccAWSOIDCAccountBasic(t *testing.T) { | ||
localName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha) | ||
prefix := "octopusdeploy_aws_account." + localName | ||
|
||
description := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha) | ||
name := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha) | ||
tenantedDeploymentParticipation := core.TenantedDeploymentModeTenantedOrUntenanted | ||
|
||
roleArn := "arn:aws:iam::sourceAccountId:roleroleName" | ||
sessionDuration := "3600" | ||
executionKeys := []string{"space"} | ||
healthKeys := []string{"target"} | ||
accountKeys := []string{"type"} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
CheckDestroy: testAccountCheckDestroy, | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccountExists(prefix), | ||
resource.TestCheckResourceAttr(prefix, "description", description), | ||
resource.TestCheckResourceAttr(prefix, "name", name), | ||
resource.TestCheckResourceAttr(prefix, "role_arn", roleArn), | ||
resource.TestCheckResourceAttr(prefix, "session_duration", sessionDuration), | ||
resource.TestCheckResourceAttr(prefix, "tenanted_deployment_participation", string(tenantedDeploymentParticipation)), | ||
resource.TestCheckResourceAttr(prefix, "execution_subject_keys", executionKeys[0]), | ||
resource.TestCheckResourceAttr(prefix, "health_subject_keys", healthKeys[0]), | ||
resource.TestCheckResourceAttr(prefix, "account_test_subject_keys", accountKeys[0]), | ||
), | ||
Config: testAwsOIDCAccountBasic(localName, name, description, roleArn, sessionDuration, tenantedDeploymentParticipation, executionKeys, healthKeys, accountKeys), | ||
}, | ||
{ | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccountExists(prefix), | ||
resource.TestCheckResourceAttr(prefix, "description", description), | ||
resource.TestCheckResourceAttr(prefix, "name", name), | ||
resource.TestCheckResourceAttr(prefix, "role_arn", roleArn), | ||
resource.TestCheckResourceAttr(prefix, "session_duration", sessionDuration), | ||
resource.TestCheckResourceAttr(prefix, "tenanted_deployment_participation", string(tenantedDeploymentParticipation)), | ||
resource.TestCheckResourceAttr(prefix, "execution_subject_keys", executionKeys[0]), | ||
resource.TestCheckResourceAttr(prefix, "health_subject_keys", healthKeys[0]), | ||
resource.TestCheckResourceAttr(prefix, "account_test_subject_keys", accountKeys[0]), | ||
), | ||
Config: testAwsOIDCAccountBasic(localName, name, description, roleArn, sessionDuration, tenantedDeploymentParticipation, executionKeys, healthKeys, accountKeys), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAwsOIDCAccountBasic(localName string, name string, description string, roleArn string, sessionDuration string, tenantedDeploymentParticipation core.TenantedDeploymentMode, execution_subject_keys []string, health_subject_keys []string, account_test_subject_keys []string) string { | ||
return fmt.Sprintf(`resource "octopusdeploy_aws_openid_connect_account" "%s" { | ||
description = "%s" | ||
name = "%s" | ||
role_arn = "%s" | ||
tenanted_deployment_participation = "%s" | ||
execution_subject_keys = "%s" | ||
health_subject_keys = "%s" | ||
account_test_subject_keys = "%s" | ||
session_duration = "%s" | ||
} | ||
data "octopusdeploy_accounts" "test" { | ||
ids = [octopusdeploy_aws_openid_connect_account.%s.id] | ||
}`, localName, description, name, roleArn, tenantedDeploymentParticipation, execution_subject_keys, health_subject_keys, account_test_subject_keys, sessionDuration, localName) | ||
} | ||
|
||
func testAwsOIDCAccount(localName string, name string, roleArn string, sessionDuration string) string { | ||
return fmt.Sprintf(`resource "octopusdeploy_aws_openid_connect_account" "%s" { | ||
name = "%s" | ||
role_arn = "%s" | ||
session_duration = "%s" | ||
}`, localName, name, roleArn, sessionDuration) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.