-
Notifications
You must be signed in to change notification settings - Fork 65
/
schema_amazon_web_services_account.go
94 lines (77 loc) · 2.94 KB
/
schema_amazon_web_services_account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package octopusdeploy
import (
"context"
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func expandAmazonWebServicesAccount(d *schema.ResourceData) *octopusdeploy.AmazonWebServicesAccount {
name := d.Get("name").(string)
accessKey := d.Get("access_key").(string)
secretKey := octopusdeploy.NewSensitiveValue(d.Get("secret_key").(string))
account, _ := octopusdeploy.NewAmazonWebServicesAccount(name, accessKey, secretKey)
account.ID = d.Id()
if v, ok := d.GetOk("description"); ok {
account.Description = v.(string)
}
if v, ok := d.GetOk("environments"); ok {
account.EnvironmentIDs = getSliceFromTerraformTypeList(v)
}
if v, ok := d.GetOk("space_id"); ok {
account.SpaceID = v.(string)
}
if v, ok := d.GetOk("tenanted_deployment_participation"); ok {
account.TenantedDeploymentMode = octopusdeploy.TenantedDeploymentMode(v.(string))
}
if v, ok := d.GetOk("tenant_tags"); ok {
account.TenantTags = getSliceFromTerraformTypeList(v)
}
if v, ok := d.GetOk("tenants"); ok {
account.TenantIDs = getSliceFromTerraformTypeList(v)
}
return account
}
func getAmazonWebServicesAccountSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"access_key": {
Description: "The access key associated with this AWS account.",
Required: true,
Type: schema.TypeString,
},
"description": {
Description: "A user-friendly description of this AWS account.",
Optional: true,
Type: schema.TypeString,
},
"environments": getEnvironmentsSchema(),
"name": {
Description: "The name of this AWS account.",
Required: true,
Type: schema.TypeString,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 200)),
},
"secret_key": getSecretKeySchema(true),
"space_id": getSpaceIDSchema(),
"tenanted_deployment_participation": getTenantedDeploymentSchema(),
"tenants": getTenantsSchema(),
"tenant_tags": getTenantTagsSchema(),
}
}
func setAmazonWebServicesAccount(ctx context.Context, d *schema.ResourceData, account *octopusdeploy.AmazonWebServicesAccount) error {
d.Set("access_key", account.AccessKey)
d.Set("description", account.GetDescription())
d.Set("name", account.GetName())
d.Set("space_id", account.GetSpaceID())
d.Set("tenanted_deployment_participation", account.GetTenantedDeploymentMode())
if err := d.Set("environments", account.GetEnvironmentIDs()); err != nil {
return fmt.Errorf("error setting environments: %s", err)
}
if err := d.Set("tenants", account.GetTenantIDs()); err != nil {
return fmt.Errorf("error setting tenants: %s", err)
}
if err := d.Set("tenant_tags", account.GetTenantTags()); err != nil {
return fmt.Errorf("error setting tenant_tags: %s", err)
}
return nil
}