Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private ca ga #9480

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changelog/4919.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```release-note:new-resource
google_privateca_certificate
```
```release-note:new-resource
google_privateca_certificate_authority
```
```release-note:new-resource
google_privateca_ca_pool
```
```release-note:breaking-change
privateca: existing beta resources will no longer function
```
4 changes: 4 additions & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type Config struct {
NotebooksBasePath string
OSConfigBasePath string
OSLoginBasePath string
PrivatecaBasePath string
PubsubBasePath string
PubsubLiteBasePath string
RedisBasePath string
Expand Down Expand Up @@ -211,6 +212,7 @@ const NetworkManagementBasePathKey = "NetworkManagement"
const NotebooksBasePathKey = "Notebooks"
const OSConfigBasePathKey = "OSConfig"
const OSLoginBasePathKey = "OSLogin"
const PrivatecaBasePathKey = "Privateca"
const PubsubBasePathKey = "Pubsub"
const PubsubLiteBasePathKey = "PubsubLite"
const RedisBasePathKey = "Redis"
Expand Down Expand Up @@ -290,6 +292,7 @@ var DefaultBasePaths = map[string]string{
NotebooksBasePathKey: "https://notebooks.googleapis.com/v1/",
OSConfigBasePathKey: "https://osconfig.googleapis.com/v1/",
OSLoginBasePathKey: "https://oslogin.googleapis.com/v1/",
PrivatecaBasePathKey: "https://privateca.googleapis.com/v1/",
PubsubBasePathKey: "https://pubsub.googleapis.com/v1/",
PubsubLiteBasePathKey: "https://{{region}}-pubsublite.googleapis.com/v1/admin/",
RedisBasePathKey: "https://redis.googleapis.com/v1/",
Expand Down Expand Up @@ -1122,6 +1125,7 @@ func ConfigureBasePaths(c *Config) {
c.NotebooksBasePath = DefaultBasePaths[NotebooksBasePathKey]
c.OSConfigBasePath = DefaultBasePaths[OSConfigBasePathKey]
c.OSLoginBasePath = DefaultBasePaths[OSLoginBasePathKey]
c.PrivatecaBasePath = DefaultBasePaths[PrivatecaBasePathKey]
c.PubsubBasePath = DefaultBasePaths[PubsubBasePathKey]
c.PubsubLiteBasePath = DefaultBasePaths[PubsubLiteBasePathKey]
c.RedisBasePath = DefaultBasePaths[RedisBasePathKey]
Expand Down
222 changes: 222 additions & 0 deletions google/iam_privateca_ca_pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
// ----------------------------------------------------------------------------
//
// *** 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 PrivatecaCaPoolIamSchema = map[string]*schema.Schema{
"project": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"location": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"ca_pool": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
}

type PrivatecaCaPoolIamUpdater struct {
project string
location string
caPool string
d TerraformResourceData
Config *Config
}

func PrivatecaCaPoolIamUpdaterProducer(d TerraformResourceData, config *Config) (ResourceIamUpdater, error) {
values := make(map[string]string)

project, _ := getProject(d, config)
if project != "" {
if err := d.Set("project", project); err != nil {
return nil, fmt.Errorf("Error setting project: %s", err)
}
}
values["project"] = project
location, _ := getLocation(d, config)
if location != "" {
if err := d.Set("location", location); err != nil {
return nil, fmt.Errorf("Error setting location: %s", err)
}
}
values["location"] = location
if v, ok := d.GetOk("ca_pool"); ok {
values["ca_pool"] = 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>[^/]+)/caPools/(?P<ca_pool>[^/]+)", "(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<ca_pool>[^/]+)", "(?P<location>[^/]+)/(?P<ca_pool>[^/]+)"}, d, config, d.Get("ca_pool").(string))
if err != nil {
return nil, err
}

for k, v := range m {
values[k] = v
}

u := &PrivatecaCaPoolIamUpdater{
project: values["project"],
location: values["location"],
caPool: values["ca_pool"],
d: d,
Config: config,
}

if err := d.Set("project", u.project); err != nil {
return nil, fmt.Errorf("Error setting project: %s", err)
}
if err := d.Set("location", u.location); err != nil {
return nil, fmt.Errorf("Error setting location: %s", err)
}
if err := d.Set("ca_pool", u.GetResourceId()); err != nil {
return nil, fmt.Errorf("Error setting ca_pool: %s", err)
}

return u, nil
}

func PrivatecaCaPoolIdParseFunc(d *schema.ResourceData, config *Config) error {
values := make(map[string]string)

project, _ := getProject(d, config)
if project != "" {
values["project"] = project
}

location, _ := getLocation(d, config)
if location != "" {
values["location"] = location
}

m, err := getImportIdQualifiers([]string{"projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/caPools/(?P<ca_pool>[^/]+)", "(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<ca_pool>[^/]+)", "(?P<location>[^/]+)/(?P<ca_pool>[^/]+)"}, d, config, d.Id())
if err != nil {
return err
}

for k, v := range m {
values[k] = v
}

u := &PrivatecaCaPoolIamUpdater{
project: values["project"],
location: values["location"],
caPool: values["ca_pool"],
d: d,
Config: config,
}
if err := d.Set("ca_pool", u.GetResourceId()); err != nil {
return fmt.Errorf("Error setting ca_pool: %s", err)
}
d.SetId(u.GetResourceId())
return nil
}

func (u *PrivatecaCaPoolIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
url, err := u.qualifyCaPoolUrl("getIamPolicy")
if err != nil {
return nil, err
}

project, err := getProject(u.d, u.Config)
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", project, 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 *PrivatecaCaPoolIamUpdater) 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.qualifyCaPoolUrl("setIamPolicy")
if err != nil {
return err
}
project, err := getProject(u.d, u.Config)
if err != nil {
return err
}

userAgent, err := generateUserAgentString(u.d, u.Config.userAgent)
if err != nil {
return err
}

_, err = sendRequestWithTimeout(u.Config, "POST", project, 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 *PrivatecaCaPoolIamUpdater) qualifyCaPoolUrl(methodIdentifier string) (string, error) {
urlTemplate := fmt.Sprintf("{{PrivatecaBasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/caPools/%s", u.project, u.location, u.caPool), methodIdentifier)
url, err := replaceVars(u.d, u.Config, urlTemplate)
if err != nil {
return "", err
}
return url, nil
}

func (u *PrivatecaCaPoolIamUpdater) GetResourceId() string {
return fmt.Sprintf("projects/%s/locations/%s/caPools/%s", u.project, u.location, u.caPool)
}

func (u *PrivatecaCaPoolIamUpdater) GetMutexKey() string {
return fmt.Sprintf("iam-privateca-capool-%s", u.GetResourceId())
}

func (u *PrivatecaCaPoolIamUpdater) DescribeResource() string {
return fmt.Sprintf("privateca capool %q", u.GetResourceId())
}
Loading