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

artifact registry - promote to ga #12063

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/6240.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```release-note:new-resource
`google_artifact_registry_repository` (ga only)
```
```release-note:new-resource
`google_artifact_registry_repository_iam_policy` (ga only)
```
```release-note:new-resource
`google_artifact_registry_repository_iam_binding` (ga only)
```
```release-note:new-resource
`google_artifact_registry_repository_iam_member` (ga only)
```
74 changes: 74 additions & 0 deletions google/artifact_registry_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// 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 (
"encoding/json"
"fmt"
"time"
)

type ArtifactRegistryOperationWaiter struct {
Config *Config
UserAgent string
Project string
CommonOperationWaiter
}

func (w *ArtifactRegistryOperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
// Returns the proper get.
url := fmt.Sprintf("%s%s", w.Config.ArtifactRegistryBasePath, w.CommonOperationWaiter.Op.Name)

return sendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil)
}

func createArtifactRegistryWaiter(config *Config, op map[string]interface{}, project, activity, userAgent string) (*ArtifactRegistryOperationWaiter, error) {
w := &ArtifactRegistryOperationWaiter{
Config: config,
UserAgent: userAgent,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func artifactRegistryOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
w, err := createArtifactRegistryWaiter(config, op, project, activity, userAgent)
if err != nil {
return err
}
if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func artifactRegistryOperationWaitTime(config *Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil
}
w, err := createArtifactRegistryWaiter(config, op, project, activity, userAgent)
if err != nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeout, config.PollInterval)
}
4 changes: 4 additions & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ type Config struct {
ActiveDirectoryBasePath string
ApigeeBasePath string
AppEngineBasePath string
ArtifactRegistryBasePath string
BigQueryBasePath string
BigqueryConnectionBasePath string
BigqueryDataTransferBasePath string
Expand Down Expand Up @@ -257,6 +258,7 @@ const AccessContextManagerBasePathKey = "AccessContextManager"
const ActiveDirectoryBasePathKey = "ActiveDirectory"
const ApigeeBasePathKey = "Apigee"
const AppEngineBasePathKey = "AppEngine"
const ArtifactRegistryBasePathKey = "ArtifactRegistry"
const BigQueryBasePathKey = "BigQuery"
const BigqueryConnectionBasePathKey = "BigqueryConnection"
const BigqueryDataTransferBasePathKey = "BigqueryDataTransfer"
Expand Down Expand Up @@ -342,6 +344,7 @@ var DefaultBasePaths = map[string]string{
ActiveDirectoryBasePathKey: "https://managedidentities.googleapis.com/v1/",
ApigeeBasePathKey: "https://apigee.googleapis.com/v1/",
AppEngineBasePathKey: "https://appengine.googleapis.com/v1/",
ArtifactRegistryBasePathKey: "https://artifactregistry.googleapis.com/v1/",
BigQueryBasePathKey: "https://bigquery.googleapis.com/bigquery/v2/",
BigqueryConnectionBasePathKey: "https://bigqueryconnection.googleapis.com/v1/",
BigqueryDataTransferBasePathKey: "https://bigquerydatatransfer.googleapis.com/v1/",
Expand Down Expand Up @@ -1189,6 +1192,7 @@ func ConfigureBasePaths(c *Config) {
c.ActiveDirectoryBasePath = DefaultBasePaths[ActiveDirectoryBasePathKey]
c.ApigeeBasePath = DefaultBasePaths[ApigeeBasePathKey]
c.AppEngineBasePath = DefaultBasePaths[AppEngineBasePathKey]
c.ArtifactRegistryBasePath = DefaultBasePaths[ArtifactRegistryBasePathKey]
c.BigQueryBasePath = DefaultBasePaths[BigQueryBasePathKey]
c.BigqueryConnectionBasePath = DefaultBasePaths[BigqueryConnectionBasePathKey]
c.BigqueryDataTransferBasePath = DefaultBasePaths[BigqueryDataTransferBasePathKey]
Expand Down
222 changes: 222 additions & 0 deletions google/iam_artifact_registry_repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// 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 ArtifactRegistryRepositoryIamSchema = map[string]*schema.Schema{
"project": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"location": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"repository": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
}

type ArtifactRegistryRepositoryIamUpdater struct {
project string
location string
repository string
d TerraformResourceData
Config *Config
}

func ArtifactRegistryRepositoryIamUpdaterProducer(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("repository"); ok {
values["repository"] = 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>[^/]+)/repositories/(?P<repository>[^/]+)", "(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<repository>[^/]+)", "(?P<location>[^/]+)/(?P<repository>[^/]+)", "(?P<repository>[^/]+)"}, d, config, d.Get("repository").(string))
if err != nil {
return nil, err
}

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

u := &ArtifactRegistryRepositoryIamUpdater{
project: values["project"],
location: values["location"],
repository: values["repository"],
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("repository", u.GetResourceId()); err != nil {
return nil, fmt.Errorf("Error setting repository: %s", err)
}

return u, nil
}

func ArtifactRegistryRepositoryIdParseFunc(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>[^/]+)/repositories/(?P<repository>[^/]+)", "(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<repository>[^/]+)", "(?P<location>[^/]+)/(?P<repository>[^/]+)", "(?P<repository>[^/]+)"}, d, config, d.Id())
if err != nil {
return err
}

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

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

func (u *ArtifactRegistryRepositoryIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
url, err := u.qualifyRepositoryUrl("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 *ArtifactRegistryRepositoryIamUpdater) 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.qualifyRepositoryUrl("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 *ArtifactRegistryRepositoryIamUpdater) qualifyRepositoryUrl(methodIdentifier string) (string, error) {
urlTemplate := fmt.Sprintf("{{ArtifactRegistryBasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/repositories/%s", u.project, u.location, u.repository), methodIdentifier)
url, err := replaceVars(u.d, u.Config, urlTemplate)
if err != nil {
return "", err
}
return url, nil
}

func (u *ArtifactRegistryRepositoryIamUpdater) GetResourceId() string {
return fmt.Sprintf("projects/%s/locations/%s/repositories/%s", u.project, u.location, u.repository)
}

func (u *ArtifactRegistryRepositoryIamUpdater) GetMutexKey() string {
return fmt.Sprintf("iam-artifactregistry-repository-%s", u.GetResourceId())
}

func (u *ArtifactRegistryRepositoryIamUpdater) DescribeResource() string {
return fmt.Sprintf("artifactregistry repository %q", u.GetResourceId())
}
Loading