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

Add Cloud Run v2 Service urls field #20313

Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .changelog/12194.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudrunv2: added `urls` output field to `google_cloud_run_v2_service` resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package cloudrunv2_test

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand All @@ -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) },
Expand All @@ -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),
),
},
},
Expand Down
15 changes: 15 additions & 0 deletions google/services/cloudrunv2/resource_cloud_run_v2_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/cloud_run_v2_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down