forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go rewrite constants templates (GoogleCloudPlatform#10409)
- Loading branch information
Showing
73 changed files
with
3,060 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
mmv1/templates/terraform/constants/go/access_approval.go.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{{/* | ||
The license inside this block applies to this file | ||
Copyright 2024 Google Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/}} | ||
var accessApprovalCloudProductMapping = map[string]string{ | ||
"appengine.googleapis.com": "App Engine", | ||
"bigquery.googleapis.com": "BigQuery", | ||
"bigtable.googleapis.com": "Cloud Bigtable", | ||
"cloudkms.googleapis.com": "Cloud Key Management Service", | ||
"compute.googleapis.com": "Compute Engine", | ||
"dataflow.googleapis.com": "Cloud Dataflow", | ||
"iam.googleapis.com": "Cloud Identity and Access Management", | ||
"pubsub.googleapis.com": "Cloud Pub/Sub", | ||
"storage.googleapis.com": "Cloud Storage", | ||
} | ||
func accessApprovalEnrolledServicesHash(v interface{}) int { | ||
var buf bytes.Buffer | ||
m := v.(map[string]interface{}) | ||
cp := m["cloud_product"].(string) | ||
if n, ok := accessApprovalCloudProductMapping[cp]; ok { | ||
cp = n | ||
} | ||
buf.WriteString(fmt.Sprintf("%s-", strings.ToLower(cp))) // ToLower just in case | ||
buf.WriteString(fmt.Sprintf("%s-", strings.ToLower(m["enrollment_level"].(string)))) | ||
return tpgresource.Hashcode(buf.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{{ if ne $.Compiler "terraformgoogleconversion-codegen" }} | ||
// waitForAgentPoolReady waits for an agent pool to leave the | ||
// "CREATING" state and become "CREATED", to indicate that it's ready. | ||
func waitForAgentPoolReady(d *schema.ResourceData, config *transport_tpg.Config, timeout time.Duration) error { | ||
return resource.Retry(timeout, func() *resource.RetryError { | ||
if err := resourceStorageTransferAgentPoolRead(d, config); err != nil { | ||
return resource.NonRetryableError(err) | ||
} | ||
|
||
name := d.Get("name").(string) | ||
state := d.Get("state").(string) | ||
if state == "CREATING" { | ||
return resource.RetryableError(fmt.Errorf("AgentPool %q has state %q.", name, state)) | ||
} else if state == "CREATED" { | ||
log.Printf("[DEBUG] AgentPool %q has state %q.", name, state) | ||
return nil | ||
} else { | ||
return resource.NonRetryableError(fmt.Errorf("AgentPool %q has state %q.", name, state)) | ||
} | ||
}) | ||
} | ||
{{ end -}} |
24 changes: 24 additions & 0 deletions
24
mmv1/templates/terraform/constants/go/apigee_instance.go.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Supress diffs when the lists of project have the same number of entries to handle the case that | ||
// API does not return what the user originally provided. Instead, API does some transformation. | ||
// For example, user provides a list of project number, but API returns a list of project Id. | ||
func projectListDiffSuppress(_, _, _ string, d *schema.ResourceData) bool { | ||
return ProjectListDiffSuppressFunc(d) | ||
} | ||
|
||
func ProjectListDiffSuppressFunc(d tpgresource.TerraformResourceDataChange) bool { | ||
kLength := "consumer_accept_list.#" | ||
oldLength, newLength := d.GetChange(kLength) | ||
|
||
oldInt, ok := oldLength.(int) | ||
if !ok { | ||
return false | ||
} | ||
|
||
newInt, ok := newLength.(int) | ||
if !ok { | ||
return false | ||
} | ||
log.Printf("[DEBUG] - suppressing diff with oldInt %d, newInt %d", oldInt, newInt) | ||
|
||
return oldInt == newInt | ||
} |
4 changes: 4 additions & 0 deletions
4
mmv1/templates/terraform/constants/go/apphub_service_project.go.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Suppress all diff for the field Service Project | ||
func ServiceProjectDiffSuppress(_, _, _ string, _ *schema.ResourceData) bool { | ||
return true | ||
} |
45 changes: 45 additions & 0 deletions
45
mmv1/templates/terraform/constants/go/artifact_registry_repository.go.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{{/* | ||
The license inside this block applies to this file | ||
Copyright 2024 Google Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/}} | ||
func upstreamPoliciesDiffSuppress(k, old, new string, d *schema.ResourceData) bool { | ||
o, n := d.GetChange("virtual_repository_config.0.upstream_policies") | ||
oldPolicies, ok := o.([]any) | ||
if !ok { | ||
return false | ||
} | ||
newPolicies, ok := n.([]any) | ||
if !ok { | ||
return false | ||
} | ||
|
||
var oldHashes, newHashes []interface{} | ||
for _, policy := range oldPolicies { | ||
data, ok := policy.(map[string]any) | ||
if !ok { | ||
return false | ||
} | ||
hashStr := fmt.Sprintf("[id:%v priority:%v repository:%v]", data["id"], data["priority"], data["repository"]) | ||
oldHashes = append(oldHashes, hashStr) | ||
} | ||
for _, policy := range newPolicies { | ||
data, ok := policy.(map[string]any) | ||
if !ok { | ||
return false | ||
} | ||
hashStr := fmt.Sprintf("[id:%v priority:%v repository:%v]", data["id"], data["priority"], data["repository"]) | ||
newHashes = append(newHashes, hashStr) | ||
} | ||
|
||
oldSet := schema.NewSet(schema.HashString, oldHashes) | ||
newSet := schema.NewSet(schema.HashString, newHashes) | ||
return oldSet.Equal(newSet) | ||
} |
158 changes: 158 additions & 0 deletions
158
mmv1/templates/terraform/constants/go/backend_service.go.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
{{/* | ||
The license inside this block applies to this file | ||
Copyright 2024 Google Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/}} | ||
// suppress changes on sample_rate if log_config is set to disabled. | ||
func suppressWhenDisabled(k, old, new string, d *schema.ResourceData) bool { | ||
_, n := d.GetChange("log_config.0.enable") | ||
if tpgresource.IsEmptyValue(reflect.ValueOf(n)) { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// Whether the backend is a global or regional NEG | ||
func isNegBackend(backend map[string]interface{}) bool { | ||
backendGroup, ok := backend["group"] | ||
if !ok { | ||
return false | ||
} | ||
|
||
match, err := regexp.MatchString("(?:global|regions/[^/]+)/networkEndpointGroups", backendGroup.(string)) | ||
if err != nil { | ||
// should not happen as long as the regexp pattern compiled correctly | ||
return false | ||
} | ||
return match | ||
} | ||
|
||
func resourceGoogleComputeBackendServiceBackendHash(v interface{}) int { | ||
if v == nil { | ||
return 0 | ||
} | ||
|
||
var buf bytes.Buffer | ||
m := v.(map[string]interface{}) | ||
log.Printf("[DEBUG] hashing %v", m) | ||
|
||
if group, err := tpgresource.GetRelativePath(m["group"].(string)); err != nil { | ||
log.Printf("[WARN] Error on retrieving relative path of instance group: %s", err) | ||
buf.WriteString(fmt.Sprintf("%s-", m["group"].(string))) | ||
} else { | ||
buf.WriteString(fmt.Sprintf("%s-", group)) | ||
} | ||
|
||
if v, ok := m["balancing_mode"]; ok { | ||
if v == nil { | ||
v = "" | ||
} | ||
|
||
buf.WriteString(fmt.Sprintf("%v-", v)) | ||
} | ||
if v, ok := m["capacity_scaler"]; ok { | ||
if v == nil { | ||
v = 0.0 | ||
} | ||
|
||
// floats can't be added to the hash with %v as the other values are because | ||
// %v and %f are not equivalent strings so this must remain as a float so that | ||
// the hash function doesn't return something else. | ||
buf.WriteString(fmt.Sprintf("%f-", v.(float64))) | ||
} | ||
if v, ok := m["description"]; ok { | ||
if v == nil { | ||
v = "" | ||
} | ||
|
||
log.Printf("[DEBUG] writing description %s", v) | ||
buf.WriteString(fmt.Sprintf("%v-", v)) | ||
} | ||
if v, ok := m["max_rate"]; ok { | ||
if v == nil { | ||
v = 0 | ||
} | ||
|
||
buf.WriteString(fmt.Sprintf("%v-", v)) | ||
} | ||
if v, ok := m["max_rate_per_instance"]; ok { | ||
if v == nil { | ||
v = 0.0 | ||
} | ||
|
||
// floats can't be added to the hash with %v as the other values are because | ||
// %v and %f are not equivalent strings so this must remain as a float so that | ||
// the hash function doesn't return something else. | ||
buf.WriteString(fmt.Sprintf("%f-", v.(float64))) | ||
} | ||
if v, ok := m["max_connections"]; ok { | ||
if v == nil { | ||
v = 0 | ||
} | ||
|
||
buf.WriteString(fmt.Sprintf("%v-", v)) | ||
} | ||
if v, ok := m["max_connections_per_instance"]; ok { | ||
if v == nil { | ||
v = 0 | ||
} | ||
|
||
buf.WriteString(fmt.Sprintf("%v-", v)) | ||
} | ||
if v, ok := m["max_rate_per_instance"]; ok { | ||
if v == nil { | ||
v = 0.0 | ||
} | ||
|
||
// floats can't be added to the hash with %v as the other values are because | ||
// %v and %f are not equivalent strings so this must remain as a float so that | ||
// the hash function doesn't return something else. | ||
buf.WriteString(fmt.Sprintf("%f-", v.(float64))) | ||
} | ||
if v, ok := m["max_connections_per_endpoint"]; ok { | ||
if v == nil { | ||
v = 0 | ||
} | ||
|
||
buf.WriteString(fmt.Sprintf("%v-", v)) | ||
} | ||
if v, ok := m["max_rate_per_endpoint"]; ok { | ||
if v == nil { | ||
v = 0.0 | ||
} | ||
|
||
// floats can't be added to the hash with %v as the other values are because | ||
// %v and %f are not equivalent strings so this must remain as a float so that | ||
// the hash function doesn't return something else. | ||
buf.WriteString(fmt.Sprintf("%f-", v.(float64))) | ||
} | ||
if v, ok := m["max_utilization"]; ok && !isNegBackend(m) { | ||
if v == nil { | ||
v = 0.0 | ||
} | ||
|
||
// floats can't be added to the hash with %v as the other values are because | ||
// %v and %f are not equivalent strings so this must remain as a float so that | ||
// the hash function doesn't return something else. | ||
buf.WriteString(fmt.Sprintf("%f-", v.(float64))) | ||
} | ||
|
||
// This is in region backend service, but not in backend service. Should be a no-op | ||
// if it's not present. | ||
if v, ok := m["failover"]; ok { | ||
if v == nil { | ||
v = false | ||
} | ||
buf.WriteString(fmt.Sprintf("%v-", v.(bool))) | ||
} | ||
|
||
log.Printf("[DEBUG] computed hash value of %v from %v", tpgresource.Hashcode(buf.String()), buf.String()) | ||
return tpgresource.Hashcode(buf.String()) | ||
} |
Oops, something went wrong.