Skip to content

Commit c0d20fb

Browse files
authored
tgc-revival: add google_logging_metric (#15718)
1 parent 2891c9d commit c0d20fb

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

mmv1/products/logging/Metric.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ mutex: 'customMetric/{{project}}'
3232
import_format:
3333
- '{{name}}'
3434
- '{{project}} {{name}}'
35+
include_in_tgc_next_DO_NOT_USE: true
36+
tgc_include_handwritten_tests: true
3537
timeouts:
3638
insert_minutes: 20
3739
update_minutes: 20

mmv1/templates/tgc_next/cai2hcl/resource_converter.go.tmpl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"reflect"
2222
"regexp"
2323
"strings"
24+
"crypto/sha256"
25+
"encoding/hex"
2426

2527
{{/* We list all the v2 imports here and unstable imports, because we run 'goimports' to guess the correct
2628
set of imports, which will never guess the major version correctly. */ -}}
@@ -111,8 +113,12 @@ func (c *{{ $.ResourceName -}}Cai2hclConverter) convertResourceData(asset caiass
111113

112114
hclBlockName := assetNameParts[len(assetNameParts)-1]
113115
digitRegex := regexp.MustCompile(`^\d+$`)
114-
if digitRegex.MatchString(hclBlockName) {
115-
hclBlockName = fmt.Sprintf("resource%s", utils.RandString(8))
116+
nameValidator := regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_-]*$")
117+
if digitRegex.MatchString(hclBlockName) || !nameValidator.MatchString(hclBlockName) {
118+
hasher := sha256.New()
119+
hasher.Write([]byte(hclBlockName))
120+
fullHash := hex.EncodeToString(hasher.Sum(nil))
121+
hclBlockName = fmt.Sprintf("resource%s", fullHash[:8])
116122
}
117123
hclData := make(map[string]interface{})
118124

0 commit comments

Comments
 (0)