Skip to content

Commit e5f609d

Browse files
artifact registry - promote to ga (#6240) (#12063)
Signed-off-by: Modular Magician <[email protected]>
1 parent bd7c042 commit e5f609d

11 files changed

+1379
-62
lines changed

.changelog/6240.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```release-note:new-resource
2+
`google_artifact_registry_repository` (ga only)
3+
```
4+
```release-note:new-resource
5+
`google_artifact_registry_repository_iam_policy` (ga only)
6+
```
7+
```release-note:new-resource
8+
`google_artifact_registry_repository_iam_binding` (ga only)
9+
```
10+
```release-note:new-resource
11+
`google_artifact_registry_repository_iam_member` (ga only)
12+
```

google/artifact_registry_operation.go

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
package google
15+
16+
import (
17+
"encoding/json"
18+
"fmt"
19+
"time"
20+
)
21+
22+
type ArtifactRegistryOperationWaiter struct {
23+
Config *Config
24+
UserAgent string
25+
Project string
26+
CommonOperationWaiter
27+
}
28+
29+
func (w *ArtifactRegistryOperationWaiter) QueryOp() (interface{}, error) {
30+
if w == nil {
31+
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
32+
}
33+
// Returns the proper get.
34+
url := fmt.Sprintf("%s%s", w.Config.ArtifactRegistryBasePath, w.CommonOperationWaiter.Op.Name)
35+
36+
return sendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil)
37+
}
38+
39+
func createArtifactRegistryWaiter(config *Config, op map[string]interface{}, project, activity, userAgent string) (*ArtifactRegistryOperationWaiter, error) {
40+
w := &ArtifactRegistryOperationWaiter{
41+
Config: config,
42+
UserAgent: userAgent,
43+
Project: project,
44+
}
45+
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
46+
return nil, err
47+
}
48+
return w, nil
49+
}
50+
51+
// nolint: deadcode,unused
52+
func artifactRegistryOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
53+
w, err := createArtifactRegistryWaiter(config, op, project, activity, userAgent)
54+
if err != nil {
55+
return err
56+
}
57+
if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil {
58+
return err
59+
}
60+
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
61+
}
62+
63+
func artifactRegistryOperationWaitTime(config *Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
64+
if val, ok := op["name"]; !ok || val == "" {
65+
// This was a synchronous call - there is no operation to wait for.
66+
return nil
67+
}
68+
w, err := createArtifactRegistryWaiter(config, op, project, activity, userAgent)
69+
if err != nil {
70+
// If w is nil, the op was synchronous.
71+
return err
72+
}
73+
return OperationWait(w, activity, timeout, config.PollInterval)
74+
}

google/config.go

