From a43ba47b71b642969080f67ed161f9865889eab0 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 12 Nov 2024 15:13:13 -0800 Subject: [PATCH] Add Cloud Run v2 Service urls field (#12194) (#20313) [upstream:9958bae3d4c3148a7ba864c31e3b56d0af66669a] Signed-off-by: Modular Magician --- .changelog/12194.txt | 3 +++ ...ata_source_google_cloud_run_v2_service_test.go | 7 +++++++ .../cloudrunv2/resource_cloud_run_v2_service.go | 15 +++++++++++++++ website/docs/r/cloud_run_v2_service.html.markdown | 3 +++ 4 files changed, 28 insertions(+) create mode 100644 .changelog/12194.txt diff --git a/.changelog/12194.txt b/.changelog/12194.txt new file mode 100644 index 00000000000..cf52a6e35d9 --- /dev/null +++ b/.changelog/12194.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +cloudrunv2: added `urls` output field to `google_cloud_run_v2_service` resource +``` \ No newline at end of file diff --git a/google/services/cloudrunv2/data_source_google_cloud_run_v2_service_test.go b/google/services/cloudrunv2/data_source_google_cloud_run_v2_service_test.go index c0ff573faf9..124283370fc 100644 --- a/google/services/cloudrunv2/data_source_google_cloud_run_v2_service_test.go +++ b/google/services/cloudrunv2/data_source_google_cloud_run_v2_service_test.go @@ -4,6 +4,7 @@ package cloudrunv2_test import ( "fmt" + "regexp" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -19,6 +20,10 @@ func TestAccDataSourceGoogleCloudRunV2Service_basic(t *testing.T) { name := fmt.Sprintf("tf-test-cloud-run-v2-service-%d", acctest.RandInt(t)) location := "us-central1" id := fmt.Sprintf("projects/%s/locations/%s/services/%s", project, location, name) + deterministicURLRegex, err := regexp.Compile(fmt.Sprintf("https://%s-[0-9]+.%s.run.ap", name, location)) + if err != nil { + t.Fatalf("Failed to compile deterministic URL regex: %v", err) + } acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -30,6 +35,8 @@ func TestAccDataSourceGoogleCloudRunV2Service_basic(t *testing.T) { resource.TestCheckResourceAttr("data.google_cloud_run_v2_service.hello", "id", id), resource.TestCheckResourceAttr("data.google_cloud_run_v2_service.hello", "name", name), resource.TestCheckResourceAttr("data.google_cloud_run_v2_service.hello", "location", location), + resource.TestCheckResourceAttr("data.google_cloud_run_v2_service.hello", "urls.#", "2"), + resource.TestMatchResourceAttr("data.google_cloud_run_v2_service.hello", "urls.0", deterministicURLRegex), ), }, }, diff --git a/google/services/cloudrunv2/resource_cloud_run_v2_service.go b/google/services/cloudrunv2/resource_cloud_run_v2_service.go index dd88a68f8a5..ad54bb217f2 100644 --- a/google/services/cloudrunv2/resource_cloud_run_v2_service.go +++ b/google/services/cloudrunv2/resource_cloud_run_v2_service.go @@ -1103,6 +1103,14 @@ If reconciliation failed, trafficStatuses, observedGeneration, and latestReadyRe Computed: true, Description: `The main URI in which this Service is serving traffic.`, }, + "urls": { + Type: schema.TypeList, + Computed: true, + Description: `All URLs serving traffic for this Service.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, "deletion_protection": { Type: schema.TypeBool, Optional: true, @@ -1454,6 +1462,9 @@ func resourceCloudRunV2ServiceRead(d *schema.ResourceData, meta interface{}) err if err := d.Set("uri", flattenCloudRunV2ServiceUri(res["uri"], d, config)); err != nil { return fmt.Errorf("Error reading Service: %s", err) } + if err := d.Set("urls", flattenCloudRunV2ServiceUrls(res["urls"], d, config)); err != nil { + return fmt.Errorf("Error reading Service: %s", err) + } if err := d.Set("reconciling", flattenCloudRunV2ServiceReconciling(res["reconciling"], d, config)); err != nil { return fmt.Errorf("Error reading Service: %s", err) } @@ -3122,6 +3133,10 @@ func flattenCloudRunV2ServiceUri(v interface{}, d *schema.ResourceData, config * return v } +func flattenCloudRunV2ServiceUrls(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenCloudRunV2ServiceReconciling(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { return v } diff --git a/website/docs/r/cloud_run_v2_service.html.markdown b/website/docs/r/cloud_run_v2_service.html.markdown index 191846305d9..496316fc2de 100644 --- a/website/docs/r/cloud_run_v2_service.html.markdown +++ b/website/docs/r/cloud_run_v2_service.html.markdown @@ -1321,6 +1321,9 @@ In addition to the arguments listed above, the following computed attributes are * `uri` - The main URI in which this Service is serving traffic. +* `urls` - + All URLs serving traffic for this Service. + * `reconciling` - Returns true if the Service is currently being acted upon by the system to bring it into the desired state. When a new Service is created, or an existing one is updated, Cloud Run will asynchronously perform all necessary steps to bring the Service to the desired serving state. This process is called reconciliation. While reconciliation is in process, observedGeneration, latest_ready_revison, trafficStatuses, and uri will have transient values that might mismatch the intended state: Once reconciliation is over (and this field is false), there are two possible outcomes: reconciliation succeeded and the serving state matches the Service, or there was an error, and reconciliation failed. This state can be found in terminalCondition.state.