mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 17:16: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
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/hashicorp/errwrap"
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
"google.golang.org/api/cloudresourcemanager/v1"
|
|
)
|
|
|
|
var IamProjectSchema = map[string]*schema.Schema{
|
|
"project": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
ForceNew: true,
|
|
},
|
|
}
|
|
|
|
type ProjectIamUpdater struct {
|
|
resourceId string
|
|
Config *Config
|
|
}
|
|
|
|
func NewProjectIamUpdater(d *schema.ResourceData, config *Config) (ResourceIamUpdater, error) {
|
|
pid, err := getProject(d, config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &ProjectIamUpdater{
|
|
resourceId: pid,
|
|
Config: config,
|
|
}, nil
|
|
}
|
|
|
|
func ProjectIdParseFunc(d *schema.ResourceData, _ *Config) error {
|
|
d.Set("project", d.Id())
|
|
return nil
|
|
}
|
|
|
|
func (u *ProjectIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
|
|
p, err := u.Config.clientResourceManager.Projects.GetIamPolicy(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 *ProjectIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error {
|
|
_, err := u.Config.clientResourceManager.Projects.SetIamPolicy(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 *ProjectIamUpdater) GetResourceId() string {
|
|
return u.resourceId
|
|
}
|
|
|
|
func (u *ProjectIamUpdater) GetMutexKey() string {
|
|
return fmt.Sprintf("iam-project-%s", u.resourceId)
|
|
}
|
|
|
|
func (u *ProjectIamUpdater) DescribeResource() string {
|
|
return fmt.Sprintf("project %q", u.resourceId)
|
|
}
|