+4
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ type Config struct {
166166
ActiveDirectoryBasePath string
167167
ApigeeBasePath string
168168
AppEngineBasePath string
169+
ArtifactRegistryBasePath string
169170
BigQueryBasePath string
170171
BigqueryConnectionBasePath string
171172
BigqueryDataTransferBasePath string
@@ -257,6 +258,7 @@ const AccessContextManagerBasePathKey = "AccessContextManager"
257258
const ActiveDirectoryBasePathKey = "ActiveDirectory"
258259
const ApigeeBasePathKey = "Apigee"
259260
const AppEngineBasePathKey = "AppEngine"
261+
const ArtifactRegistryBasePathKey = "ArtifactRegistry"
260262
const BigQueryBasePathKey = "BigQuery"
261263
const BigqueryConnectionBasePathKey = "BigqueryConnection"
262264
const BigqueryDataTransferBasePathKey = "BigqueryDataTransfer"
@@ -342,6 +344,7 @@ var DefaultBasePaths = map[string]string{
342344
ActiveDirectoryBasePathKey: "https://managedidentities.googleapis.com/v1/",
343345
ApigeeBasePathKey: "https://apigee.googleapis.com/v1/",
344346
AppEngineBasePathKey: "https://appengine.googleapis.com/v1/",
347+
ArtifactRegistryBasePathKey: "https://artifactregistry.googleapis.com/v1/",
345348
BigQueryBasePathKey: "https://bigquery.googleapis.com/bigquery/v2/",
346349
BigqueryConnectionBasePathKey: "https://bigqueryconnection.googleapis.com/v1/",
347350
BigqueryDataTransferBasePathKey: "https://bigquerydatatransfer.googleapis.com/v1/",
@@ -1189,6 +1192,7 @@ func ConfigureBasePaths(c *Config) {
11891192
c.ActiveDirectoryBasePath = DefaultBasePaths[ActiveDirectoryBasePathKey]
11901193
c.ApigeeBasePath = DefaultBasePaths[ApigeeBasePathKey]
11911194
c.AppEngineBasePath = DefaultBasePaths[AppEngineBasePathKey]
1195+
c.ArtifactRegistryBasePath = DefaultBasePaths[ArtifactRegistryBasePathKey]
11921196
c.BigQueryBasePath = DefaultBasePaths[BigQueryBasePathKey]
11931197
c.BigqueryConnectionBasePath = DefaultBasePaths[BigqueryConnectionBasePathKey]
11941198
c.BigqueryDataTransferBasePath = DefaultBasePaths[BigqueryDataTransferBasePathKey]
+222
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
package google
15+
16+
import (
17+
"fmt"
18+
19+
"github.com/hashicorp/errwrap"
20+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
21+
"google.golang.org/api/cloudresourcemanager/v1"
22+
)
23+
24+
var ArtifactRegistryRepositoryIamSchema = map[string]*schema.Schema{
25+
"project": {
26+
Type: schema.TypeString,
27+
Computed: true,
28+
Optional: true,
29+
ForceNew: true,
30+
},
31+
"location": {
32+
Type: schema.TypeString,
33+
Computed: true,
34+
Optional: true,
35+
ForceNew: true,
36+
},
37+
"repository": {
38+
Type: schema.TypeString,
39+
Required: true,
40+
ForceNew: true,
41+
DiffSuppressFunc: compareSelfLinkOrResourceName,
42+
},
43+
}
44+
45+
type ArtifactRegistryRepositoryIamUpdater struct {
46+
project string
47+
location string
48+
repository string
49+
d TerraformResourceData
50+
Config *Config
51+
}
52+
53+
func ArtifactRegistryRepositoryIamUpdaterProducer(d TerraformResourceData, config *Config) (ResourceIamUpdater, error) {
54+
values := make(map[string]string)
55+
56+
project, _ := getProject(d, config)
57+
if project != "" {
58+
if err := d.Set("project", project); err != nil {
59+
return nil, fmt.Errorf("Error setting project: %s", err)
60+
}
61+
}
62+
values["project"] = project
63+
location, _ := getLocation(d, config)
64+
if location != "" {
65+
if err := d.Set("location", location); err != nil {
66+
return nil, fmt.Errorf("Error setting location: %s", err)
67+
}
68+
}
69+
values["location"] = location
70+
if v, ok := d.GetOk("repository"); ok {
71+
values["repository"] = v.(string)
72+
}
73+
74+
// We may have gotten either a long or short name, so attempt to parse long name if possible
75+
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))
76+
if err != nil {
77+
return nil, err
78+
}
79+
80+
for k, v := range m {
81+
values[k] = v
82+
}
83+
84+
u := &ArtifactRegistryRepositoryIamUpdater{
85+
project: values["project"],
86+
location: values["location"],
87+
repository: values["repository"],
88+
d: d,
89+
Config: config,
90+
}
91+
92+
if err := d.Set("project", u.project); err != nil {
93+
return nil, fmt.Errorf("Error setting project: %s", err)
94+
}
95+
if err := d.Set("location", u.location); err != nil {
96+
return nil, fmt.Errorf("Error setting location: %s", err)
97+
}
98+
if err := d.Set("repository", u.GetResourceId()); err != nil {
99+
return nil, fmt.Errorf("Error setting repository: %s", err)
100+
}
101+
102+
return u, nil
103+
}
104+
105+
func ArtifactRegistryRepositoryIdParseFunc(d *schema.ResourceData, config *Config) error {
106+
values := make(map[string]string)
107+
108+
project, _ := getProject(d, config)
109+
if project != "" {
110+
values["project"] = project
111+
}
112+
113+
location, _ := getLocation(d, config)
114+
if location != "" {
115+
values["location"] = location
116+
}
117+
118+
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())
119+
if err != nil {
120+
return err
121+
}
122+
123+
for k, v := range m {
124+
values[k] = v
125+
}
126+
127+
u := &ArtifactRegistryRepositoryIamUpdater{
128+
project: values["project"],
129+
location: values["location"],
130+
repository: values["repository"],
131+
d: d,
132+
Config: config,
133+
}
134+
if err := d.Set("repository", u.GetResourceId()); err != nil {
135+
return fmt.Errorf("Error setting repository: %s", err)
136+
}
137+
d.SetId(u.GetResourceId())
138+
return nil
139+
}
140+
141+
func (u *ArtifactRegistryRepositoryIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
142+
url, err := u.qualifyRepositoryUrl("getIamPolicy")
143+
if err != nil {
144+
return nil, err
145+
}
146+
147+
project, err := getProject(u.d, u.Config)
148+
if err != nil {
149+
return nil, err
150+
}
151+
var obj map[string]interface{}
152+
153+
userAgent, err := generateUserAgentString(u.d, u.Config.userAgent)
154+
if err != nil {
155+
return nil, err
156+
}
157+
158+
policy, err := sendRequest(u.Config, "GET", project, url, userAgent, obj)
159+
if err != nil {
160+
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
161+
}
162+
163+
out := &cloudresourcemanager.Policy{}
164+
err = Convert(policy, out)
165+
if err != nil {
166+
return nil, errwrap.Wrapf("Cannot convert a policy to a resource manager policy: {{err}}", err)
167+
}
168+
169+
return out, nil
170+
}
171+
172+
func (u *ArtifactRegistryRepositoryIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error {
173+
json, err := ConvertToMap(policy)
174+
if err != nil {
175+
return err
176+
}
177+
178+
obj := make(map[string]interface{})
179+
obj["policy"] = json
180+
181+
url, err := u.qualifyRepositoryUrl("setIamPolicy")
182+
if err != nil {
183+
return err
184+
}
185+
project, err := getProject(u.d, u.Config)
186+
if err != nil {
187+
return err
188+
}
189+
190+
userAgent, err := generateUserAgentString(u.d, u.Config.userAgent)
191+
if err != nil {
192+
return err
193+
}
194+
195+
_, err = sendRequestWithTimeout(u.Config, "POST", project, url, userAgent, obj, u.d.Timeout(schema.TimeoutCreate))
196+
if err != nil {
197+
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
198+
}
199+
200+
return nil
201+
}
202+
203+
func (u *ArtifactRegistryRepositoryIamUpdater) qualifyRepositoryUrl(methodIdentifier string) (string, error) {
204+
urlTemplate := fmt.Sprintf("{{ArtifactRegistryBasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/repositories/%s", u.project, u.location, u.repository), methodIdentifier)
205+
url, err := replaceVars(u.d, u.Config, urlTemplate)
206+
if err != nil {
207+
return "", err
208+
}
209+
return url, nil
210+
}
211+
212+
func (u *ArtifactRegistryRepositoryIamUpdater) GetResourceId() string {
213+
return fmt.Sprintf("projects/%s/locations/%s/repositories/%s", u.project, u.location, u.repository)
214+
}
215+
216+
func (u *ArtifactRegistryRepositoryIamUpdater) GetMutexKey() string {
217+
return fmt.Sprintf("iam-artifactregistry-repository-%s", u.GetResourceId())
218+
}
219+
220+
func (u *ArtifactRegistryRepositoryIamUpdater) DescribeResource() string {
221+
return fmt.Sprintf("artifactregistry repository %q", u.GetResourceId())
222+
}

0 commit comments

Comments
 (0)