Skip to content

Commit

Permalink
Updated formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jbristowe committed Nov 6, 2020
1 parent adade46 commit 0c739fd
Showing 1 changed file with 22 additions and 32 deletions.
54 changes: 22 additions & 32 deletions octopusdeploy/resource_aws_account.go
Expand Up @@ -8,28 +8,28 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceAmazonWebServicesAccount() *schema.Resource {
func resourceAWSAccount() *schema.Resource {
validateSchema()
schemaMap := getCommonAccountsSchema()
schemaMap[constAccessKey] = &schema.Schema{
resourceAWSAccountSchema := getCommonAccountsSchema()
resourceAWSAccountSchema[constAccessKey] = &schema.Schema{
Type: schema.TypeString,
Required: true,
}
schemaMap[constSecretKey] = &schema.Schema{
resourceAWSAccountSchema[constSecretKey] = &schema.Schema{
Type: schema.TypeString,
Required: true,
Sensitive: true,
}
return &schema.Resource{
CreateContext: resourceAmazonWebServicesAccountCreate,
CreateContext: resourceAWSAccountCreate,
DeleteContext: resourceAccountDeleteCommon,
ReadContext: resourceAmazonWebServicesAccountRead,
UpdateContext: resourceAmazonWebServicesAccountUpdate,
Schema: schemaMap,
ReadContext: resourceAWSAccountRead,
Schema: resourceAWSAccountSchema,
UpdateContext: resourceAWSAccountUpdate,
}
}

func resourceAmazonWebServicesAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceAWSAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*octopusdeploy.Client)
accountResource, err := client.Accounts.GetByID(d.Id())
if err != nil {
Expand All @@ -42,24 +42,12 @@ func resourceAmazonWebServicesAccountRead(ctx context.Context, d *schema.Resourc
}

account := accountResource.(*octopusdeploy.AmazonWebServicesAccount)

d.Set(constAccessKey, account.AccessKey)
d.Set(constDescription, account.Description)
d.Set(constEnvironments, account.EnvironmentIDs)
d.Set(constName, account.GetName())
d.Set(constTenantedDeploymentParticipation, account.TenantedDeploymentMode)
d.Set(constTenants, account.TenantIDs)
d.Set(constTenantTags, account.TenantTags)

// TODO: determine what to do here...
// d.Set(constSecretKey, account.SecretKey)

d.SetId(account.GetID())
flattenAWSAccount(ctx, d, account)

return nil
}

func buildAmazonWebServicesAccountResource(d *schema.ResourceData) (*octopusdeploy.AmazonWebServicesAccount, error) {
func buildAWSAccountResource(d *schema.ResourceData) (*octopusdeploy.AmazonWebServicesAccount, error) {
name := d.Get(constName).(string)
accessKey := d.Get(constAccessKey).(string)
password := d.Get(constSecretKey).(string)
Expand All @@ -85,37 +73,39 @@ func buildAmazonWebServicesAccountResource(d *schema.ResourceData) (*octopusdepl
return account, nil
}

func resourceAmazonWebServicesAccountCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
amazonWebServicesAccount, err := buildAmazonWebServicesAccountResource(d)
func resourceAWSAccountCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
account, err := buildAWSAccountResource(d)
if err != nil {
return diag.FromErr(err)
}

client := m.(*octopusdeploy.Client)
account, err := client.Accounts.Add(amazonWebServicesAccount)
createdAccount, err := client.Accounts.Add(account)
if err != nil {
return diag.FromErr(err)
}

d.SetId(account.GetID())
account = createdAccount.(*octopusdeploy.AmazonWebServicesAccount)
flattenAWSAccount(ctx, d, account)

return nil
}

func resourceAmazonWebServicesAccountUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
amazonWebServicesAccount, err := buildAmazonWebServicesAccountResource(d)
func resourceAWSAccountUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
account, err := buildAWSAccountResource(d)
if err != nil {
return diag.FromErr(err)
}
amazonWebServicesAccount.ID = d.Id()
account.ID = d.Id()

client := m.(*octopusdeploy.Client)
account, err := client.Accounts.Update(amazonWebServicesAccount)
updatedAccount, err := client.Accounts.Update(account)
if err != nil {
return diag.FromErr(err)
}

d.SetId(account.GetID())
account = updatedAccount.(*octopusdeploy.AmazonWebServicesAccount)
flattenAWSAccount(ctx, d, account)

return nil
}

0 comments on commit 0c739fd

Please sign in to comment.