Skip to content

Commit

Permalink
Add annotations for cloudrunV2_service (#7023) (#13509)
Browse files Browse the repository at this point in the history
* cloudrunV2: added `annotations` to `CloudRunV2_service` resource

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Jan 18, 2023
1 parent e574237 commit 17d467e
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/7023.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudrunV2: added `annotations` to `CloudRunV2_service` resource
```
66 changes: 66 additions & 0 deletions google/resource_cloud_run_v2_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func resourceCloudRunV2Service() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"annotations": {
Type: schema.TypeMap,
Optional: true,
Description: `KRM-style annotations for the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"containers": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -544,6 +550,12 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
},
},
},
"annotations": {
Type: schema.TypeMap,
Optional: true,
Description: `Unstructured key value map that may be set by external tools to store and arbitrary metadata. They are not queryable and should be preserved when modifying objects. Cloud Run will populate some annotations using 'run.googleapis.com' or 'serving.knative.dev' namespaces. This field follows Kubernetes annotations' namespacing, limits, and rules. More info: https://kubernetes.io/docs/user-guide/annotations`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"binary_authorization": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -848,6 +860,12 @@ func resourceCloudRunV2ServiceCreate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
annotationsProp, err := expandCloudRunV2ServiceAnnotations(d.Get("annotations"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("annotations"); !isEmptyValue(reflect.ValueOf(annotationsProp)) && (ok || !reflect.DeepEqual(v, annotationsProp)) {
obj["annotations"] = annotationsProp
}
clientProp, err := expandCloudRunV2ServiceClient(d.Get("client"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -993,6 +1011,9 @@ func resourceCloudRunV2ServiceRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("labels", flattenCloudRunV2ServiceLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading Service: %s", err)
}
if err := d.Set("annotations", flattenCloudRunV2ServiceAnnotations(res["annotations"], d, config)); err != nil {
return fmt.Errorf("Error reading Service: %s", err)
}
if err := d.Set("client", flattenCloudRunV2ServiceClient(res["client"], d, config)); err != nil {
return fmt.Errorf("Error reading Service: %s", err)
}
Expand Down Expand Up @@ -1073,6 +1094,12 @@ func resourceCloudRunV2ServiceUpdate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
annotationsProp, err := expandCloudRunV2ServiceAnnotations(d.Get("annotations"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("annotations"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, annotationsProp)) {
obj["annotations"] = annotationsProp
}
clientProp, err := expandCloudRunV2ServiceClient(d.Get("client"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1228,6 +1255,10 @@ func flattenCloudRunV2ServiceLabels(v interface{}, d *schema.ResourceData, confi
return v
}

func flattenCloudRunV2ServiceAnnotations(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenCloudRunV2ServiceClient(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}
Expand Down Expand Up @@ -1280,6 +1311,8 @@ func flattenCloudRunV2ServiceTemplate(v interface{}, d *schema.ResourceData, con
flattenCloudRunV2ServiceTemplateRevision(original["revision"], d, config)
transformed["labels"] =
flattenCloudRunV2ServiceTemplateLabels(original["labels"], d, config)
transformed["annotations"] =
flattenCloudRunV2ServiceTemplateAnnotations(original["annotations"], d, config)
transformed["scaling"] =
flattenCloudRunV2ServiceTemplateScaling(original["scaling"], d, config)
transformed["vpc_access"] =
Expand Down Expand Up @@ -1308,6 +1341,10 @@ func flattenCloudRunV2ServiceTemplateLabels(v interface{}, d *schema.ResourceDat
return v
}

func flattenCloudRunV2ServiceTemplateAnnotations(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenCloudRunV2ServiceTemplateScaling(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -2321,6 +2358,17 @@ func expandCloudRunV2ServiceLabels(v interface{}, d TerraformResourceData, confi
return m, nil
}

func expandCloudRunV2ServiceAnnotations(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}

func expandCloudRunV2ServiceClient(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -2394,6 +2442,13 @@ func expandCloudRunV2ServiceTemplate(v interface{}, d TerraformResourceData, con
transformed["labels"] = transformedLabels
}

transformedAnnotations, err := expandCloudRunV2ServiceTemplateAnnotations(original["annotations"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedAnnotations); val.IsValid() && !isEmptyValue(val) {
transformed["annotations"] = transformedAnnotations
}

transformedScaling, err := expandCloudRunV2ServiceTemplateScaling(original["scaling"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -2475,6 +2530,17 @@ func expandCloudRunV2ServiceTemplateLabels(v interface{}, d TerraformResourceDat
return m, nil
}

func expandCloudRunV2ServiceTemplateAnnotations(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}

func expandCloudRunV2ServiceTemplateScaling(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
17 changes: 14 additions & 3 deletions google/resource_cloud_run_v2_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ resource "google_cloud_run_v2_service" "default" {
name = "tf-test-cloudrun-service%{random_suffix}"
description = "description creating"
location = "us-central1"
annotations = {
generated-by = "magic-modules"
}
ingress = "INGRESS_TRAFFIC_ALL"
labels = {
label-1 = "value-1"
}
client = "client-1"
client_version = "client-version-1"
template {
labels = {
label-1 = "value-1"
Expand All @@ -64,6 +66,9 @@ resource "google_cloud_run_v2_service" "default" {
max_instance_count = 3
min_instance_count = 1
}
annotations = {
generated-by = "magic-modules"
}
containers {
name = "container-1"
image = "us-docker.pkg.dev/cloudrun/container/hello"
Expand Down Expand Up @@ -103,6 +108,9 @@ resource "google_cloud_run_v2_service" "default" {
name = "tf-test-cloudrun-service%{random_suffix}"
description = "description updating"
location = "us-central1"
annotations = {
generated-by = "magic-modules-files"
}
ingress = "INGRESS_TRAFFIC_ALL"
binary_authorization {
use_default = true
Expand All @@ -113,7 +121,7 @@ resource "google_cloud_run_v2_service" "default" {
}
client = "client-update"
client_version = "client-version-update"
template {
labels = {
label-1 = "value-update"
Expand All @@ -125,6 +133,9 @@ resource "google_cloud_run_v2_service" "default" {
max_instance_count = 2
min_instance_count = 1
}
annotations = {
generated-by = "magic-modules"
}
containers {
name = "container-update"
image = "us-docker.pkg.dev/cloudrun/container/hello"
Expand Down Expand Up @@ -156,7 +167,7 @@ resource "google_cloud_run_v2_service" "default" {
traffic {
type = "TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST"
percent = 100
tag = "traffic-tag-update"
tag = "tt-update"
}
}
Expand Down
138 changes: 138 additions & 0 deletions google/resource_sql_source_representation_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@ func resourceSQLSourceRepresentationInstance() *schema.Resource {
ValidateFunc: validateIpAddress,
Description: `The externally accessible IPv4 address for the source database server.`,
},
"ca_certificate": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The CA certificate on the external server. Include only if SSL/TLS is used on the external server.`,
},
"client_certificate": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The client certificate on the external server. Required only for server-client authentication. Include only if SSL/TLS is used on the external server.`,
},
"client_key": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The private key file for the client certificate on the external server. Required only for server-client authentication. Include only if SSL/TLS is used on the external server.`,
},
"dump_file_path": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `A file in the bucket that contains the data from the external server.`,
},
"password": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The password for the replication user account.`,
},
"port": {
Type: schema.TypeInt,
Optional: true,
Expand All @@ -72,6 +102,12 @@ func resourceSQLSourceRepresentationInstance() *schema.Resource {
Defaults to 3306.`,
Default: 3306,
},
"username": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The replication user account on the external server.`,
},

"region": {
Type: schema.TypeString,
Expand Down Expand Up @@ -340,6 +376,18 @@ func flattenSQLSourceRepresentationInstanceOnPremisesConfiguration(v interface{}
flattenSQLSourceRepresentationInstanceOnPremisesConfigurationHost(original["host"], d, config)
transformed["port"] =
flattenSQLSourceRepresentationInstanceOnPremisesConfigurationPort(original["port"], d, config)
transformed["username"] =
flattenSQLSourceRepresentationInstanceOnPremisesConfigurationUsername(original["username"], d, config)
transformed["password"] =
flattenSQLSourceRepresentationInstanceOnPremisesConfigurationPassword(original["password"], d, config)
transformed["dump_file_path"] =
flattenSQLSourceRepresentationInstanceOnPremisesConfigurationDumpFilePath(original["dumpFilePath"], d, config)
transformed["ca_certificate"] =
flattenSQLSourceRepresentationInstanceOnPremisesConfigurationCaCertificate(original["caCertificate"], d, config)
transformed["client_certificate"] =
flattenSQLSourceRepresentationInstanceOnPremisesConfigurationClientCertificate(original["clientCertificate"], d, config)
transformed["client_key"] =
flattenSQLSourceRepresentationInstanceOnPremisesConfigurationClientKey(original["clientKey"], d, config)
return []interface{}{transformed}
}
func flattenSQLSourceRepresentationInstanceOnPremisesConfigurationHost(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand All @@ -363,6 +411,30 @@ func flattenSQLSourceRepresentationInstanceOnPremisesConfigurationPort(v interfa
return v // let terraform core handle it otherwise
}

func flattenSQLSourceRepresentationInstanceOnPremisesConfigurationUsername(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenSQLSourceRepresentationInstanceOnPremisesConfigurationPassword(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenSQLSourceRepresentationInstanceOnPremisesConfigurationDumpFilePath(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenSQLSourceRepresentationInstanceOnPremisesConfigurationCaCertificate(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenSQLSourceRepresentationInstanceOnPremisesConfigurationClientCertificate(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenSQLSourceRepresentationInstanceOnPremisesConfigurationClientKey(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func expandSQLSourceRepresentationInstanceName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -391,6 +463,48 @@ func expandSQLSourceRepresentationInstanceOnPremisesConfiguration(v interface{},
transformed["port"] = transformedPort
}

transformedUsername, err := expandSQLSourceRepresentationInstanceOnPremisesConfigurationUsername(d.Get("username"), d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedUsername); val.IsValid() && !isEmptyValue(val) {
transformed["username"] = transformedUsername
}

transformedPassword, err := expandSQLSourceRepresentationInstanceOnPremisesConfigurationPassword(d.Get("password"), d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPassword); val.IsValid() && !isEmptyValue(val) {
transformed["password"] = transformedPassword
}

transformedDumpFilePath, err := expandSQLSourceRepresentationInstanceOnPremisesConfigurationDumpFilePath(d.Get("dump_file_path"), d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedDumpFilePath); val.IsValid() && !isEmptyValue(val) {
transformed["dumpFilePath"] = transformedDumpFilePath
}

transformedCaCertificate, err := expandSQLSourceRepresentationInstanceOnPremisesConfigurationCaCertificate(d.Get("ca_certificate"), d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedCaCertificate); val.IsValid() && !isEmptyValue(val) {
transformed["caCertificate"] = transformedCaCertificate
}

transformedClientCertificate, err := expandSQLSourceRepresentationInstanceOnPremisesConfigurationClientCertificate(d.Get("client_certificate"), d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedClientCertificate); val.IsValid() && !isEmptyValue(val) {
transformed["clientCertificate"] = transformedClientCertificate
}

transformedClientKey, err := expandSQLSourceRepresentationInstanceOnPremisesConfigurationClientKey(d.Get("client_key"), d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedClientKey); val.IsValid() && !isEmptyValue(val) {
transformed["clientKey"] = transformedClientKey
}

return transformed, nil
}

Expand All @@ -402,6 +516,30 @@ func expandSQLSourceRepresentationInstanceOnPremisesConfigurationPort(v interfac
return v, nil
}

func expandSQLSourceRepresentationInstanceOnPremisesConfigurationUsername(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandSQLSourceRepresentationInstanceOnPremisesConfigurationPassword(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandSQLSourceRepresentationInstanceOnPremisesConfigurationDumpFilePath(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandSQLSourceRepresentationInstanceOnPremisesConfigurationCaCertificate(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandSQLSourceRepresentationInstanceOnPremisesConfigurationClientCertificate(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandSQLSourceRepresentationInstanceOnPremisesConfigurationClientKey(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func resourceSQLSourceRepresentationInstanceEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
opc := obj["onPremisesConfiguration"].(map[string]interface{})
opc["hostPort"] = fmt.Sprintf("%v:%v", opc["host"], opc["port"])
Expand Down
Loading

0 comments on commit 17d467e

Please sign in to comment.