Skip to content

Commit 3e57c15

Browse files
authored
tgc-revival: add monitoring resources (#15507)
1 parent 015c3ea commit 3e57c15

File tree

5 files changed

+49
-17
lines changed

5 files changed

+49
-17
lines changed

mmv1/api/resource.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,6 +2195,28 @@ func (r Resource) GetCaiAssetNameTemplate() string {
21952195
return fmt.Sprintf("//%s.googleapis.com/%s", r.CaiProductBackendName(r.CaiProductBaseUrl()), r.IdFormat)
21962196
}
21972197

2198+
// Ignores verifying CAI asset name if it is one computed field
2199+
// For example, the CAI asset name format is //monitoring.googleapis.com/{{name}}
2200+
// for google_monitoring_notification_channel
2201+
func (r Resource) IgnoreCaiAssetName() bool {
2202+
nameTemplate := r.GetCaiAssetNameTemplate()
2203+
parts := strings.Split(nameTemplate, "/")
2204+
if len(parts) > 4 {
2205+
return false
2206+
}
2207+
2208+
params := r.ExtractIdentifiers(nameTemplate)
2209+
if len(params) == 1 {
2210+
param := params[0]
2211+
for _, p := range r.GettableProperties() {
2212+
if google.Underscore(p.Name) == param {
2213+
return p.Output
2214+
}
2215+
}
2216+
}
2217+
return false
2218+
}
2219+
21982220
// Gets the Cai API version
21992221
func (r Resource) CaiApiVersion(productBackendName, caiProductBaseUrl string) string {
22002222
template := r.rawCaiAssetNameTemplate(productBackendName)
@@ -2413,6 +2435,10 @@ func (r Resource) TGCTestIgnorePropertiesToStrings() []string {
24132435
}
24142436
}
24152437

2438+
if r.IgnoreCaiAssetName() {
2439+
props = append(props, "ASSETNAME")
2440+
}
2441+
24162442
slices.Sort(props)
24172443
return props
24182444
}

mmv1/products/monitoring/NotificationChannel.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ timeouts:
4848
insert_minutes: 20
4949
update_minutes: 20
5050
delete_minutes: 20
51+
include_in_tgc_next_DO_NOT_USE: true
5152
custom_code:
5253
constants: 'templates/terraform/constants/monitoring_notification_channel.go.tmpl'
5354
encoder: 'templates/terraform/encoders/monitoring_notification_channel.go.tmpl'
@@ -56,7 +57,6 @@ custom_code:
5657
custom_diff:
5758
- 'sensitiveLabelCustomizeDiff'
5859
error_retry_predicates:
59-
6060
- 'transport_tpg.IsMonitoringConcurrentEditError'
6161
examples:
6262
- name: 'notification_channel_basic'

mmv1/products/monitoring/UptimeCheckConfig.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ timeouts:
3434
insert_minutes: 20
3535
update_minutes: 20
3636
delete_minutes: 20
37+
include_in_tgc_next_DO_NOT_USE: true
3738
custom_code:
3839
encoder: 'templates/terraform/encoders/uptime_check_config.go.tmpl'
3940
constants: 'templates/terraform/constants/monitoring_uptime_check_config.go.tmpl'
4041
custom_delete: 'templates/terraform/custom_delete/monitoring_uptime_check_config.go.tmpl'
4142
custom_import: 'templates/terraform/custom_import/self_link_as_name.tmpl'
4243
error_retry_predicates:
43-
4444
- 'transport_tpg.IsMonitoringConcurrentEditError'
4545
examples:
4646
- name: 'uptime_check_config_http'
@@ -377,6 +377,7 @@ properties:
377377
all bytes fields JSON representations are base64 encoded. e.g.
378378
`foo=bar` in URL-encoded form is `foo%3Dbar` and in base64 encoding is
379379
`Zm9vJTI1M0RiYXI=`.
380+
is_missing_in_cai: true
380381
- name: 'acceptedResponseStatusCodes'
381382
type: Array
382383
description:

