Skip to content

Commit

Permalink
Support service-level min instances in Cloud Run v2 services. (Google…
Browse files Browse the repository at this point in the history
  • Loading branch information
bskaplan authored and balanaguharsha committed May 2, 2024
1 parent 6032a70 commit 85436c7
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mmv1/products/cloudrunv2/Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ properties:
One or more custom audiences that you want this service to support. Specify each custom audience as the full URL in a string. The custom audiences are encoded in the token and used to authenticate requests.
For more information, see https://cloud.google.com/run/docs/configuring/custom-audiences.
item_type: Api::Type::String
- !ruby/object:Api::Type::NestedObject
name: 'scaling'
min_version: beta
description: |
Scaling settings that apply to the whole service
properties:
- !ruby/object:Api::Type::Integer
name: 'minInstanceCount'
description: |
Minimum number of instances for the service, to be divided among all revisions receiving traffic.
- !ruby/object:Api::Type::NestedObject
name: 'template'
required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,107 @@ func TestAccCloudRunV2Service_cloudrunv2ServiceAttributionLabel(t *testing.T) {
})
}

<% unless version == 'ga' -%>
func TestAccCloudRunV2Service_cloudrunv2ServiceWithServiceMinInstances(t *testing.T) {
t.Parallel()
context := map[string]interface{} {
"random_suffix" : acctest.RandString(t, 10),
}
acctest.VcrTest(t, resource.TestCase {
PreCheck: func() { acctest.AccTestPreCheck(t)},
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckCloudRunV2ServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccCloudRunV2Service_cloudrunv2ServiceWithMinInstances(context),
},
{
ResourceName: "google_cloud_run_v2_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "location", "annotations", "labels", "terraform_labels", "launch_stage"},
},
{
Config: testAccCloudRunV2Service_cloudrunv2ServiceWithNoMinInstances(context),
},
{
ResourceName: "google_cloud_run_v2_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "location", "annotations", "labels", "terraform_labels", "launch_stage"},
},

},
})
}

func testAccCloudRunV2Service_cloudrunv2ServiceWithNoMinInstances(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_cloud_run_v2_service" "default" {
name = "tf-test-cloudrun-service%{random_suffix}"
description = "description creating"
location = "us-central1"
launch_stage = "BETA"
annotations = {
generated-by = "magic-modules"
}
ingress = "INGRESS_TRAFFIC_ALL"
labels = {
label-1 = "value-1"
}
client = "client-1"
client_version = "client-version-1"
template {
containers {
name = "container-1"
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
}
lifecycle {
ignore_changes = [
launch_stage,
]
}
}

`, context)
}
func testAccCloudRunV2Service_cloudrunv2ServiceWithMinInstances(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_cloud_run_v2_service" "default" {
name = "tf-test-cloudrun-service%{random_suffix}"
description = "description creating"
location = "us-central1"
launch_stage = "BETA"
annotations = {
generated-by = "magic-modules"
}
ingress = "INGRESS_TRAFFIC_ALL"
labels = {
label-1 = "value-1"
}
client = "client-1"
client_version = "client-version-1"
scaling {
min_instance_count = 1
}
template {
containers {
name = "container-1"
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
}
lifecycle {
ignore_changes = [
launch_stage,
]
}
}

`, context)
}
<% end -%>

func testAccCloudRunV2Service_cloudrunv2ServiceWithAttributionLabel(context map[string]interface{}) string {
return acctest.Nprintf(`
provider "google" {
Expand Down

0 comments on commit 85436c7

Please sign in to comment.