forked from hashicorp/terraform-provider-google
-
Notifications
You must be signed in to change notification settings - Fork 1
/
iam_organization.go
66 lines (53 loc) · 1.78 KB
/
iam_organization.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
package google
import (
"fmt"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/cloudresourcemanager/v1"
)
var IamOrganizationSchema = map[string]*schema.Schema{
"org_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
}
type OrganizationIamUpdater struct {
resourceId string
Config *Config
}
func NewOrganizationIamUpdater(d *schema.ResourceData, config *Config) (ResourceIamUpdater, error) {
return &OrganizationIamUpdater{
resourceId: d.Get("org_id").(string),
Config: config,
}, nil
}
func OrgIdParseFunc(d *schema.ResourceData, _ *Config) error {
d.Set("org_id", d.Id())
return nil
}
func (u *OrganizationIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
p, err := u.Config.clientResourceManager.Organizations.GetIamPolicy("organizations/"+u.resourceId, &cloudresourcemanager.GetIamPolicyRequest{}).Do()
if err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
return p, nil
}
func (u *OrganizationIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error {
_, err := u.Config.clientResourceManager.Organizations.SetIamPolicy("organizations/"+u.resourceId, &cloudresourcemanager.SetIamPolicyRequest{
Policy: policy,
}).Do()
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
return nil
}
func (u *OrganizationIamUpdater) GetResourceId() string {
return u.resourceId
}
func (u *OrganizationIamUpdater) GetMutexKey() string {
return fmt.Sprintf("iam-organization-%s", u.resourceId)
}
func (u *OrganizationIamUpdater) DescribeResource() string {
return fmt.Sprintf("organization %q", u.resourceId)
}