Skip to content

Commit 800f9ea

Browse files
Add GKE Multicloud (#5522) (#10754)
* Release GKE Multicloud in terraform at GA. * Updates to samples as we go GA. * Some additional complexities in moving to GA - regional endpoints and divergence in naming between this and OSPolicy. * Move to handwritten samples, add data source for versions and permissible regions. * Add handwritten docs for Azure and AWS container versions. * Get data sources under same header as resources. * Fix documentation + update node pool test to use the version everywhere. * fix lints - do error checking. * Update DCL version again. Signed-off-by: Modular Magician <[email protected]>
1 parent 9c5d180 commit 800f9ea

File tree

46 files changed

+8021
-24
lines changed

Some content is hidden

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

46 files changed

+8021
-24
lines changed

.changelog/5522.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
```release-note:new-resource
2+
google_container_azure_client
3+
```
4+
```release-note:new-resource
5+
google_container_azure_cluster
6+
```
7+
```release-note:new-resource
8+
google_container_azure_node_pool
9+
```
10+
```release-note:new-resource
11+
google_container_aws_cluster
12+
```
13+
```release-note:new-resource
14+
google_container_aws_node_pool
15+
```
16+
```release-note:new-datasource
17+
google_container_aws_versions
18+
```
19+
```release-note:new-datasource
20+
google_container_azure_versions
21+
```

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module github.com/hashicorp/terraform-provider-google
22
require (
33
cloud.google.com/go/bigtable v1.10.1
4-
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636
4+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211215020606-79616333f950
55
github.com/apparentlymart/go-cidr v1.1.0
66
github.com/client9/misspell v0.3.4
77
github.com/davecgh/go-spew v1.1.1

go.sum

+18
Original file line numberDiff line numberDiff line change
@@ -1457,3 +1457,21 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
14571457
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
14581458
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
14591459
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
1460+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636 h1:91BjCMjMOZc+qBIkXxj2RU0dznJx/ySUL1HBJ5i+YRs=
1461+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
1462+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636 h1:91BjCMjMOZc+qBIkXxj2RU0dznJx/ySUL1HBJ5i+YRs=
1463+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
1464+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636 h1:91BjCMjMOZc+qBIkXxj2RU0dznJx/ySUL1HBJ5i+YRs=
1465+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
1466+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636 h1:91BjCMjMOZc+qBIkXxj2RU0dznJx/ySUL1HBJ5i+YRs=
1467+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
1468+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636 h1:91BjCMjMOZc+qBIkXxj2RU0dznJx/ySUL1HBJ5i+YRs=
1469+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
1470+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636 h1:91BjCMjMOZc+qBIkXxj2RU0dznJx/ySUL1HBJ5i+YRs=
1471+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
1472+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636 h1:91BjCMjMOZc+qBIkXxj2RU0dznJx/ySUL1HBJ5i+YRs=
1473+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
1474+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636 h1:91BjCMjMOZc+qBIkXxj2RU0dznJx/ySUL1HBJ5i+YRs=
1475+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211214175538-23aaa3b3a636/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
1476+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211215020606-79616333f950 h1:pJAaEIUF6dSY6hRyiHpSlSHgvyaCv478IUVZR6t2OIU=
1477+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211215020606-79616333f950/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=

google/config.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ type Config struct {
247247
CloudResourceManagerBasePath string
248248
EventarcBasePath string
249249
GkeHubBasePath string
250+
ContainerAzureBasePath string
251+
ContainerAwsBasePath string
250252
OrgPolicyBasePath string
251253
RecaptchaEnterpriseBasePath string
252254
// CloudBuild WorkerPool uses a different endpoint (v1beta1) than any other CloudBuild resources
@@ -328,7 +330,9 @@ const ResourceManagerV2BasePathKey = "ResourceManagerV2"
328330
const ServiceNetworkingBasePathKey = "ServiceNetworking"
329331
const StorageTransferBasePathKey = "StorageTransfer"
330332
const BigtableAdminBasePathKey = "BigtableAdmin"
331-
const GkeHubFeatureBasePathKey = "GkeHubFeatureBasePathKey"
333+
const GkeHubFeatureBasePathKey = "GkeHubFeature"
334+
const ContainerAwsBasePathKey = "ContainerAws"
335+
const ContainerAzureBasePathKey = "ContainerAzure"
332336

333337
// Generated product base paths
334338
var DefaultBasePaths = map[string]string{
@@ -408,6 +412,8 @@ var DefaultBasePaths = map[string]string{
408412
StorageTransferBasePathKey: "https://storagetransfer.googleapis.com/v1/",
409413
BigtableAdminBasePathKey: "https://bigtableadmin.googleapis.com/v2/",
410414
GkeHubFeatureBasePathKey: "https://gkehub.googleapis.com/v1beta/",
415+
ContainerAwsBasePathKey: "https://{{location}}-gkemulticloud.googleapis.com/v1/",
416+
ContainerAzureBasePathKey: "https://{{location}}-gkemulticloud.googleapis.com/v1/",
411417
}
412418

413419
var DefaultClientScopes = []string{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package google
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
)
9+
10+
func dataSourceGoogleContainerAwsVersions() *schema.Resource {
11+
return &schema.Resource{
12+
Read: dataSourceGoogleContainerAwsVersionsRead,
13+
Schema: map[string]*schema.Schema{
14+
"project": {
15+
Type: schema.TypeString,
16+
Optional: true,
17+
},
18+
"location": {
19+
Type: schema.TypeString,
20+
Optional: true,
21+
},
22+
"valid_versions": {
23+
Type: schema.TypeList,
24+
Computed: true,
25+
Elem: &schema.Schema{Type: schema.TypeString},
26+
},
27+
"supported_regions": {
28+
Type: schema.TypeList,
29+
Computed: true,
30+
Elem: &schema.Schema{Type: schema.TypeString},
31+
},
32+
},
33+
}
34+
}
35+
36+
func dataSourceGoogleContainerAwsVersionsRead(d *schema.ResourceData, meta interface{}) error {
37+
config := meta.(*Config)
38+
userAgent, err := generateUserAgentString(d, config.userAgent)
39+
if err != nil {
40+
return err
41+
}
42+
43+
project, err := getProject(d, config)
44+
if err != nil {
45+
return err
46+
}
47+
48+
location, err := getLocation(d, config)
49+
if err != nil {
50+
return err
51+
}
52+
if len(location) == 0 {
53+
return fmt.Errorf("Cannot determine location: set location in this data source or at provider-level")
54+
}
55+
56+
url, err := replaceVars(d, config, "{{ContainerAwsBasePath}}projects/{{project}}/locations/{{location}}/awsServerConfig")
57+
if err != nil {
58+
return err
59+
}
60+
res, err := sendRequest(config, "GET", project, url, userAgent, nil)
61+
if err != nil {
62+
return err
63+
}
64+
if err := d.Set("supported_regions", res["supportedAwsRegions"]); err != nil {
65+
return err
66+
}
67+
var validVersions []string
68+
for _, v := range res["validVersions"].([]interface{}) {
69+
vm := v.(map[string]interface{})
70+
validVersions = append(validVersions, vm["version"].(string))
71+
}
72+
if err := d.Set("valid_versions", validVersions); err != nil {
73+
return err
74+
}
75+
76+
d.SetId(time.Now().UTC().String())
77+
return nil
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package google
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
)
9+
10+
func dataSourceGoogleContainerAzureVersions() *schema.Resource {
11+
return &schema.Resource{
12+
Read: dataSourceGoogleContainerAzureVersionsRead,
13+
Schema: map[string]*schema.Schema{
14+
"project": {
15+
Type: schema.TypeString,
16+
Optional: true,
17+
},
18+
"location": {
19+
Type: schema.TypeString,
20+
Optional: true,
21+
},
22+
"valid_versions": {
23+
Type: schema.TypeList,
24+
Computed: true,
25+
Elem: &schema.Schema{Type: schema.TypeString},
26+
},
27+
"supported_regions": {
28+
Type: schema.TypeList,
29+
Computed: true,
30+
Elem: &schema.Schema{Type: schema.TypeString},
31+
},
32+
},
33+
}
34+
}
35+
36+
func dataSourceGoogleContainerAzureVersionsRead(d *schema.ResourceData, meta interface{}) error {
37+
config := meta.(*Config)
38+
userAgent, err := generateUserAgentString(d, config.userAgent)
39+
if err != nil {
40+
return err
41+
}
42+
43+
project, err := getProject(d, config)
44+
if err != nil {
45+
return err
46+
}
47+
48+
location, err := getLocation(d, config)
49+
if err != nil {
50+
return err
51+
}
52+
if len(location) == 0 {
53+
return fmt.Errorf("Cannot determine location: set location in this data source or at provider-level")
54+
}
55+
56+
url, err := replaceVars(d, config, "{{ContainerAzureBasePath}}projects/{{project}}/locations/{{location}}/azureServerConfig")
57+
if err != nil {
58+
return err
59+
}
60+
res, err := sendRequest(config, "GET", project, url, userAgent, nil)
61+
if err != nil {
62+
return err
63+
}
64+
if err := d.Set("supported_regions", res["supportedAzureRegions"]); err != nil {
65+
return err
66+
}
67+
var validVersions []string
68+
for _, v := range res["validVersions"].([]interface{}) {
69+
vm := v.(map[string]interface{})
70+
validVersions = append(validVersions, vm["version"].(string))
71+
}
72+
if err := d.Set("valid_versions", validVersions); err != nil {
73+
return err
74+
}
75+
76+
d.SetId(time.Now().UTC().String())
77+
return nil
78+
}

google/provider.go

+11
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,8 @@ func Provider() *schema.Provider {
691691
OrgPolicyEndpointEntryKey: OrgPolicyEndpointEntry,
692692
PrivatecaCertificateTemplateEndpointEntryKey: PrivatecaCertificateTemplateCustomEndpointEntry,
693693
RecaptchaEnterpriseEndpointEntryKey: RecaptchaEnterpriseEndpointEntry,
694+
ContainerAwsCustomEndpointEntryKey: ContainerAwsCustomEndpointEntry,
695+
ContainerAzureCustomEndpointEntryKey: ContainerAzureCustomEndpointEntry,
694696

695697
CloudBuildWorkerPoolEndpointEntryKey: CloudBuildWorkerPoolEndpointEntry,
696698
},
@@ -745,6 +747,8 @@ func Provider() *schema.Provider {
745747
"google_compute_subnetwork": dataSourceGoogleComputeSubnetwork(),
746748
"google_compute_vpn_gateway": dataSourceGoogleComputeVpnGateway(),
747749
"google_compute_zones": dataSourceGoogleComputeZones(),
750+
"google_container_azure_versions": dataSourceGoogleContainerAzureVersions(),
751+
"google_container_aws_versions": dataSourceGoogleContainerAwsVersions(),
748752
"google_container_cluster": dataSourceGoogleContainerCluster(),
749753
"google_container_engine_versions": dataSourceGoogleContainerEngineVersions(),
750754
"google_container_registry_image": dataSourceGoogleContainerImage(),
@@ -1212,6 +1216,11 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
12121216
"google_os_config_os_policy_assignment": resourceOSConfigOSPolicyAssignment(),
12131217
"google_privateca_certificate_template": resourcePrivatecaCertificateTemplate(),
12141218
"google_recaptcha_enterprise_key": resourceRecaptchaEnterpriseKey(),
1219+
"google_container_aws_cluster": resourceContainerAwsCluster(),
1220+
"google_container_aws_node_pool": resourceContainerAwsNodePool(),
1221+
"google_container_azure_client": resourceContainerAzureClient(),
1222+
"google_container_azure_cluster": resourceContainerAzureCluster(),
1223+
"google_container_azure_node_pool": resourceContainerAzureNodePool(),
12151224
},
12161225
// ------------------------------------
12171226
map[string]*schema.Resource{
@@ -1446,6 +1455,8 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
14461455
config.GkeHubBasePath = d.Get(GkeHubFeatureCustomEndpointEntryKey).(string)
14471456
config.OrgPolicyBasePath = d.Get(OrgPolicyEndpointEntryKey).(string)
14481457
config.PrivatecaBasePath = d.Get(PrivatecaCertificateTemplateEndpointEntryKey).(string)
1458+
config.ContainerAwsBasePath = d.Get(ContainerAwsCustomEndpointEntryKey).(string)
1459+
config.ContainerAzureBasePath = d.Get(ContainerAzureCustomEndpointEntryKey).(string)
14491460
config.CloudBuildWorkerPoolBasePath = d.Get(CloudBuildWorkerPoolEndpointEntryKey).(string)
14501461

14511462
stopCtx, ok := schema.StopContext(ctx)

google/provider_dcl_client_creation.go

+48
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
cloudbuild "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuild"
2424
cloudresourcemanager "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudresourcemanager"
2525
compute "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/compute"
26+
containeraws "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/containeraws"
27+
containerazure "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/containerazure"
2628
dataproc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/dataproc"
2729
eventarc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/eventarc"
2830
orgpolicy "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/orgpolicy"
@@ -123,6 +125,52 @@ func NewDCLComputeClient(config *Config, userAgent, billingProject string, timeo
123125
return compute.NewClient(dclConfig)
124126
}
125127

128+
func NewDCLContainerAwsClient(config *Config, userAgent, billingProject string, timeout time.Duration) *containeraws.Client {
129+
configOptions := []dcl.ConfigOption{
130+
dcl.WithHTTPClient(config.client),
131+
dcl.WithUserAgent(userAgent),
132+
dcl.WithLogger(dclLogger{}),
133+
dcl.WithBasePath(config.ContainerAwsBasePath),
134+
}
135+
136+
if timeout != 0 {
137+
configOptions = append(configOptions, dcl.WithTimeout(timeout))
138+
}
139+
140+
if config.UserProjectOverride {
141+
configOptions = append(configOptions, dcl.WithUserProjectOverride())
142+
if billingProject != "" {
143+
configOptions = append(configOptions, dcl.WithBillingProject(billingProject))
144+
}
145+
}
146+
147+
dclConfig := dcl.NewConfig(configOptions...)
148+
return containeraws.NewClient(dclConfig)
149+
}
150+
151+
func NewDCLContainerAzureClient(config *Config, userAgent, billingProject string, timeout time.Duration) *containerazure.Client {
152+
configOptions := []dcl.ConfigOption{
153+
dcl.WithHTTPClient(config.client),
154+
dcl.WithUserAgent(userAgent),
155+
dcl.WithLogger(dclLogger{}),
156+
dcl.WithBasePath(config.ContainerAzureBasePath),
157+
}
158+
159+
if timeout != 0 {
160+
configOptions = append(configOptions, dcl.WithTimeout(timeout))
161+
}
162+
163+
if config.UserProjectOverride {
164+
configOptions = append(configOptions, dcl.WithUserProjectOverride())
165+
if billingProject != "" {
166+
configOptions = append(configOptions, dcl.WithBillingProject(billingProject))
167+
}
168+
}
169+
170+
dclConfig := dcl.NewConfig(configOptions...)
171+
return containerazure.NewClient(dclConfig)
172+
}
173+
126174
func NewDCLDataprocClient(config *Config, userAgent, billingProject string, timeout time.Duration) *dataproc.Client {
127175
configOptions := []dcl.ConfigOption{
128176
dcl.WithHTTPClient(config.client),

google/provider_dcl_endpoints.go

+24
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ var ComputeEndpointEntry = &schema.Schema{
5858
}, ""),
5959
}
6060

61+
var ContainerAwsEndpointEntryKey = "container_aws_custom_endpoint"
62+
var ContainerAwsEndpointEntry = &schema.Schema{
63+
Type: schema.TypeString,
64+
Optional: true,
65+
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
66+
"GOOGLE_CONTAINER_AWS_CUSTOM_ENDPOINT",
67+
}, ""),
68+
}
69+
70+
var ContainerAzureEndpointEntryKey = "container_azure_custom_endpoint"
71+
var ContainerAzureEndpointEntry = &schema.Schema{
72+
Type: schema.TypeString,
73+
Optional: true,
74+
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
75+
"GOOGLE_CONTAINER_AZURE_CUSTOM_ENDPOINT",
76+
}, ""),
77+
}
78+
6179
var EventarcEndpointEntryKey = "eventarc_custom_endpoint"
6280
var EventarcEndpointEntry = &schema.Schema{
6381
Type: schema.TypeString,
@@ -108,6 +126,8 @@ var RecaptchaEnterpriseEndpointEntry = &schema.Schema{
108126
//CloudBuildWorkerPoolBasePath string
109127
//CloudResourceManagerBasePath string
110128
//ComputeBasePath string
129+
//ContainerAwsBasePath string
130+
//ContainerAzureBasePath string
111131
//EventarcBasePath string
112132
//OrgPolicyBasePath string
113133
//OSConfigBasePath string
@@ -119,6 +139,8 @@ var RecaptchaEnterpriseEndpointEntry = &schema.Schema{
119139
// CloudBuildWorkerPoolEndpointEntryKey: CloudBuildWorkerPoolEndpointEntry,
120140
// CloudResourceManagerEndpointEntryKey: CloudResourceManagerEndpointEntry,
121141
// ComputeEndpointEntryKey: ComputeEndpointEntry,
142+
// ContainerAwsEndpointEntryKey: ContainerAwsEndpointEntry,
143+
// ContainerAzureEndpointEntryKey: ContainerAzureEndpointEntry,
122144
// EventarcEndpointEntryKey: EventarcEndpointEntry,
123145
// OrgPolicyEndpointEntryKey: OrgPolicyEndpointEntry,
124146
// OSConfigEndpointEntryKey: OSConfigEndpointEntry,
@@ -130,6 +152,8 @@ var RecaptchaEnterpriseEndpointEntry = &schema.Schema{
130152
// config.CloudBuildWorkerPoolBasePath = d.Get(CloudBuildWorkerPoolEndpointEntryKey).(string)
131153
// config.CloudResourceManagerBasePath = d.Get(CloudResourceManagerEndpointEntryKey).(string)
132154
// config.ComputeBasePath = d.Get(ComputeEndpointEntryKey).(string)
155+
// config.ContainerAwsBasePath = d.Get(ContainerAwsEndpointEntryKey).(string)
156+
// config.ContainerAzureBasePath = d.Get(ContainerAzureEndpointEntryKey).(string)
133157
// config.EventarcBasePath = d.Get(EventarcEndpointEntryKey).(string)
134158
// config.OrgPolicyBasePath = d.Get(OrgPolicyEndpointEntryKey).(string)
135159
// config.OSConfigBasePath = d.Get(OSConfigEndpointEntryKey).(string)

0 commit comments

Comments
 (0)