-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
9e91f2d
commit 4b7dc8d
Showing
9 changed files
with
926 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
```release-note:new-resource | ||
google_privateca_certificate_authority_iam_policy | ||
``` | ||
```release-note:new-resource | ||
google_privateca_certificate_authority_iam_binding | ||
``` | ||
```release-note:new-resource | ||
google_privateca_certificate_authority_iam_member | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/errwrap" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"google.golang.org/api/cloudresourcemanager/v1" | ||
) | ||
|
||
var PrivatecaCertificateAuthorityIamSchema = map[string]*schema.Schema{ | ||
"certificate_authority": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
DiffSuppressFunc: compareSelfLinkOrResourceName, | ||
}, | ||
} | ||
|
||
type PrivatecaCertificateAuthorityIamUpdater struct { | ||
certificateAuthority string | ||
d *schema.ResourceData | ||
Config *Config | ||
} | ||
|
||
func PrivatecaCertificateAuthorityIamUpdaterProducer(d *schema.ResourceData, config *Config) (ResourceIamUpdater, error) { | ||
values := make(map[string]string) | ||
|
||
if v, ok := d.GetOk("certificate_authority"); ok { | ||
values["certificate_authority"] = v.(string) | ||
} | ||
|
||
// We may have gotten either a long or short name, so attempt to parse long name if possible | ||
m, err := getImportIdQualifiers([]string{"projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/certificateAuthorities/(?P<certificate_authority_id>[^/]+)", "(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<certificate_authority_id>[^/]+)", "(?P<location>[^/]+)/(?P<certificate_authority_id>[^/]+)"}, d, config, d.Get("certificate_authority").(string)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for k, v := range m { | ||
values[k] = v | ||
} | ||
|
||
u := &PrivatecaCertificateAuthorityIamUpdater{ | ||
certificateAuthority: values["certificate_authority"], | ||
d: d, | ||
Config: config, | ||
} | ||
|
||
if err := d.Set("certificate_authority", u.GetResourceId()); err != nil { | ||
return nil, fmt.Errorf("Error setting certificate_authority: %s", err) | ||
} | ||
|
||
return u, nil | ||
} | ||
|
||
func PrivatecaCertificateAuthorityIdParseFunc(d *schema.ResourceData, config *Config) error { | ||
values := make(map[string]string) | ||
|
||
m, err := getImportIdQualifiers([]string{"projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/certificateAuthorities/(?P<certificate_authority_id>[^/]+)", "(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<certificate_authority_id>[^/]+)", "(?P<location>[^/]+)/(?P<certificate_authority_id>[^/]+)"}, d, config, d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for k, v := range m { | ||
values[k] = v | ||
} | ||
|
||
u := &PrivatecaCertificateAuthorityIamUpdater{ | ||
certificateAuthority: values["certificate_authority"], | ||
d: d, | ||
Config: config, | ||
} | ||
if err := d.Set("certificate_authority", u.GetResourceId()); err != nil { | ||
return fmt.Errorf("Error setting certificate_authority: %s", err) | ||
} | ||
d.SetId(u.GetResourceId()) | ||
return nil | ||
} | ||
|
||
func (u *PrivatecaCertificateAuthorityIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) { | ||
url, err := u.qualifyCertificateAuthorityUrl("getIamPolicy") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var obj map[string]interface{} | ||
|
||
userAgent, err := generateUserAgentString(u.d, u.Config.userAgent) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
policy, err := sendRequest(u.Config, "GET", "", url, userAgent, obj) | ||
if err != nil { | ||
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err) | ||
} | ||
|
||
out := &cloudresourcemanager.Policy{} | ||
err = Convert(policy, out) | ||
if err != nil { | ||
return nil, errwrap.Wrapf("Cannot convert a policy to a resource manager policy: {{err}}", err) | ||
} | ||
|
||
return out, nil | ||
} | ||
|
||
func (u *PrivatecaCertificateAuthorityIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error { | ||
json, err := ConvertToMap(policy) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
obj := make(map[string]interface{}) | ||
obj["policy"] = json | ||
|
||
url, err := u.qualifyCertificateAuthorityUrl("setIamPolicy") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
userAgent, err := generateUserAgentString(u.d, u.Config.userAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = sendRequestWithTimeout(u.Config, "POST", "", url, userAgent, obj, u.d.Timeout(schema.TimeoutCreate)) | ||
if err != nil { | ||
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (u *PrivatecaCertificateAuthorityIamUpdater) qualifyCertificateAuthorityUrl(methodIdentifier string) (string, error) { | ||
urlTemplate := fmt.Sprintf("{{PrivatecaBasePath}}%s:%s", fmt.Sprintf("%s", u.certificateAuthority), methodIdentifier) | ||
url, err := replaceVars(u.d, u.Config, urlTemplate) | ||
if err != nil { | ||
return "", err | ||
} | ||
return url, nil | ||
} | ||
|
||
func (u *PrivatecaCertificateAuthorityIamUpdater) GetResourceId() string { | ||
return fmt.Sprintf("%s", u.certificateAuthority) | ||
} | ||
|
||
func (u *PrivatecaCertificateAuthorityIamUpdater) GetMutexKey() string { | ||
return fmt.Sprintf("iam-privateca-certificateauthority-%s", u.GetResourceId()) | ||
} | ||
|
||
func (u *PrivatecaCertificateAuthorityIamUpdater) DescribeResource() string { | ||
return fmt.Sprintf("privateca certificateauthority %q", u.GetResourceId()) | ||
} |
Oops, something went wrong.