Skip to content

Commit b0a98d6

Browse files
yerniyazNDawid212
authored andcommitted
Adding magic module config for osconfigv2 (GoogleCloudPlatform#13120)
1 parent b30b32c commit b0a98d6

File tree

6 files changed

+1473
-0
lines changed

6 files changed

+1473
-0
lines changed

mmv1/products/osconfigv2/PolicyOrchestrator.yaml

+1,243
Large diffs are not rendered by default.

mmv1/products/osconfigv2/product.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2024 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: 'OSConfigV2'
16+
display_name: 'OS Config v2'
17+
versions:
18+
- name: 'ga'
19+
base_url: 'https://osconfig.googleapis.com/v2/'
20+
- name: 'beta'
21+
base_url: 'https://osconfig.googleapis.com/v2beta/'
22+
scopes:
23+
- 'https://www.googleapis.com/auth/cloud-platform'
24+
- 'https://www.googleapis.com/auth/compute'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
resource "google_os_config_v2_policy_orchestrator" "{{$.PrimaryResourceId}}" {
2+
provider = google-beta
3+
policy_orchestrator_id = "{{index $.Vars "policy_orchestrator_id"}}"
4+
5+
state = "ACTIVE"
6+
action = "UPSERT"
7+
8+
orchestrated_resource {
9+
id = "{{index $.Vars "orchestrated_resource_id"}}"
10+
os_policy_assignment_v1_payload {
11+
os_policies {
12+
id = "{{index $.Vars "os_policy_id"}}"
13+
mode = "VALIDATION"
14+
resource_groups {
15+
resources {
16+
id = "resource-tf"
17+
file {
18+
content = "file-content-tf"
19+
path = "file-path-tf-1"
20+
state = "PRESENT"
21+
}
22+
}
23+
}
24+
}
25+
instance_filter {
26+
inventories {
27+
os_short_name = "windows-10"
28+
}
29+
}
30+
rollout {
31+
disruption_budget {
32+
percent = 100
33+
}
34+
min_wait_duration = "60s"
35+
}
36+
}
37+
}
38+
labels = {
39+
state = "active"
40+
}
41+
}

mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt

+5
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ var ServicesListBeta = mapOf(
601601
"displayName" to "Osconfig",
602602
"path" to "./google-beta/services/osconfig"
603603
),
604+
"osconfigv2" to mapOf(
605+
"name" to "osconfigv2",
606+
"displayName" to "Osconfigv2",
607+
"path" to "./google-beta/services/osconfigv2"
608+
),
604609
"oslogin" to mapOf(
605610
"name" to "oslogin",
606611
"displayName" to "Oslogin",

mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt

+5
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,11 @@ var ServicesListGa = mapOf(
596596
"displayName" to "Osconfig",
597597
"path" to "./google/services/osconfig"
598598
),
599+
"osconfigv2" to mapOf(
600+
"name" to "osconfigv2",
601+
"displayName" to "Osconfigv2",
602+
"path" to "./google/services/osconfigv2"
603+
),
599604
"oslogin" to mapOf(
600605
"name" to "oslogin",
601606
"displayName" to "Oslogin",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package osconfigv2_test
2+
{{- if ne $.TargetVersionName "ga" }}
3+
4+
import (
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
8+
"github.com/hashicorp/terraform-provider-google/google/acctest"
9+
"github.com/hashicorp/terraform-provider-google/google/envvar"
10+
)
11+
12+
func TestAccOSConfigV2PolicyOrchestrator_basic(t *testing.T) {
13+
t.Parallel()
14+
15+
acctest.BootstrapIamMembers(t, []acctest.IamMember{
16+
{
17+
Member: "serviceAccount:service-{project_number}@gcp-sa-osconfig.iam.gserviceaccount.com",
18+
Role: "roles/osconfig.serviceAgent",
19+
},
20+
{
21+
Member: "serviceAccount:service-{project_number}@gcp-sa-osconfig-rollout.iam.gserviceaccount.com",
22+
Role: "roles/osconfig.rolloutServiceAgent",
23+
},
24+
{
25+
Member: "serviceAccount:service-{project_number}@gcp-sa-progrollout.iam.gserviceaccount.com",
26+
Role: "roles/progressiverollout.serviceAgent",
27+
},
28+
})
29+
30+
context := map[string]interface{}{
31+
"project": envvar.GetTestProjectFromEnv(),
32+
"project_number": envvar.GetTestProjectNumberFromEnv(),
33+
"random_suffix": acctest.RandString(t, 10),
34+
}
35+
36+
37+
acctest.VcrTest(t, resource.TestCase{
38+
PreCheck: func() { acctest.AccTestPreCheck(t) },
39+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
40+
Steps: []resource.TestStep{
41+
{
42+
Config: testAccOSConfigV2PolicyOrchestrator_basic(context),
43+
},
44+
{
45+
ResourceName: "google_os_config_v2_policy_orchestrator.policy_orchestrator",
46+
ImportState: true,
47+
ImportStateVerify: true,
48+
ImportStateVerifyIgnore: []string{"labels", "policy_orchestrator_id", "terraform_labels"},
49+
},
50+
{
51+
Config: testAccOSConfigV2PolicyOrchestrator_update(context),
52+
},
53+
{
54+
ResourceName: "google_os_config_v2_policy_orchestrator.policy_orchestrator",
55+
ImportState: true,
56+
ImportStateVerify: true,
57+
ImportStateVerifyIgnore: []string{"labels", "policy_orchestrator_id", "terraform_labels"},
58+
},
59+
},
60+
})
61+
}
62+
63+
func testAccOSConfigV2PolicyOrchestrator_basic(context map[string]interface{}) string {
64+
return acctest.Nprintf(`
65+
resource "google_os_config_v2_policy_orchestrator" "policy_orchestrator" {
66+
provider = google-beta
67+
policy_orchestrator_id = "tf-test-test-po%{random_suffix}"
68+
69+
state = "ACTIVE"
70+
action = "UPSERT"
71+
72+
orchestrated_resource {
73+
id = "tf-test-test-orchestrated-resource%{random_suffix}"
74+
os_policy_assignment_v1_payload {
75+
os_policies {
76+
id = "tf-test-test-os-policy%{random_suffix}"
77+
mode = "VALIDATION"
78+
resource_groups {
79+
resources {
80+
id = "resource-tf"
81+
file {
82+
content = "file-content-tf"
83+
path = "file-path-tf-1"
84+
state = "PRESENT"
85+
}
86+
}
87+
}
88+
}
89+
instance_filter {
90+
inventories {
91+
os_short_name = "windows-10"
92+
}
93+
}
94+
rollout {
95+
disruption_budget {
96+
percent = 100
97+
}
98+
min_wait_duration = "60s"
99+
}
100+
}
101+
}
102+
labels = {
103+
state = "active"
104+
}
105+
}
106+
`, context)
107+
}
108+
109+
func testAccOSConfigV2PolicyOrchestrator_update(context map[string]interface{}) string {
110+
return acctest.Nprintf(`
111+
resource "google_os_config_v2_policy_orchestrator" "policy_orchestrator" {
112+
provider = google-beta
113+
policy_orchestrator_id = "tf-test-test-po%{random_suffix}"
114+
115+
state = "STOPPED"
116+
action = "DELETE"
117+
description = "Updated description"
118+
119+
orchestrated_resource {
120+
id = "tf-test-test-orchestrated-resource%{random_suffix}"
121+
os_policy_assignment_v1_payload {
122+
os_policies {
123+
id = "tf-test-test-os-policy%{random_suffix}"
124+
mode = "VALIDATION"
125+
resource_groups {
126+
resources {
127+
id = "resource-tf"
128+
file {
129+
content = "file-content-tf-2"
130+
path = "file-path-tf-2"
131+
state = "PRESENT"
132+
}
133+
}
134+
}
135+
}
136+
instance_filter {
137+
inventories {
138+
os_short_name = "ubuntu"
139+
}
140+
}
141+
rollout {
142+
disruption_budget {
143+
percent = 50
144+
}
145+
min_wait_duration = "120s"
146+
}
147+
}
148+
}
149+
labels = {
150+
state = "active"
151+
}
152+
}
153+
`, context)
154+
}
155+
{{ end }}

0 commit comments

Comments
 (0)