mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 09:36:44 +00:00
![emily](/assets/img/avatar_default.png)
* add util for handling wrapped/raw google api errors * add 404 error handling to shared iam files * fix errwrap calls in iam files * fix import * remove newlines, clear ID for removed state in iam binding
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
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)
|
|
}
|