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

Move Cloud Build Worker Pool to GA. #5356

Merged
merged 5 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion mmv1/third_party/terraform/go.mod.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/hashicorp/terraform-provider-google<%= "-" + version unless ve

require (
cloud.google.com/go/bigtable v1.10.1
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211021165233-f4f2a757f9e0
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211109205522-6cd3cdca0637
github.com/apparentlymart/go-cidr v1.1.0
github.com/client9/misspell v0.3.4
github.com/davecgh/go-spew v1.1.1
Expand Down
2 changes: 2 additions & 0 deletions mmv1/third_party/terraform/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1430,3 +1430,5 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211109205522-6cd3cdca0637 h1:sFNz5neMQaa4CIRE2D35t5A84lps/ylOlAXE+ByRKho=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211109205522-6cd3cdca0637/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<% autogen_exception -%>
package google

<% unless version == 'ga' -%>
import (
"fmt"
"strings"
Expand Down Expand Up @@ -190,4 +189,3 @@ func funcAccTestCloudbuildWorkerPoolCheckDestroy(t *testing.T) func(s *terraform
return nil
}
}
<% end -%>
2 changes: 0 additions & 2 deletions mmv1/third_party/terraform/utils/config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@ type Config struct {
<% if version == 'private' -%>
VmwareBasePath string
<% end -%>
<% unless version == 'ga' -%>
// CloudBuild WorkerPool uses a different endpoint (v1beta1) than any other CloudBuild resources
CloudBuildWorkerPoolBasePath string
<% end -%>
}

<% products.each do |product| -%>
Expand Down
6 changes: 0 additions & 6 deletions mmv1/third_party/terraform/utils/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ func Provider() *schema.Provider {
VmwareEndpointEntryKey: VmwareEndpointEntry,
<% end -%>

<% unless version == "ga" -%>
CloudBuildWorkerPoolEndpointEntryKey: CloudBuildWorkerPoolEndpointEntry,
<% end -%>
},

ProviderMetaSchema: map[string]*schema.Schema{
Expand Down Expand Up @@ -456,9 +454,7 @@ end # products.each do
// resources implemented within tpgtools
map[string]*schema.Resource{
"google_assured_workloads_workload": resourceAssuredWorkloadsWorkload(),
<% unless version == 'ga' -%>
"google_cloudbuild_worker_pool": resourceCloudbuildWorkerPool(),
<% end -%>
"google_compute_firewall_policy_association": resourceComputeFirewallPolicyAssociation(),
"google_compute_firewall_policy": resourceComputeFirewallPolicy(),
"google_compute_firewall_policy_rule": resourceComputeFirewallPolicyRule(),
Expand Down Expand Up @@ -655,9 +651,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.GkeHubBasePath = d.Get(GkeHubFeatureCustomEndpointEntryKey).(string)
config.OrgPolicyBasePath = d.Get(OrgPolicyEndpointEntryKey).(string)
config.PrivatecaBasePath = d.Get(PrivatecaCertificateTemplateEndpointEntryKey).(string)
<% unless version == "ga" -%>
config.CloudBuildWorkerPoolBasePath = d.Get(CloudBuildWorkerPoolEndpointEntryKey).(string)
<% end -%>

stopCtx, ok := schema.StopContext(ctx)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion tpgtools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
bitbucket.org/creachadair/stringset v0.0.9
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211021165233-f4f2a757f9e0
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211109205522-6cd3cdca0637
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/hcl v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions tpgtools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211021165233-f4f2a757f9e0 h1:GQS66Qx0pa9JHrjKyI5AHesSPeFNlHebXlASOXzCJKY=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211021165233-f4f2a757f9e0/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211109205522-6cd3cdca0637 h1:sFNz5neMQaa4CIRE2D35t5A84lps/ylOlAXE+ByRKho=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20211109205522-6cd3cdca0637/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
Expand Down
6 changes: 6 additions & 0 deletions tpgtools/overrides/cloudbuild/tpgtools_product.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- type: PRODUCT_BASE_PATH
details:
basepathidentifier: cloud_build_worker_pool
- type: PRODUCT_TITLE # used to align with mmv1 product
details:
title: "cloudbuild"
4 changes: 4 additions & 0 deletions tpgtools/overrides/cloudbuild/worker_pool.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- type: DIFF_SUPPRESS_FUNC
field: network_config.peered_network
details:
diffsuppressfunc: compareResourceNames
120 changes: 120 additions & 0 deletions tpgtools/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

assuredworkloads "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/assuredworkloads"
assuredworkloadsBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/assuredworkloads/beta"
cloudbuild "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuild"
cloudbuildBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuild/beta"
cloudresourcemanager "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudresourcemanager"
cloudresourcemanagerBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudresourcemanager/beta"
Expand Down Expand Up @@ -88,6 +89,8 @@ func DCLToTerraformReference(resourceType, version string) (string, error) {
switch resourceType {
case "AssuredWorkloadsWorkload":
return "google_assured_workloads_workload", nil
case "CloudbuildWorkerPool":
return "google_cloudbuild_worker_pool", nil
case "CloudResourceManagerFolder":
return "google_folder", nil
case "CloudResourceManagerProject":
Expand Down Expand Up @@ -123,6 +126,8 @@ func DCLToTerraformSampleName(service, resource string) (string, string, error)
switch service + resource {
case "assuredworkloadsworkload":
return "AssuredWorkloads", "Workload", nil
case "cloudbuildworkerpool":
return "cloudbuild", "WorkerPool", nil
case "cloudresourcemanagerfolder":
return "CloudResourceManager", "Folder", nil
case "cloudresourcemanagerproject":
Expand Down Expand Up @@ -263,6 +268,12 @@ func ConvertSampleJSONToHCL(resourceType string, version string, hasGAEquivalent
return "", err
}
return AssuredWorkloadsWorkloadAsHCL(*r, hasGAEquivalent)
case "CloudbuildWorkerPool":
r := &cloudbuild.WorkerPool{}
if err := json.Unmarshal(b, r); err != nil {
return "", err
}
return CloudbuildWorkerPoolAsHCL(*r, hasGAEquivalent)
case "CloudResourceManagerFolder":
r := &cloudresourcemanager.Folder{}
if err := json.Unmarshal(b, r); err != nil {
Expand Down Expand Up @@ -2708,6 +2719,71 @@ func convertAssuredWorkloadsWorkloadResourcesToHCL(r *assuredworkloads.WorkloadR
return outputConfig + "}"
}

// CloudbuildWorkerPoolAsHCL returns a string representation of the specified resource in HCL.
// The generated HCL will include every settable field as a literal - that is, no
// variables, no references. This may not be the best possible representation, but
// the crucial point is that `terraform import; terraform apply` will not produce
// any changes. We do not validate that the resource specified will pass terraform
// validation unless is an object returned from the API after an Apply.
func CloudbuildWorkerPoolAsHCL(r cloudbuild.WorkerPool, hasGAEquivalent bool) (string, error) {
outputConfig := "resource \"google_cloudbuild_worker_pool\" \"output\" {\n"
if r.Location != nil {
outputConfig += fmt.Sprintf("\tlocation = %#v\n", *r.Location)
}
if r.Name != nil {
outputConfig += fmt.Sprintf("\tname = %#v\n", *r.Name)
}
if r.DisplayName != nil {
outputConfig += fmt.Sprintf("\tdisplay_name = %#v\n", *r.DisplayName)
}
if v := convertCloudbuildWorkerPoolNetworkConfigToHCL(r.NetworkConfig); v != "" {
outputConfig += fmt.Sprintf("\tnetwork_config %s\n", v)
}
if r.Project != nil {
outputConfig += fmt.Sprintf("\tproject = %#v\n", *r.Project)
}
if v := convertCloudbuildWorkerPoolWorkerConfigToHCL(r.WorkerConfig); v != "" {
outputConfig += fmt.Sprintf("\tworker_config %s\n", v)
}
formatted, err := formatHCL(outputConfig + "}")
if err != nil {
return "", err
}
if !hasGAEquivalent {
// The formatter will not accept the google-beta symbol because it is injected during testing.
return withProviderLine(formatted), nil
}
return formatted, nil
}

func convertCloudbuildWorkerPoolNetworkConfigToHCL(r *cloudbuild.WorkerPoolNetworkConfig) string {
if r == nil {
return ""
}
outputConfig := "{\n"
if r.PeeredNetwork != nil {
outputConfig += fmt.Sprintf("\tpeered_network = %#v\n", *r.PeeredNetwork)
}
return outputConfig + "}"
}

func convertCloudbuildWorkerPoolWorkerConfigToHCL(r *cloudbuild.WorkerPoolWorkerConfig) string {
if r == nil {
return ""
}
outputConfig := "{\n"
if r.DiskSizeGb != nil {
outputConfig += fmt.Sprintf("\tdisk_size_gb = %#v\n", *r.DiskSizeGb)
}
if r.MachineType != nil {
outputConfig += fmt.Sprintf("\tmachine_type = %#v\n", *r.MachineType)
}
if r.NoExternalIP != nil {
outputConfig += fmt.Sprintf("\tno_external_ip = %#v\n", *r.NoExternalIP)
}
return outputConfig + "}"
}

// CloudResourceManagerFolderAsHCL returns a string representation of the specified resource in HCL.
// The generated HCL will include every settable field as a literal - that is, no
// variables, no references. This may not be the best possible representation, but
Expand Down Expand Up @@ -6692,6 +6768,50 @@ func convertAssuredWorkloadsWorkloadResourcesList(i interface{}) (out []map[stri
return out
}

func convertCloudbuildWorkerPoolNetworkConfig(i interface{}) map[string]interface{} {
if i == nil {
return nil
}
in := i.(map[string]interface{})
return map[string]interface{}{
"peeredNetwork": in["peered_network"],
}
}

func convertCloudbuildWorkerPoolNetworkConfigList(i interface{}) (out []map[string]interface{}) {
if i == nil {
return nil
}

for _, v := range i.([]interface{}) {
out = append(out, convertCloudbuildWorkerPoolNetworkConfig(v))
}
return out
}

func convertCloudbuildWorkerPoolWorkerConfig(i interface{}) map[string]interface{} {
if i == nil {
return nil
}
in := i.(map[string]interface{})
return map[string]interface{}{
"diskSizeGb": in["disk_size_gb"],
"machineType": in["machine_type"],
"noExternalIP": in["no_external_ip"],
}
}

func convertCloudbuildWorkerPoolWorkerConfigList(i interface{}) (out []map[string]interface{}) {
if i == nil {
return nil
}

for _, v := range i.([]interface{}) {
out = append(out, convertCloudbuildWorkerPoolWorkerConfig(v))
}
return out
}

func convertComputeFirewallPolicyRuleMatch(i interface{}) map[string]interface{} {
if i == nil {
return nil
Expand Down