Skip to content

Commit c7adbd3

Browse files
Add Cloud Run v2 Service urls field (#12194) (#8686)
[upstream:9958bae3d4c3148a7ba864c31e3b56d0af66669a] Signed-off-by: Modular Magician <[email protected]>
1 parent bcfa3cd commit c7adbd3

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

.changelog/12194.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
cloudrunv2: added `urls` output field to `google_cloud_run_v2_service` resource
3+
```

google-beta/services/cloudrunv2/data_source_google_cloud_run_v2_service_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package cloudrunv2_test
44

55
import (
66
"fmt"
7+
"regexp"
78
"testing"
89

910
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -19,6 +20,10 @@ func TestAccDataSourceGoogleCloudRunV2Service_basic(t *testing.T) {
1920
name := fmt.Sprintf("tf-test-cloud-run-v2-service-%d", acctest.RandInt(t))
2021
location := "us-central1"
2122
id := fmt.Sprintf("projects/%s/locations/%s/services/%s", project, location, name)
23+
deterministicURLRegex, err := regexp.Compile(fmt.Sprintf("https://%s-[0-9]+.%s.run.ap", name, location))
24+
if err != nil {
25+
t.Fatalf("Failed to compile deterministic URL regex: %v", err)
26+
}
2227

2328
acctest.VcrTest(t, resource.TestCase{
2429
PreCheck: func() { acctest.AccTestPreCheck(t) },
@@ -30,6 +35,8 @@ func TestAccDataSourceGoogleCloudRunV2Service_basic(t *testing.T) {
3035
resource.TestCheckResourceAttr("data.google_cloud_run_v2_service.hello", "id", id),
3136
resource.TestCheckResourceAttr("data.google_cloud_run_v2_service.hello", "name", name),
3237
resource.TestCheckResourceAttr("data.google_cloud_run_v2_service.hello", "location", location),
38+
resource.TestCheckResourceAttr("data.google_cloud_run_v2_service.hello", "urls.#", "2"),
39+
resource.TestMatchResourceAttr("data.google_cloud_run_v2_service.hello", "urls.0", deterministicURLRegex),
3340
),
3441
},
3542
},

google-beta/services/cloudrunv2/resource_cloud_run_v2_service.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,14 @@ If reconciliation failed, trafficStatuses, observedGeneration, and latestReadyRe
11471147
Computed: true,
11481148
Description: `The main URI in which this Service is serving traffic.`,
11491149
},
1150+
"urls": {
1151+
Type: schema.TypeList,
1152+
Computed: true,
1153+
Description: `All URLs serving traffic for this Service.`,
1154+
Elem: &schema.Schema{
1155+
Type: schema.TypeString,
1156+
},
1157+
},
11501158
"deletion_protection": {
11511159
Type: schema.TypeBool,
11521160
Optional: true,
@@ -1507,6 +1515,9 @@ func resourceCloudRunV2ServiceRead(d *schema.ResourceData, meta interface{}) err
15071515
if err := d.Set("uri", flattenCloudRunV2ServiceUri(res["uri"], d, config)); err != nil {
15081516
return fmt.Errorf("Error reading Service: %s", err)
15091517
}
1518+
if err := d.Set("urls", flattenCloudRunV2ServiceUrls(res["urls"], d, config)); err != nil {
1519+
return fmt.Errorf("Error reading Service: %s", err)
1520+
}
15101521
if err := d.Set("reconciling", flattenCloudRunV2ServiceReconciling(res["reconciling"], d, config)); err != nil {
15111522
return fmt.Errorf("Error reading Service: %s", err)
15121523
}
@@ -3229,6 +3240,10 @@ func flattenCloudRunV2ServiceUri(v interface{}, d *schema.ResourceData, config *
32293240
return v
32303241
}
32313242

3243+
func flattenCloudRunV2ServiceUrls(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
3244+
return v
3245+
}
3246+
32323247
func flattenCloudRunV2ServiceReconciling(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
32333248
return v
32343249
}

website/docs/r/cloud_run_v2_service.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,9 @@ In addition to the arguments listed above, the following computed attributes are
13211321
* `uri` -
13221322
The main URI in which this Service is serving traffic.
13231323

1324+
* `urls` -
1325+
All URLs serving traffic for this Service.
1326+
13241327
* `reconciling` -
13251328
Returns true if the Service is currently being acted upon by the system to bring it into the desired state.
13261329
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.

0 commit comments

Comments
 (0)