forked from cnicolov/terraform-provider-spotinstadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_account_aws_link.go
82 lines (67 loc) · 2.08 KB
/
resource_account_aws_link.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
package main
import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/kinvey/terraform-provider-spotinstadmin/services/accounts"
)
func resourceAccountAWSLink() *schema.Resource {
return &schema.Resource{
Create: resourceAccountAWSLinkCreate,
Read: resourceAccountAWSLinkRead,
Update: resourceAccountAWSLinkUpdate,
Delete: resourceAccountAWSLinkDelete,
Schema: map[string]*schema.Schema{
linkAccountResourceAccountIDAttrKey: {
Type: schema.TypeString,
Description: "Account ID to link",
Required: true,
},
linkAccountResourceRoleArnAttrKey: {
Type: schema.TypeString,
Description: "AWS Role arn to assume",
Required: true,
},
linkAccountResourceProviderExternalIdAttrKey: {
Type: schema.TypeString,
Description: "AWS Provider External ID",
Computed: true,
},
linkAccountResourceOrganizationIdAttrKey: {
Type: schema.TypeString,
Description: "Organization ID",
Computed: true,
},
},
}
}
func resourceAccountAWSLinkCreate(d *schema.ResourceData, m interface{}) error {
accountsService := m.(*Meta).accountsService
accountID := d.Get(linkAccountResourceAccountIDAttrKey).(string)
iamRole := d.Get(linkAccountResourceRoleArnAttrKey).(string)
err := accountsService.LinkAWSAccount(accountID, iamRole)
if err != nil {
return err
}
d.SetId(accountID)
return resourceAccountAWSLinkRead(d, m)
}
func resourceAccountAWSLinkRead(d *schema.ResourceData, m interface{}) error {
accountsService := m.(*Meta).accountsService
obj, err := accountsService.Get(d.Id())
if err != nil {
if accounts.IsAccountNotFoundErr(err) {
d.SetId("")
return nil
}
return err
}
d.SetId(obj.ID)
d.Set(linkAccountResourceOrganizationIdAttrKey, obj.OrganizationID)
d.Set(linkAccountResourceProviderExternalIdAttrKey, obj.ProviderExternalID)
return nil
}
func resourceAccountAWSLinkUpdate(d *schema.ResourceData, m interface{}) error {
return resourceAccountAWSLinkRead(d, m)
}
func resourceAccountAWSLinkDelete(d *schema.ResourceData, m interface{}) error {
return nil
}