mmv1/third_party/tgc_next/test/assert_test_files.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,10 @@ func testSingleResource(t *testing.T, testName string, testData ResourceTestData
251251
if roundtripAsset, ok := roundtripAssetMap[assetType]; !ok {
252252
return fmt.Errorf("roundtrip asset for type %s is missing", assetType)
253253
} else {
254-
if err := compareAssetName(asset.Name, roundtripAsset.Name); err != nil {
255-
return err
254+
if _, ok := ignoredFieldSet["ASSETNAME"]; !ok {
255+
if err := compareAssetName(asset.Name, roundtripAsset.Name); err != nil {
256+
return err
257+
}
256258
}
257259
if diff := cmp.Diff(
258260
asset.Resource,
@@ -435,7 +437,7 @@ func getRoundtripConfig(t *testing.T, testName string, tfDir string, ancestryCac
435437
// Converts tf file to CAI assets
436438
func tfplan2caiConvert(t *testing.T, tfFileName, jsonFileName string, tfDir string, ancestryCache map[string]string, defaultProject string, logger *zap.Logger) ([]caiasset.Asset, error) {
437439
// Run terraform init and terraform apply to generate tfplan.json files
438-
terraformWorkflow(t, tfDir, tfFileName)
440+
terraformWorkflow(t, tfDir, tfFileName, defaultProject)
439441

440442
planFile := fmt.Sprintf("%s.tfplan.json", tfFileName)
441443
planfilePath := filepath.Join(tfDir, planFile)

mmv1/third_party/tgc_next/test/utils.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,33 @@ const (
3030
defaultProject = "ci-test-project-nightly-beta"
3131
)
3232

33-
func terraformWorkflow(t *testing.T, dir, name string) {
34-
terraformInit(t, "terraform", dir)
35-
terraformPlan(t, "terraform", dir, name+".tfplan")
36-
payload := terraformShow(t, "terraform", dir, name+".tfplan")
33+
func terraformWorkflow(t *testing.T, dir, name, project string) {
34+
terraformInit(t, "terraform", dir, project)
35+
terraformPlan(t, "terraform", dir, project, name+".tfplan")
36+
payload := terraformShow(t, "terraform", dir, project, name+".tfplan")
3737
saveFile(t, dir, name+".tfplan.json", payload)
3838
}
3939

40-
func terraformInit(t *testing.T, executable, dir string) {
41-
terraformExec(t, executable, dir, "init", "-input=false")
40+
func terraformInit(t *testing.T, executable, dir, project string) {
41+
terraformExec(t, executable, dir, project, "init", "-input=false")
4242
}
4343

44-
func terraformPlan(t *testing.T, executable, dir, tfplan string) {
45-
terraformExec(t, executable, dir, "plan", "-input=false", "-refresh=false", "-out", tfplan)
44+
func terraformPlan(t *testing.T, executable, dir, project, tfplan string) {
45+
terraformExec(t, executable, dir, project, "plan", "-input=false", "-refresh=false", "-out", tfplan)
4646
}
4747

48-
func terraformShow(t *testing.T, executable, dir, tfplan string) []byte {
49-
return terraformExec(t, executable, dir, "show", "--json", tfplan)
48+
func terraformShow(t *testing.T, executable, dir, project, tfplan string) []byte {
49+
return terraformExec(t, executable, dir, project, "show", "--json", tfplan)
5050
}
5151

52-
func terraformExec(t *testing.T, executable, dir string, args ...string) []byte {
52+
func terraformExec(t *testing.T, executable, dir, project string, args ...string) []byte {
53+
if project == "" {
54+
project = defaultProject
55+
}
5356
cmd := exec.Command(executable, args...)
5457
cmd.Env = []string{
5558
"HOME=" + filepath.Join(dir, "fakehome"),
56-
"GOOGLE_PROJECT=" + defaultProject,
59+
"GOOGLE_PROJECT=" + project,
5760
"GOOGLE_FOLDER=" + "",
5861
"GOOGLE_ORG=" + defaultOrganization,
5962
"GOOGLE_OAUTH_ACCESS_TOKEN=fake-token", // GOOGLE_OAUTH_ACCESS_TOKEN is required so terraform plan does not require the google authentication cert

0 commit comments

Comments
 (0)