Skip to content

Commit 06d0745

Browse files
authored
Add provider for SaaS Runtime Tenant resource (#15277)
1 parent 3b7746b commit 06d0745

File tree

3 files changed

+237
-0
lines changed

3 files changed

+237
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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: Tenant
16+
description: The Tenant resource represents the service producer's view of a service instance created for a consumer. It enables the association between the service producer's managed resources and the end consumer.
17+
base_url: projects/{{project}}/locations/{{location}}/tenants
18+
update_mask: true
19+
self_link: projects/{{project}}/locations/{{location}}/tenants/{{tenant_id}}
20+
create_url: projects/{{project}}/locations/{{location}}/tenants?tenantId={{tenant_id}}
21+
update_verb: PATCH
22+
id_format: projects/{{project}}/locations/{{location}}/tenants/{{tenant_id}}
23+
import_format:
24+
- projects/{{project}}/locations/{{location}}/tenants/{{tenant_id}}
25+
min_version: beta
26+
examples:
27+
- name: saas_runtime_tenant_basic
28+
primary_resource_id: "example"
29+
min_version: "beta"
30+
vars:
31+
saas_name: example-saas
32+
tenant_name: example-tenant
33+
test_env_vars:
34+
project: "PROJECT_NAME"
35+
bootstrap_iam:
36+
- member: "serviceAccount:service-{project_number}@gcp-sa-saasservicemgmt.iam.gserviceaccount.com"
37+
role: "roles/saasservicemgmt.serviceAgent"
38+
autogen_async: false
39+
autogen_status: VGVuYW50
40+
parameters:
41+
- name: location
42+
type: String
43+
description: Resource ID segment making up resource `name`. It identifies the resource within its parent collection as described in https://google.aip.dev/122.
44+
immutable: true
45+
url_param_only: true
46+
required: true
47+
- name: tenantId
48+
type: String
49+
description: The ID value for the new tenant.
50+
immutable: true
51+
url_param_only: true
52+
required: true
53+
properties:
54+
- name: annotations
55+
type: KeyValueAnnotations
56+
description: |-
57+
Annotations is an unstructured key-value map stored with a resource that
58+
may be set by external tools to store and retrieve arbitrary metadata.
59+
They are not queryable and should be preserved when modifying objects.
60+
61+
More info: https://kubernetes.io/docs/user-guide/annotations
62+
- name: consumerResource
63+
type: String
64+
description: |-
65+
A reference to the consumer resource this SaaS Tenant is representing.
66+
67+
The relationship with a consumer resource can be used by SaaS Runtime for
68+
retrieving consumer-defined settings and policies such as maintenance
69+
policies (using Unified Maintenance Policy API).
70+
immutable: true
71+
- name: createTime
72+
type: String
73+
description: The timestamp when the resource was created.
74+
output: true
75+
- name: labels
76+
type: KeyValueLabels
77+
description: |-
78+
The labels on the resource, which can be used for categorization.
79+
similar to Kubernetes resource labels.
80+
- name: name
81+
type: String
82+
description: |-
83+
Identifier. The resource name (full URI of the resource) following the standard naming
84+
scheme:
85+
86+
"projects/{project}/locations/{location}/tenants/{tenant}"
87+
output: true
88+
- name: saas
89+
type: String
90+
description: |-
91+
A reference to the Saas that defines the product (managed service) that
92+
the producer wants to manage with SaaS Runtime. Part of the
93+
SaaS Runtime common data model.
94+
immutable: true
95+
required: true
96+
- name: uid
97+
type: String
98+
description: |-
99+
The unique identifier of the resource. UID is unique in the time
100+
and space for this resource within the scope of the service. It is
101+
typically generated by the server on successful creation of a resource
102+
and must not be changed. UID is used to uniquely identify resources
103+
with resource name reuses. This should be a UUID4.
104+
output: true
105+
- name: updateTime
106+
type: String
107+
description: |-
108+
The timestamp when the resource was last updated. Any
109+
change to the resource made by users must refresh this value.
110+
Changes to a resource made by the service should refresh this value.
111+
output: true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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_tenant" "{{$.PrimaryResourceId}}" {
12+
provider = google-beta
13+
location = "global"
14+
tenant_id = "{{index $.Vars "tenant_name"}}"
15+
saas = google_saas_runtime_saas.example_saas.id
16+
consumer_resource = "//compute.googleapis.com/projects/example-project/zones/us-central1-a/instances/example-instance"
17+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
"github.com/hashicorp/terraform-provider-google/google/envvar"
13+
)
14+
15+
func TestAccSaasRuntimeTenant_update(t *testing.T) {
16+
t.Parallel()
17+
acctest.BootstrapIamMembers(t, []acctest.IamMember{
18+
{
19+
Member: "serviceAccount:service-{project_number}@gcp-sa-saasservicemgmt.iam.gserviceaccount.com",
20+
Role: "roles/saasservicemgmt.serviceAgent",
21+
},
22+
})
23+
24+
context := map[string]interface{}{
25+
"project": envvar.GetTestProjectFromEnv(),
26+
"random_suffix": acctest.RandString(t, 10),
27+
}
28+
29+
acctest.VcrTest(t, resource.TestCase{
30+
PreCheck: func() { acctest.AccTestPreCheck(t) },
31+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
32+
Steps: []resource.TestStep{
33+
{
34+
Config: testAccSaasRuntimeTenant_basic(context),
35+
},
36+
{
37+
ResourceName: "google_saas_runtime_tenant.example",
38+
ImportState: true,
39+
ImportStateVerify: true,
40+
ImportStateVerifyIgnore: []string{"annotations", "labels", "location", "tenant_id", "terraform_labels"},
41+
},
42+
{
43+
Config: testAccSaasRuntimeTenant_update(context),
44+
ConfigPlanChecks: resource.ConfigPlanChecks{
45+
PreApply: []plancheck.PlanCheck{
46+
plancheck.ExpectResourceAction("google_saas_runtime_tenant.example", plancheck.ResourceActionUpdate),
47+
},
48+
},
49+
},
50+
{
51+
ResourceName: "google_saas_runtime_tenant.example",
52+
ImportState: true,
53+
ImportStateVerify: true,
54+
ImportStateVerifyIgnore: []string{"annotations", "labels", "location", "tenant_id", "terraform_labels"},
55+
},
56+
},
57+
})
58+
}
59+
60+
func testAccSaasRuntimeTenant_basic(context map[string]interface{}) string {
61+
return acctest.Nprintf(`
62+
resource "google_saas_runtime_saas" "example_saas" {
63+
provider = google-beta
64+
saas_id = "tf-test-example-saas%{random_suffix}"
65+
location = "global"
66+
67+
locations {
68+
name = "us-central1"
69+
}
70+
}
71+
72+
resource "google_saas_runtime_tenant" "example" {
73+
provider = google-beta
74+
location = "global"
75+
tenant_id = "tf-test-example-tenant%{random_suffix}"
76+
saas = google_saas_runtime_saas.example_saas.id
77+
consumer_resource = "//compute.googleapis.com/projects/example-project/zones/us-central1-a/instances/example-instance"
78+
}
79+
`, context)
80+
}
81+
82+
func testAccSaasRuntimeTenant_update(context map[string]interface{}) string {
83+
return acctest.Nprintf(`
84+
resource "google_saas_runtime_saas" "example_saas" {
85+
provider = google-beta
86+
saas_id = "tf-test-example-saas%{random_suffix}"
87+
location = "global"
88+
89+
locations {
90+
name = "us-central1"
91+
}
92+
}
93+
94+
resource "google_saas_runtime_tenant" "example" {
95+
provider = google-beta
96+
location = "global"
97+
tenant_id = "tf-test-example-tenant%{random_suffix}"
98+
saas = google_saas_runtime_saas.example_saas.id
99+
consumer_resource = "//compute.googleapis.com/projects/example-project/zones/us-central1-a/instances/example-instance"
100+
labels = {
101+
"label-one": "foo"
102+
}
103+
annotations = {
104+
"annotation-one": "bar"
105+
}
106+
}
107+
`, context)
108+
}
109+
{{- end }}

0 commit comments

Comments
 (0)