From 5934fedd7a47992791f47166919cd71ddc82da87 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 21 Jun 2023 18:19:08 +0000 Subject: [PATCH] add annotations (#8176) Signed-off-by: Modular Magician --- .changelog/8176.txt | 4 + google/resource_cloud_run_v2_job_test.go | 12 +++ .../cloudrunv2/resource_cloud_run_v2_job.go | 101 ++++++++++++++++-- .../resource_cloud_run_v2_service.go | 50 ++++++--- website/docs/r/cloud_run_v2_job.html.markdown | 25 ++++- .../docs/r/cloud_run_v2_service.html.markdown | 20 +++- 6 files changed, 182 insertions(+), 30 deletions(-) create mode 100644 .changelog/8176.txt diff --git a/.changelog/8176.txt b/.changelog/8176.txt new file mode 100644 index 00000000000..8a3abd8b96f --- /dev/null +++ b/.changelog/8176.txt @@ -0,0 +1,4 @@ +```release-note:enhancement + +cloudrunv2: added fields `annotations` and `template.annotations` to resource `google_cloud_run_v2_job` +``` diff --git a/google/resource_cloud_run_v2_job_test.go b/google/resource_cloud_run_v2_job_test.go index 76180717721..09f98a150ad 100644 --- a/google/resource_cloud_run_v2_job_test.go +++ b/google/resource_cloud_run_v2_job_test.go @@ -51,6 +51,9 @@ func testAccCloudRunV2Job_cloudrunv2JobFull(context map[string]interface{}) stri labels = { label-1 = "value-1" } + annotations = { + job-annotation-1 = "job-value-1" + } client = "client-1" client_version = "client-version-1" @@ -58,6 +61,9 @@ func testAccCloudRunV2Job_cloudrunv2JobFull(context map[string]interface{}) stri labels = { label-1 = "value-1" } + annotations = { + temp-annotation-1 = "temp-value-1" + } parallelism = 4 task_count = 4 template { @@ -117,6 +123,9 @@ resource "google_cloud_run_v2_job" "default" { labels = { label-1 = "value-update" } + annotations = { + job-annotation-1 = "job-value-update" + } client = "client-update" client_version = "client-version-update" @@ -124,6 +133,9 @@ resource "google_cloud_run_v2_job" "default" { labels = { label-1 = "value-update" } + annotations = { + temp-annotation-1 = "temp-value-update" + } parallelism = 2 task_count = 8 template { diff --git a/google/services/cloudrunv2/resource_cloud_run_v2_job.go b/google/services/cloudrunv2/resource_cloud_run_v2_job.go index 7ed487ee457..a350c1a3479 100644 --- a/google/services/cloudrunv2/resource_cloud_run_v2_job.go +++ b/google/services/cloudrunv2/resource_cloud_run_v2_job.go @@ -525,11 +525,27 @@ 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 API v2 does not support annotations with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected. +All system annotations in v1 now have a corresponding field in v2 ExecutionTemplate. + +This field follows Kubernetes annotations' namespacing, limits, and rules.`, + Elem: &schema.Schema{Type: schema.TypeString}, + }, "labels": { - Type: schema.TypeMap, - Optional: true, - Description: `KRM-style labels for the resource.`, - Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeMap, + Optional: true, + Description: `Unstructured key value map that can be used to organize and categorize objects. User-provided labels are shared with Google's billing system, so they can be used to filter, +or break down billing charges by team, component, environment, state, etc. For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or +https://cloud.google.com/run/docs/configuring/labels. + +Cloud Run API v2 does not support labels with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected. +All system labels in v1 now have a corresponding field in v2 ExecutionTemplate.`, + Elem: &schema.Schema{Type: schema.TypeString}, }, "parallelism": { Type: schema.TypeInt, @@ -546,6 +562,17 @@ 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 API v2 does not support annotations with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected on new resources. +All system annotations in v1 now have a corresponding field in v2 Job. + +This field follows Kubernetes annotations' namespacing, limits, and rules.`, + Elem: &schema.Schema{Type: schema.TypeString}, + }, "binary_authorization": { Type: schema.TypeList, Optional: true, @@ -577,10 +604,14 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl Description: `Arbitrary version identifier for the API client.`, }, "labels": { - Type: schema.TypeMap, - Optional: true, - Description: `KRM-style labels for the resource. User-provided labels are shared with Google's billing system, so they can be used to filter, or break down billing charges by team, component, environment, state, etc. For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or https://cloud.google.com/run/docs/configuring/labels Cloud Run will populate some labels with 'run.googleapis.com' or 'serving.knative.dev' namespaces. Those labels are read-only, and user changes will not be preserved.`, - Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeMap, + Optional: true, + Description: `Unstructured key value map that can be used to organize and categorize objects. User-provided labels are shared with Google's billing system, so they can be used to filter, or break down billing charges by team, component, +environment, state, etc. For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or https://cloud.google.com/run/docs/configuring/labels. + +Cloud Run API v2 does not support labels with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected. +All system labels in v1 now have a corresponding field in v2 Job.`, + Elem: &schema.Schema{Type: schema.TypeString}, }, "launch_stage": { Type: schema.TypeString, @@ -789,6 +820,12 @@ func resourceCloudRunV2JobCreate(d *schema.ResourceData, meta interface{}) error } else if v, ok := d.GetOkExists("labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) { obj["labels"] = labelsProp } + annotationsProp, err := expandCloudRunV2JobAnnotations(d.Get("annotations"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(annotationsProp)) && (ok || !reflect.DeepEqual(v, annotationsProp)) { + obj["annotations"] = annotationsProp + } clientProp, err := expandCloudRunV2JobClient(d.Get("client"), d, config) if err != nil { return err @@ -933,6 +970,9 @@ func resourceCloudRunV2JobRead(d *schema.ResourceData, meta interface{}) error { if err := d.Set("labels", flattenCloudRunV2JobLabels(res["labels"], d, config)); err != nil { return fmt.Errorf("Error reading Job: %s", err) } + if err := d.Set("annotations", flattenCloudRunV2JobAnnotations(res["annotations"], d, config)); err != nil { + return fmt.Errorf("Error reading Job: %s", err) + } if err := d.Set("client", flattenCloudRunV2JobClient(res["client"], d, config)); err != nil { return fmt.Errorf("Error reading Job: %s", err) } @@ -995,6 +1035,12 @@ func resourceCloudRunV2JobUpdate(d *schema.ResourceData, meta interface{}) error } else if v, ok := d.GetOkExists("labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) { obj["labels"] = labelsProp } + annotationsProp, err := expandCloudRunV2JobAnnotations(d.Get("annotations"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, annotationsProp)) { + obj["annotations"] = annotationsProp + } clientProp, err := expandCloudRunV2JobClient(d.Get("client"), d, config) if err != nil { return err @@ -1150,6 +1196,10 @@ func flattenCloudRunV2JobLabels(v interface{}, d *schema.ResourceData, config *t return v } +func flattenCloudRunV2JobAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenCloudRunV2JobClient(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { return v } @@ -1196,6 +1246,8 @@ func flattenCloudRunV2JobTemplate(v interface{}, d *schema.ResourceData, config transformed := make(map[string]interface{}) transformed["labels"] = flattenCloudRunV2JobTemplateLabels(original["labels"], d, config) + transformed["annotations"] = + flattenCloudRunV2JobTemplateAnnotations(original["annotations"], d, config) transformed["parallelism"] = flattenCloudRunV2JobTemplateParallelism(original["parallelism"], d, config) transformed["task_count"] = @@ -1208,6 +1260,10 @@ func flattenCloudRunV2JobTemplateLabels(v interface{}, d *schema.ResourceData, c return v } +func flattenCloudRunV2JobTemplateAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenCloudRunV2JobTemplateParallelism(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { // Handles the string fixed64 format if strVal, ok := v.(string); ok { @@ -2152,6 +2208,17 @@ func expandCloudRunV2JobLabels(v interface{}, d tpgresource.TerraformResourceDat return m, nil } +func expandCloudRunV2JobAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.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 expandCloudRunV2JobClient(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { return v, nil } @@ -2214,6 +2281,13 @@ func expandCloudRunV2JobTemplate(v interface{}, d tpgresource.TerraformResourceD transformed["labels"] = transformedLabels } + transformedAnnotations, err := expandCloudRunV2JobTemplateAnnotations(original["annotations"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAnnotations); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["annotations"] = transformedAnnotations + } + transformedParallelism, err := expandCloudRunV2JobTemplateParallelism(original["parallelism"], d, config) if err != nil { return nil, err @@ -2249,6 +2323,17 @@ func expandCloudRunV2JobTemplateLabels(v interface{}, d tpgresource.TerraformRes return m, nil } +func expandCloudRunV2JobTemplateAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.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 expandCloudRunV2JobTemplateParallelism(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { return v, nil } diff --git a/google/services/cloudrunv2/resource_cloud_run_v2_service.go b/google/services/cloudrunv2/resource_cloud_run_v2_service.go index f20c75a47d2..6cbd04120b7 100644 --- a/google/services/cloudrunv2/resource_cloud_run_v2_service.go +++ b/google/services/cloudrunv2/resource_cloud_run_v2_service.go @@ -63,10 +63,15 @@ func ResourceCloudRunV2Service() *schema.Resource { 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}, + 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 API v2 does not support annotations with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected. +All system annotations in v1 now have a corresponding field in v2 RevisionTemplate. + +This field follows Kubernetes annotations' namespacing, limits, and rules.`, + Elem: &schema.Schema{Type: schema.TypeString}, }, "containers": { Type: schema.TypeList, @@ -476,10 +481,14 @@ If not specified, defaults to the same value as container.ports[0].containerPort Description: `The sandbox environment to host this Revision. Possible values: ["EXECUTION_ENVIRONMENT_GEN1", "EXECUTION_ENVIRONMENT_GEN2"]`, }, "labels": { - Type: schema.TypeMap, - Optional: true, - Description: `KRM-style labels for the resource.`, - Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeMap, + Optional: true, + Description: `Unstructured key value map that can be used to organize and categorize objects. User-provided labels are shared with Google's billing system, so they can be used to filter, or break down billing charges by team, component, environment, state, etc. +For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or https://cloud.google.com/run/docs/configuring/labels. + +Cloud Run API v2 does not support labels with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected. +All system labels in v1 now have a corresponding field in v2 RevisionTemplate.`, + Elem: &schema.Schema{Type: schema.TypeString}, }, "max_instance_request_concurrency": { Type: schema.TypeInt, @@ -633,10 +642,15 @@ 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/concepts/overview/working-with-objects/annotations`, - Elem: &schema.Schema{Type: schema.TypeString}, + 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 API v2 does not support annotations with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected in new resources. +All system annotations in v1 now have a corresponding field in v2 Service. + +This field follows Kubernetes annotations' namespacing, limits, and rules.`, + Elem: &schema.Schema{Type: schema.TypeString}, }, "binary_authorization": { Type: schema.TypeList, @@ -681,10 +695,14 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl Description: `Provides the ingress settings for this Service. On output, returns the currently observed ingress settings, or INGRESS_TRAFFIC_UNSPECIFIED if no revision is active. Possible values: ["INGRESS_TRAFFIC_ALL", "INGRESS_TRAFFIC_INTERNAL_ONLY", "INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER"]`, }, "labels": { - Type: schema.TypeMap, - Optional: true, - Description: `Map of string keys and values that can be used to organize and categorize objects. User-provided labels are shared with Google's billing system, so they can be used to filter, or break down billing charges by team, component, environment, state, etc. For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or https://cloud.google.com/run/docs/configuring/labels Cloud Run will populate some labels with 'run.googleapis.com' or 'serving.knative.dev' namespaces. Those labels are read-only, and user changes will not be preserved.`, - Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeMap, + Optional: true, + Description: `Unstructured key value map that can be used to organize and categorize objects. User-provided labels are shared with Google's billing system, so they can be used to filter, or break down billing charges by team, component, +environment, state, etc. For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or https://cloud.google.com/run/docs/configuring/labels. + +Cloud Run API v2 does not support labels with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected. +All system labels in v1 now have a corresponding field in v2 Service.`, + Elem: &schema.Schema{Type: schema.TypeString}, }, "launch_stage": { Type: schema.TypeString, diff --git a/website/docs/r/cloud_run_v2_job.html.markdown b/website/docs/r/cloud_run_v2_job.html.markdown index 79ef4362c46..7f4a9638ffe 100644 --- a/website/docs/r/cloud_run_v2_job.html.markdown +++ b/website/docs/r/cloud_run_v2_job.html.markdown @@ -321,7 +321,18 @@ The following arguments are supported: * `labels` - (Optional) - KRM-style labels for the resource. + Unstructured key value map that can be used to organize and categorize objects. User-provided labels are shared with Google's billing system, so they can be used to filter, + or break down billing charges by team, component, environment, state, etc. For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or + https://cloud.google.com/run/docs/configuring/labels. + Cloud Run API v2 does not support labels with `run.googleapis.com`, `cloud.googleapis.com`, `serving.knative.dev`, or `autoscaling.knative.dev` namespaces, and they will be rejected. + All system labels in v1 now have a corresponding field in v2 ExecutionTemplate. + +* `annotations` - + (Optional) + 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 API v2 does not support annotations with `run.googleapis.com`, `cloud.googleapis.com`, `serving.knative.dev`, or `autoscaling.knative.dev` namespaces, and they will be rejected. + All system annotations in v1 now have a corresponding field in v2 ExecutionTemplate. + This field follows Kubernetes annotations' namespacing, limits, and rules. * `parallelism` - (Optional) @@ -693,7 +704,17 @@ The following arguments are supported: * `labels` - (Optional) - KRM-style labels for the resource. User-provided labels are shared with Google's billing system, so they can be used to filter, or break down billing charges by team, component, environment, state, etc. For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or https://cloud.google.com/run/docs/configuring/labels Cloud Run will populate some labels with 'run.googleapis.com' or 'serving.knative.dev' namespaces. Those labels are read-only, and user changes will not be preserved. + Unstructured key value map that can be used to organize and categorize objects. User-provided labels are shared with Google's billing system, so they can be used to filter, or break down billing charges by team, component, + environment, state, etc. For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or https://cloud.google.com/run/docs/configuring/labels. + Cloud Run API v2 does not support labels with `run.googleapis.com`, `cloud.googleapis.com`, `serving.knative.dev`, or `autoscaling.knative.dev` namespaces, and they will be rejected. + All system labels in v1 now have a corresponding field in v2 Job. + +* `annotations` - + (Optional) + 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 API v2 does not support annotations with `run.googleapis.com`, `cloud.googleapis.com`, `serving.knative.dev`, or `autoscaling.knative.dev` namespaces, and they will be rejected on new resources. + All system annotations in v1 now have a corresponding field in v2 Job. + This field follows Kubernetes annotations' namespacing, limits, and rules. * `client` - (Optional) diff --git a/website/docs/r/cloud_run_v2_service.html.markdown b/website/docs/r/cloud_run_v2_service.html.markdown index ca8ea465ca6..c53ff1521fa 100644 --- a/website/docs/r/cloud_run_v2_service.html.markdown +++ b/website/docs/r/cloud_run_v2_service.html.markdown @@ -349,11 +349,17 @@ The following arguments are supported: * `labels` - (Optional) - KRM-style labels for the resource. + Unstructured key value map that can be used to organize and categorize objects. User-provided labels are shared with Google's billing system, so they can be used to filter, or break down billing charges by team, component, environment, state, etc. + For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or https://cloud.google.com/run/docs/configuring/labels. + Cloud Run API v2 does not support labels with `run.googleapis.com`, `cloud.googleapis.com`, `serving.knative.dev`, or `autoscaling.knative.dev` namespaces, and they will be rejected. + All system labels in v1 now have a corresponding field in v2 RevisionTemplate. * `annotations` - (Optional) - KRM-style annotations for the resource. + 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 API v2 does not support annotations with `run.googleapis.com`, `cloud.googleapis.com`, `serving.knative.dev`, or `autoscaling.knative.dev` namespaces, and they will be rejected. + All system annotations in v1 now have a corresponding field in v2 RevisionTemplate. + This field follows Kubernetes annotations' namespacing, limits, and rules. * `scaling` - (Optional) @@ -789,11 +795,17 @@ The following arguments are supported: * `labels` - (Optional) - Map of string keys and values that can be used to organize and categorize objects. User-provided labels are shared with Google's billing system, so they can be used to filter, or break down billing charges by team, component, environment, state, etc. For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or https://cloud.google.com/run/docs/configuring/labels Cloud Run will populate some labels with 'run.googleapis.com' or 'serving.knative.dev' namespaces. Those labels are read-only, and user changes will not be preserved. + Unstructured key value map that can be used to organize and categorize objects. User-provided labels are shared with Google's billing system, so they can be used to filter, or break down billing charges by team, component, + environment, state, etc. For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or https://cloud.google.com/run/docs/configuring/labels. + Cloud Run API v2 does not support labels with `run.googleapis.com`, `cloud.googleapis.com`, `serving.knative.dev`, or `autoscaling.knative.dev` namespaces, and they will be rejected. + All system labels in v1 now have a corresponding field in v2 Service. * `annotations` - (Optional) - 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/concepts/overview/working-with-objects/annotations + 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 API v2 does not support annotations with `run.googleapis.com`, `cloud.googleapis.com`, `serving.knative.dev`, or `autoscaling.knative.dev` namespaces, and they will be rejected in new resources. + All system annotations in v1 now have a corresponding field in v2 Service. + This field follows Kubernetes annotations' namespacing, limits, and rules. * `client` - (Optional)