Skip to content

Commit 8bc5438

Browse files
Move handwritten resources to the service packages (#8147) (#5791)
* Move handwritten resources to the service packages * Fix import path Signed-off-by: Modular Magician <[email protected]>
1 parent 78d1ab3 commit 8bc5438

File tree

95 files changed

+3109
-2864
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+3109
-2864
lines changed

.changelog/8147.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google-beta/data_source_storage_object_signed_url_test.go

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,103 +5,16 @@ package google
55
import (
66
"testing"
77

8-
"bytes"
9-
"encoding/base64"
108
"fmt"
119
"io/ioutil"
1210
"net/http"
13-
"net/url"
1411

1512
"github.com/hashicorp/go-cleanhttp"
1613
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1714
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1815
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
19-
"golang.org/x/oauth2/google"
2016
)
2117

22-
const fakeCredentials = `{
23-
"type": "service_account",
24-
"project_id": "gcp-project",
25-
"private_key_id": "29a54056cee3d6886d9e8515a959af538ab5add9",
26-
"private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAsGHDAdHZfi81LgVeeMHXYLgNDpcFYhoBykYtTDdNyA5AixID\n8JdKlCmZ6qLNnZrbs4JlBJfmzw6rjUC5bVBFg5NwYVBu3+3Msa4rgLsTGsjPH9rt\nC+QFnFhcmzg3zz8eeXBqJdhw7wmn1Xa9SsC3h6YWveBk98ecyE7yGe8J8xGphjk7\nEQ/KBmRK/EJD0ZwuYW1W4Bv5f5fca7qvi9rCprEmL8//uy0qCwoJj2jU3zc5p72M\npkSZb1XlYxxTEo/h9WCEvWS9pGhy6fJ0sA2RsBHqU4Y5O7MJEei9yu5fVSZUi05f\n/ggfUID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aqWxTHyTii2+BHQ+OKEwq6kQA3deSpy6\n1jz1fwKBgQDLqbdq5FA63PWqApfNVykXukg9MASIcg/0fjADFaHTPDvJjhFutxRP\nppI5Q95P12CQ/eRBZKJnRlkhkL8tfPaWPzzOpCTjID7avRhx2oLmstmYuXx0HluE\ncqXLbAV9WDpIJ3Bpa/S8tWujWhLDmixn2JeAdurWS+naH9U9e4I6Rw==\n-----END RSA PRIVATE KEY-----\n",
27-
"client_email": "[email protected]",
28-
"client_id": "103198861025845558729",
29-
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
30-
"token_uri": "https://accounts.google.com/o/oauth2/token",
31-
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
32-
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/user%40gcp-project.iam.gserviceaccount.com"
33-
}
34-
`
35-
36-
// The following values are derived from the output of the `gsutil signurl` command.
37-
// i.e.
38-
// gsutil signurl fake_creds.json gs://tf-test-bucket-6159205297736845881/path/to/file
39-
// URL HTTP Method Expiration Signed URL
40-
// gs://tf-test-bucket-6159205297736845881/path/to/file GET 2016-08-12 14:03:30 https://storage.googleapis.com/tf-test-bucket-6159205297736845881/path/to/[email protected]&Expires=1470967410&Signature=JJvE2Jc%2BeoagyS1qRACKBGUkgLkKjw7cGymHhtB4IzzN3nbXDqr0acRWGy0%2BEpZ3HYNDalEYsK0lR9Q0WCgty5I0JKmPIuo9hOYa1xTNH%2B22xiWsekxGV%2FcA9FXgWpi%2BFt7fBmMk4dhDe%2BuuYc7N79hd0FYuSBNW1Wp32Bluoe4SNkNAB%2BuIDd9KqPzqs09UAbBoz2y4WxXOQnRyR8GAfb8B%2FDtv62gYjtmp%2F6%2Fyr6xj7byWKZdQt8kEftQLTQmP%2F17Efjp6p%2BXo71Q0F9IhAFiqWfp3Ij8hHDSebLcVb2ULXyHNNQpHBOhFgALrFW3I6Uc3WciLEOsBS9Ej3EGdTg%3D%3D
41-
42-
const testUrlPath = "/tf-test-bucket-6159205297736845881/path/to/file"
43-
const testUrlExpires = 1470967410
44-
const testUrlExpectedSignatureBase64Encoded = "JJvE2Jc%2BeoagyS1qRACKBGUkgLkKjw7cGymHhtB4IzzN3nbXDqr0acRWGy0%2BEpZ3HYNDalEYsK0lR9Q0WCgty5I0JKmPIuo9hOYa1xTNH%2B22xiWsekxGV%2FcA9FXgWpi%2BFt7fBmMk4dhDe%2BuuYc7N79hd0FYuSBNW1Wp32Bluoe4SNkNAB%2BuIDd9KqPzqs09UAbBoz2y4WxXOQnRyR8GAfb8B%2FDtv62gYjtmp%2F6%2Fyr6xj7byWKZdQt8kEftQLTQmP%2F17Efjp6p%2BXo71Q0F9IhAFiqWfp3Ij8hHDSebLcVb2ULXyHNNQpHBOhFgALrFW3I6Uc3WciLEOsBS9Ej3EGdTg%3D%3D"
45-
const testUrlExpectedUrl = "https://storage.googleapis.com/tf-test-bucket-6159205297736845881/path/to/[email protected]&Expires=1470967410&Signature=JJvE2Jc%2BeoagyS1qRACKBGUkgLkKjw7cGymHhtB4IzzN3nbXDqr0acRWGy0%2BEpZ3HYNDalEYsK0lR9Q0WCgty5I0JKmPIuo9hOYa1xTNH%2B22xiWsekxGV%2FcA9FXgWpi%2BFt7fBmMk4dhDe%2BuuYc7N79hd0FYuSBNW1Wp32Bluoe4SNkNAB%2BuIDd9KqPzqs09UAbBoz2y4WxXOQnRyR8GAfb8B%2FDtv62gYjtmp%2F6%2Fyr6xj7byWKZdQt8kEftQLTQmP%2F17Efjp6p%2BXo71Q0F9IhAFiqWfp3Ij8hHDSebLcVb2ULXyHNNQpHBOhFgALrFW3I6Uc3WciLEOsBS9Ej3EGdTg%3D%3D"
46-
47-
func TestUrlData_Signing(t *testing.T) {
48-
urlData := &UrlData{
49-
HttpMethod: "GET",
50-
Expires: testUrlExpires,
51-
Path: testUrlPath,
52-
}
53-
// unescape and decode the expected signature
54-
expectedSig, err := url.QueryUnescape(testUrlExpectedSignatureBase64Encoded)
55-
if err != nil {
56-
t.Error(err)
57-
}
58-
expected, err := base64.StdEncoding.DecodeString(expectedSig)
59-
if err != nil {
60-
t.Error(err)
61-
}
62-
63-
// load fake service account credentials
64-
cfg, err := google.JWTConfigFromJSON([]byte(fakeCredentials), "")
65-
if err != nil {
66-
t.Error(err)
67-
}
68-
69-
// create url data signature
70-
toSign := urlData.SigningString()
71-
result, err := SignString(toSign, cfg)
72-
if err != nil {
73-
t.Error(err)
74-
}
75-
76-
// compare to expected value
77-
if !bytes.Equal(result, expected) {
78-
t.Errorf("Signatures do not match:\n%x\n%x\n", expected, result)
79-
}
80-
81-
}
82-
83-
func TestUrlData_SignedUrl(t *testing.T) {
84-
// load fake service account credentials
85-
cfg, err := google.JWTConfigFromJSON([]byte(fakeCredentials), "")
86-
if err != nil {
87-
t.Error(err)
88-
}
89-
90-
urlData := &UrlData{
91-
HttpMethod: "GET",
92-
Expires: testUrlExpires,
93-
Path: testUrlPath,
94-
JwtConfig: cfg,
95-
}
96-
result, err := urlData.SignedUrl()
97-
if err != nil {
98-
t.Errorf("Could not generated signed url: %+v", err)
99-
}
100-
if result != testUrlExpectedUrl {
101-
t.Errorf("URL does not match expected value:\n%s\n%s", testUrlExpectedUrl, result)
102-
}
103-
}
104-
10518
func TestAccStorageSignedUrl_basic(t *testing.T) {
10619
t.Parallel()
10720

google-beta/iam_dataproc_cluster.go

Lines changed: 4 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -3,142 +3,19 @@
33
package google
44

55
import (
6-
"fmt"
7-
8-
"github.com/hashicorp/errwrap"
96
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/dataproc"
108
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgiamresource"
119
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
1210
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
13-
"google.golang.org/api/cloudresourcemanager/v1"
14-
"google.golang.org/api/dataproc/v1"
1511
)
1612

17-
var IamDataprocClusterSchema = map[string]*schema.Schema{
18-
"cluster": {
19-
Type: schema.TypeString,
20-
Required: true,
21-
ForceNew: true,
22-
},
23-
"project": {
24-
Type: schema.TypeString,
25-
Optional: true,
26-
Computed: true,
27-
ForceNew: true,
28-
},
29-
"region": {
30-
Type: schema.TypeString,
31-
Optional: true,
32-
Computed: true,
33-
ForceNew: true,
34-
},
35-
}
36-
37-
type DataprocClusterIamUpdater struct {
38-
project string
39-
region string
40-
cluster string
41-
d tpgresource.TerraformResourceData
42-
Config *transport_tpg.Config
43-
}
13+
var IamDataprocClusterSchema = dataproc.IamDataprocClusterSchema
4414

4515
func NewDataprocClusterUpdater(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (tpgiamresource.ResourceIamUpdater, error) {
46-
project, err := tpgresource.GetProject(d, config)
47-
if err != nil {
48-
return nil, err
49-
}
50-
51-
region, err := tpgresource.GetRegion(d, config)
52-
if err != nil {
53-
return nil, err
54-
}
55-
56-
if err := d.Set("project", project); err != nil {
57-
return nil, fmt.Errorf("Error setting project: %s", err)
58-
}
59-
if err := d.Set("region", region); err != nil {
60-
return nil, fmt.Errorf("Error setting region: %s", err)
61-
}
62-
63-
return &DataprocClusterIamUpdater{
64-
project: project,
65-
region: region,
66-
cluster: d.Get("cluster").(string),
67-
d: d,
68-
Config: config,
69-
}, nil
16+
return dataproc.NewDataprocClusterUpdater(d, config)
7017
}
7118

7219
func DataprocClusterIdParseFunc(d *schema.ResourceData, config *transport_tpg.Config) error {
73-
fv, err := tpgresource.ParseRegionalFieldValue("clusters", d.Id(), "project", "region", "zone", d, config, true)
74-
if err != nil {
75-
return err
76-
}
77-
78-
if err := d.Set("project", fv.Project); err != nil {
79-
return fmt.Errorf("Error setting project: %s", err)
80-
}
81-
if err := d.Set("region", fv.Region); err != nil {
82-
return fmt.Errorf("Error setting region: %s", err)
83-
}
84-
if err := d.Set("cluster", fv.Name); err != nil {
85-
return fmt.Errorf("Error setting cluster: %s", err)
86-
}
87-
88-
// Explicitly set the id so imported resources have the same ID format as non-imported ones.
89-
d.SetId(fv.RelativeLink())
90-
return nil
91-
}
92-
93-
func (u *DataprocClusterIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
94-
req := &dataproc.GetIamPolicyRequest{}
95-
96-
userAgent, err := tpgresource.GenerateUserAgentString(u.d, u.Config.UserAgent)
97-
if err != nil {
98-
return nil, err
99-
}
100-
101-
p, err := u.Config.NewDataprocClient(userAgent).Projects.Regions.Clusters.GetIamPolicy(u.GetResourceId(), req).Do()
102-
if err != nil {
103-
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
104-
}
105-
106-
cloudResourcePolicy, err := dataprocToResourceManagerPolicy(p)
107-
if err != nil {
108-
return nil, errwrap.Wrapf(fmt.Sprintf("Invalid IAM policy for %s: {{err}}", u.DescribeResource()), err)
109-
}
110-
111-
return cloudResourcePolicy, nil
112-
}
113-
114-
func (u *DataprocClusterIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error {
115-
dataprocPolicy, err := resourceManagerToDataprocPolicy(policy)
116-
if err != nil {
117-
return errwrap.Wrapf(fmt.Sprintf("Invalid IAM policy for %s: {{err}}", u.DescribeResource()), err)
118-
}
119-
120-
userAgent, err := tpgresource.GenerateUserAgentString(u.d, u.Config.UserAgent)
121-
if err != nil {
122-
return err
123-
}
124-
125-
req := &dataproc.SetIamPolicyRequest{Policy: dataprocPolicy}
126-
_, err = u.Config.NewDataprocClient(userAgent).Projects.Regions.Clusters.SetIamPolicy(u.GetResourceId(), req).Do()
127-
if err != nil {
128-
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
129-
}
130-
131-
return nil
132-
}
133-
134-
func (u *DataprocClusterIamUpdater) GetResourceId() string {
135-
return fmt.Sprintf("projects/%s/regions/%s/clusters/%s", u.project, u.region, u.cluster)
136-
}
137-
138-
func (u *DataprocClusterIamUpdater) GetMutexKey() string {
139-
return fmt.Sprintf("iam-dataproc-cluster-%s-%s-%s", u.project, u.region, u.cluster)
140-
}
141-
142-
func (u *DataprocClusterIamUpdater) DescribeResource() string {
143-
return fmt.Sprintf("Dataproc Cluster %s/%s/%s", u.project, u.region, u.cluster)
20+
return dataproc.DataprocClusterIdParseFunc(d, config)
14421
}

0 commit comments

Comments
 (0)