Skip to content

Commit 86f5dfe

Browse files
authored
Adds RolloutKind provider for SaasRuntime (#15124)
1 parent fbb2682 commit 86f5dfe

File tree

3 files changed

+308
-0
lines changed

3 files changed

+308
-0
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Copyright 2025 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
name: RolloutKind
16+
description: A RolloutKind is a reusable configuration resource that defines the policies, strategies, and targeting for Rollout operations. It acts as a template for repeatable Rollouts, providing guardrails and ensuring that updates are executed in a consistent manner across a fleet of Units.
17+
base_url: projects/{{project}}/locations/{{location}}/rolloutKinds
18+
update_mask: true
19+
self_link: projects/{{project}}/locations/{{location}}/rolloutKinds/{{rollout_kind_id}}
20+
create_url: projects/{{project}}/locations/{{location}}/rolloutKinds?rolloutKindId={{rollout_kind_id}}
21+
update_verb: PATCH
22+
id_format: projects/{{project}}/locations/{{location}}/rolloutKinds/{{rollout_kind_id}}
23+
import_format:
24+
- projects/{{project}}/locations/{{location}}/rolloutKinds/{{rollout_kind_id}}
25+
min_version: beta
26+
examples:
27+
- name: saas_runtime_rollout_kind_basic
28+
primary_resource_id: "example"
29+
min_version: "beta"
30+
vars:
31+
saas_name: example-saas
32+
unitkind_name: example-unitkind
33+
rolloutkind_name: example-rolloutkind
34+
bootstrap_iam:
35+
- member: "serviceAccount:service-{project_number}@gcp-sa-saasservicemgmt.iam.gserviceaccount.com"
36+
role: "roles/saasservicemgmt.serviceAgent"
37+
autogen_async: false
38+
autogen_status: Um9sbG91dEtpbmQ=
39+
parameters:
40+
- name: location
41+
type: String
42+
description: Resource ID segment making up resource `name`. It identifies the resource within its parent collection as described in https://google.aip.dev/122.
43+
immutable: true
44+
url_param_only: true
45+
required: true
46+
- name: rolloutKindId
47+
type: String
48+
description: The ID value for the new rollout kind.
49+
immutable: true
50+
url_param_only: true
51+
required: true
52+
properties:
53+
- name: annotations
54+
type: KeyValueAnnotations
55+
description: |-
56+
Annotations is an unstructured key-value map stored with a resource that
57+
may be set by external tools to store and retrieve arbitrary metadata.
58+
They are not queryable and should be preserved when modifying objects.
59+
60+
More info: https://kubernetes.io/docs/user-guide/annotations
61+
- name: createTime
62+
type: String
63+
description: The timestamp when the resource was created.
64+
output: true
65+
- name: errorBudget
66+
type: NestedObject
67+
description: |-
68+
The configuration for error budget. If the number of failed units exceeds
69+
max(allowed_count, allowed_ratio * total_units), the rollout will be paused.
70+
properties:
71+
- name: allowedCount
72+
type: Integer
73+
description: |-
74+
The maximum number of failed units allowed in a location without pausing
75+
the rollout.
76+
- name: allowedPercentage
77+
type: Integer
78+
description: |-
79+
The maximum percentage of units allowed to fail (0, 100] within a location
80+
without pausing the rollout.
81+
- name: labels
82+
type: KeyValueLabels
83+
description: |-
84+
The labels on the resource, which can be used for categorization.
85+
similar to Kubernetes resource labels.
86+
- name: name
87+
type: String
88+
description: |-
89+
Identifier. The resource name (full URI of the resource) following the standard naming
90+
scheme:
91+
92+
"projects/{project}/locations/{location}/rolloutKinds/{rollout_kind_id}"
93+
output: true
94+
- name: rolloutOrchestrationStrategy
95+
type: String
96+
description: |-
97+
The strategy used for executing a Rollout. This is a required field.
98+
99+
There are two supported values strategies which are used to control a rollout.
100+
- "Google.Cloud.Simple.AllAtOnce"
101+
- "Google.Cloud.Simple.OneLocationAtATime"
102+
103+
A rollout with one of these simple strategies will rollout across
104+
all locations defined in the associated UnitKind's Saas Locations.
105+
- name: uid
106+
type: String
107+
description: |-
108+
The unique identifier of the resource. UID is unique in the time
109+
and space for this resource within the scope of the service. It is
110+
typically generated by the server on successful creation of a resource
111+
and must not be changed. UID is used to uniquely identify resources
112+
with resource name reuses. This should be a UUID4.
113+
output: true
114+
- name: unitFilter
115+
type: String
116+
description: |-
117+
CEL(https://github.com/google/cel-spec) formatted filter string against
118+
Unit. The filter will be applied to determine the eligible unit population.
119+
This filter can only reduce, but not expand the scope of the rollout.
120+
- name: unitKind
121+
type: String
122+
description: |-
123+
UnitKind that this rollout kind corresponds to. Rollouts stemming from this
124+
rollout kind will target the units of this unit kind. In other words, this
125+
defines the population of target units to be upgraded by rollouts.
126+
immutable: true
127+
required: true
128+
- name: updateTime
129+
type: String
130+
description: |-
131+
The timestamp when the resource was last updated. Any
132+
change to the resource made by users must refresh this value.
133+
Changes to a resource made by the service should refresh this value.
134+
output: true
135+
- name: updateUnitKindStrategy
136+
type: Enum
137+
description: |-
138+
The config for updating the unit kind. By default, the unit kind will be
139+
updated on the rollout start.
140+
Possible values:
141+
UPDATE_UNIT_KIND_STRATEGY_ON_START
142+
UPDATE_UNIT_KIND_STRATEGY_NEVER
143+
enum_values:
144+
- "UPDATE_UNIT_KIND_STRATEGY_ON_START"
145+
- "UPDATE_UNIT_KIND_STRATEGY_NEVER"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
resource "google_saas_runtime_saas" "example_saas" {
2+
provider = google-beta
3+
saas_id = "{{index $.Vars "saas_name"}}"
4+
location = "global"
5+
6+
locations {
7+
name = "us-central1"
8+
}
9+
}
10+
11+
resource "google_saas_runtime_unit_kind" "example_unitkind" {
12+
provider = google-beta
13+
location = "global"
14+
unit_kind_id = "{{index $.Vars "unitkind_name"}}"
15+
saas = google_saas_runtime_saas.example_saas.id
16+
}
17+
18+
resource "google_saas_runtime_rollout_kind" "{{$.PrimaryResourceId}}" {
19+
provider = google-beta
20+
location = "global"
21+
rollout_kind_id = "{{index $.Vars "rolloutkind_name"}}"
22+
unit_kind = google_saas_runtime_unit_kind.example_unitkind.id
23+
24+
rollout_orchestration_strategy = "Google.Cloud.Simple.OneLocationAtATime"
25+
error_budget {
26+
allowed_count = 1
27+
}
28+
unit_filter = "unit.labels['key1'] == 'value1'"
29+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package saasruntime_test
2+
3+
{{ if ne $.TargetVersionName `ga` -}}
4+
5+
import (
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
10+
11+
"github.com/hashicorp/terraform-provider-google/google/acctest"
12+
)
13+
14+
func TestAccSaasRuntimeRolloutKind_update(t *testing.T) {
15+
t.Parallel()
16+
acctest.BootstrapIamMembers(t, []acctest.IamMember{
17+
{
18+
Member: "serviceAccount:service-{project_number}@gcp-sa-saasservicemgmt.iam.gserviceaccount.com",
19+
Role: "roles/saasservicemgmt.serviceAgent",
20+
},
21+
})
22+
23+
context := map[string]interface{}{
24+
"random_suffix": acctest.RandString(t, 10),
25+
}
26+
27+
acctest.VcrTest(t, resource.TestCase{
28+
PreCheck: func() { acctest.AccTestPreCheck(t) },
29+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
30+
Steps: []resource.TestStep{
31+
{
32+
Config: testAccSaasRuntimeRolloutKind_basic(context),
33+
},
34+
{
35+
ResourceName: "google_saas_runtime_rollout_kind.example",
36+
ImportState: true,
37+
ImportStateVerify: true,
38+
ImportStateVerifyIgnore: []string{"annotations", "labels", "location", "rollout_kind_id", "terraform_labels"},
39+
},
40+
{
41+
Config: testAccSaasRuntimeRolloutKind_update(context),
42+
ConfigPlanChecks: resource.ConfigPlanChecks{
43+
PreApply: []plancheck.PlanCheck{
44+
plancheck.ExpectResourceAction("google_saas_runtime_rollout_kind.example", plancheck.ResourceActionUpdate),
45+
},
46+
},
47+
},
48+
{
49+
ResourceName: "google_saas_runtime_rollout_kind.example",
50+
ImportState: true,
51+
ImportStateVerify: true,
52+
ImportStateVerifyIgnore: []string{"annotations", "labels", "location", "rollout_kind_id", "terraform_labels"},
53+
},
54+
},
55+
})
56+
}
57+
58+
func testAccSaasRuntimeRolloutKind_basic(context map[string]interface{}) string {
59+
return acctest.Nprintf(`
60+
resource "google_saas_runtime_saas" "example_saas" {
61+
provider = google-beta
62+
saas_id = "tf-test-example-saas%{random_suffix}"
63+
location = "global"
64+
65+
locations {
66+
name = "us-central1"
67+
}
68+
}
69+
70+
resource "google_saas_runtime_unit_kind" "example_unitkind" {
71+
provider = google-beta
72+
location = "global"
73+
unit_kind_id = "tf-test-example-unitkind%{random_suffix}"
74+
saas = google_saas_runtime_saas.example_saas.id
75+
}
76+
77+
resource "google_saas_runtime_rollout_kind" "example" {
78+
provider = google-beta
79+
location = "global"
80+
rollout_kind_id = "tf-test-example-rolloutkind%{random_suffix}"
81+
unit_kind = google_saas_runtime_unit_kind.example_unitkind.id
82+
83+
rollout_orchestration_strategy = "Google.Cloud.Simple.OneLocationAtATime"
84+
error_budget {
85+
allowed_count = 1
86+
}
87+
update_unit_kind_strategy = "UPDATE_UNIT_KIND_STRATEGY_ON_START"
88+
unit_filter = "unit.labels['key1'] == 'value1'"
89+
}
90+
`, context)
91+
}
92+
93+
func testAccSaasRuntimeRolloutKind_update(context map[string]interface{}) string {
94+
return acctest.Nprintf(`
95+
resource "google_saas_runtime_saas" "example_saas" {
96+
provider = google-beta
97+
saas_id = "tf-test-example-saas%{random_suffix}"
98+
location = "global"
99+
100+
locations {
101+
name = "us-central1"
102+
}
103+
}
104+
105+
resource "google_saas_runtime_unit_kind" "example_unitkind" {
106+
provider = google-beta
107+
location = "global"
108+
unit_kind_id = "tf-test-example-unitkind%{random_suffix}"
109+
saas = google_saas_runtime_saas.example_saas.id
110+
}
111+
112+
resource "google_saas_runtime_rollout_kind" "example" {
113+
provider = google-beta
114+
location = "global"
115+
rollout_kind_id = "tf-test-example-rolloutkind%{random_suffix}"
116+
unit_kind = google_saas_runtime_unit_kind.example_unitkind.id
117+
118+
rollout_orchestration_strategy = "Google.Cloud.Simple.AllAtOnce"
119+
error_budget {
120+
allowed_percentage = 10
121+
}
122+
unit_filter = "unit.labels['key2'] == 'value2'"
123+
update_unit_kind_strategy = "UPDATE_UNIT_KIND_STRATEGY_NEVER"
124+
labels = {
125+
updated = "true"
126+
}
127+
annotations = {
128+
"annotation-one": "bar"
129+
}
130+
}
131+
`, context)
132+
}
133+
134+
{{- end }}

0 commit comments

Comments
 (0)