diff --git a/.ci/magician/cmd/test_eap_vcr.go b/.ci/magician/cmd/test_eap_vcr.go index 015ff5a77a0a..7f288d0d9f8a 100644 --- a/.ci/magician/cmd/test_eap_vcr.go +++ b/.ci/magician/cmd/test_eap_vcr.go @@ -163,7 +163,7 @@ func execTestEAPVCR(changeNumber, genPath, kokoroArtifactsDir string, rnr ExecRu if err := vt.FetchCassettes(provider.Private, "main", head); err != nil { return fmt.Errorf("error fetching cassettes: %w", err) } - replayingResult, testDirs, replayingErr := runReplaying(runFullVCR, provider.Private, services, vt, false, "") + replayingResult, testDirs, replayingErr := runReplaying(runFullVCR, provider.Private, services, vt) if err := vt.UploadLogs(vcr.UploadLogsOptions{ Head: head, Mode: vcr.Replaying, diff --git a/.ci/magician/cmd/test_terraform_vcr.go b/.ci/magician/cmd/test_terraform_vcr.go index ecb8ba90d16f..b470247f6e58 100644 --- a/.ci/magician/cmd/test_terraform_vcr.go +++ b/.ci/magician/cmd/test_terraform_vcr.go @@ -12,7 +12,6 @@ import ( "github.com/spf13/cobra" - "magician/cov" "magician/exec" "magician/github" "magician/provider" @@ -83,19 +82,6 @@ type recordReplay struct { BrowseLogBaseUrl string } -const ( - covGCSPrefix = "gs://test-coverage-data" -) - -type runCovOpts struct { - repo *source.Repo - buildID string - commitSha string - covGCSPrefix string - testDirs []string - prNumber string -} - var testTerraformVCRCmd = &cobra.Command{ Use: "test-terraform-vcr", Short: "Run vcr tests for affected packages", @@ -148,11 +134,6 @@ The following environment variables are required: } ctlr := source.NewController(env["GOPATH"], "modular-magician", env["GITHUB_TOKEN_DOWNSTREAMS"], rnr) - testCovMerger, err := cov.NewTestCovMerger(rnr, filepath.Join(os.TempDir(), "cov")) - if err != nil { - return fmt.Errorf("failed to create testCovMerger: %w", err) - } - vt, err := vcr.NewTester(env, "ci-vcr-cassettes", "ci-vcr-logs", rnr) if err != nil { return fmt.Errorf("error creating VCR tester: %w", err) @@ -162,7 +143,7 @@ The following environment variables are required: return fmt.Errorf("wrong number of arguments %d, expected 5", len(args)) } - return execTestTerraformVCR(args[0], args[1], args[2], args[3], args[4], baseBranch, gh, rnr, ctlr, vt, testCovMerger) + return execTestTerraformVCR(args[0], args[1], args[2], args[3], args[4], baseBranch, gh, rnr, ctlr, vt) }, } @@ -174,7 +155,7 @@ func listTTVRequiredEnvironmentVariables() string { return result } -func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep, baseBranch string, gh GithubClient, rnr ExecRunner, ctlr *source.Controller, vt *vcr.Tester, covMerger *cov.Merger) error { +func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep, baseBranch string, gh GithubClient, rnr ExecRunner, ctlr *source.Controller, vt *vcr.Tester) error { newBranch := "auto-pr-" + prNumber oldBranch := newBranch + "-old" @@ -230,7 +211,7 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep, return fmt.Errorf("error posting pending status: %w", err) } - replayingResult, testDirs, replayingErr := runReplaying(runFullVCR, provider.Beta, services, vt, true, covMerger.VcrTestCovDir) + replayingResult, testDirs, replayingErr := runReplaying(runFullVCR, provider.Beta, services, vt) testState := "success" if replayingErr != nil { testState = "failure" @@ -314,12 +295,10 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep, var replayingAfterRecordingErr error if len(recordingResult.PassedTests) > 0 { replayingAfterRecordingResult, replayingAfterRecordingErr = vt.RunParallel(vcr.RunOptions{ - Mode: vcr.Replaying, - Version: provider.Beta, - TestDirs: testDirs, - Tests: recordingResult.PassedTests, - EnableTestCoverage: true, - TestCovDir: covMerger.VcrTestCovDir, + Mode: vcr.Replaying, + Version: provider.Beta, + TestDirs: testDirs, + Tests: recordingResult.PassedTests, }) if replayingAfterRecordingErr != nil { testState = "failure" @@ -356,25 +335,6 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep, if err != nil { return fmt.Errorf("error formatting record replay comment: %w", err) } - - // run unit test and generate combined code coverage - if err := genCov(rnr, covMerger, gh, runCovOpts{ - repo: tpgbRepo, - buildID: buildID, - commitSha: mmCommitSha, - covGCSPrefix: covGCSPrefix, - testDirs: testDirs, - prNumber: prNumber, - }); err != nil { - fmt.Printf("Failed to generate coverage: %s\n", err) - } - - out, err := covMerger.PackageCovComment() - if err != nil { - fmt.Printf("failed to get package coverage: %s\n", err) - } else { - recordReplayComment += "\n\n" + out - } if err := gh.PostComment(prNumber, recordReplayComment); err != nil { return fmt.Errorf("error posting comment: %w", err) } @@ -490,17 +450,15 @@ func modifiedPackages(changedFiles []string, version provider.Version) (map[stri return services, runFullVCR } -func runReplaying(runFullVCR bool, version provider.Version, services map[string]struct{}, vt *vcr.Tester, enableCov bool, covDir string) (vcr.Result, []string, error) { +func runReplaying(runFullVCR bool, version provider.Version, services map[string]struct{}, vt *vcr.Tester) (vcr.Result, []string, error) { result := vcr.Result{} var testDirs []string var replayingErr error if runFullVCR { fmt.Println("runReplaying: full VCR tests") result, replayingErr = vt.Run(vcr.RunOptions{ - Mode: vcr.Replaying, - Version: version, - EnableTestCoverage: enableCov, - TestCovDir: covDir, + Mode: vcr.Replaying, + Version: version, }) } else if len(services) > 0 { fmt.Printf("runReplaying: %d specific services: %v\n", len(services), services) @@ -509,11 +467,9 @@ func runReplaying(runFullVCR bool, version provider.Version, services map[string testDirs = append(testDirs, servicePath) fmt.Println("run VCR tests in ", service) serviceResult, serviceReplayingErr := vt.Run(vcr.RunOptions{ - Mode: vcr.Replaying, - Version: version, - TestDirs: []string{servicePath}, - EnableTestCoverage: enableCov, - TestCovDir: covDir, + Mode: vcr.Replaying, + Version: version, + TestDirs: []string{servicePath}, }) replayingErr = errors.Join(replayingErr, serviceReplayingErr) result.PassedTests = append(result.PassedTests, serviceResult.PassedTests...) @@ -580,48 +536,3 @@ func formatRecordReplay(data recordReplay) (string, error) { data.BrowseLogBaseUrl = fmt.Sprintf("https://console.cloud.google.com/storage/browser/%s", logBasePath) return formatComment("record_replay.tmpl", recordReplayTmplText, data) } - -func unitTest(rnr ExecRunner, repoPath, covDir string, testDirs []string) error { - if err := rnr.PushDir(repoPath); err != nil { - return fmt.Errorf("error changing to tpgbRepo dir: %w", err) - } - - if len(testDirs) == 0 { - if allPackages, err := rnr.Run("go", []string{"list", "./..."}, nil); err != nil { - return err - } else { - for _, dir := range strings.Split(allPackages, "\n") { - if !strings.Contains(dir, "github.com/hashicorp/terraform-provider-google-beta/scripts") { - testDirs = append(testDirs, dir) - } - } - } - } - - args := []string{"test", "-p", "4", "-cover"} - args = append(args, testDirs...) - args = append(args, []string{"-args", fmt.Sprintf("-test.gocoverdir=%s", covDir)}...) - _, err := rnr.Run("go", args, nil) - if err != nil { - return fmt.Errorf("unit test failed with error: %s", err) - } - return nil -} - -func genCov(rnr ExecRunner, covMerger *cov.Merger, gh GithubClient, opts runCovOpts) error { - fmt.Println("Generating code coverage...") - if err := unitTest(rnr, opts.repo.Path, covMerger.UnitTestCovDir, opts.testDirs); err != nil { - fmt.Println("unit test failed") - } - if err := covMerger.Merge(); err != nil { - return fmt.Errorf("failed to merge test coverage: %w", err) - } - covURL, err := covMerger.UploadToGCS(opts.covGCSPrefix, opts.buildID) - if err != nil { - return fmt.Errorf("failed to upload test coverage: %w", err) - } - if err := gh.PostBuildStatus(opts.prNumber, "test-cov", "success", covURL, opts.commitSha); err != nil { - return fmt.Errorf("error posting pending status: %w", err) - } - return nil -} diff --git a/.ci/magician/cmd/test_terraform_vcr_test.go b/.ci/magician/cmd/test_terraform_vcr_test.go index 486afbc3dcef..835d9d302d32 100644 --- a/.ci/magician/cmd/test_terraform_vcr_test.go +++ b/.ci/magician/cmd/test_terraform_vcr_test.go @@ -6,7 +6,6 @@ import ( "strings" "testing" - "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "magician/provider" @@ -580,51 +579,3 @@ func TestRecordReplay(t *testing.T) { }) } } - -func TestUnitTest(t *testing.T) { - tests := []struct { - testName string - testDirs []string - want map[string][]ParameterList - }{ - { - "not empty test dir", - []string{"test-dir"}, - map[string][]ParameterList{ - "Run": { - {"repo-path", "go", []string{"test", "-p", "4", "-cover", "test-dir", "-args", "-test.gocoverdir=cov-dir"}, map[string]string(nil)}, - }, - }, - }, - { - "empty test dir", - []string{}, - map[string][]ParameterList{ - "Run": { - {"repo-path", "go", []string{"list", "./..."}, map[string]string(nil)}, - {"repo-path", "go", []string{"test", "-p", "4", "-cover", "pkg1", "pkg2", "-args", "-test.gocoverdir=cov-dir"}, map[string]string(nil)}, - }, - }, - }, - } - for _, tc := range tests { - t.Run(tc.testName, func(t *testing.T) { - mr := &mockRunner{ - cwd: "cwd", - calledMethods: make(map[string][]ParameterList), - cmdResults: map[string]string{ - "repo-path go [list ./...] map[]": "pkg1\npkg2", - }, - } - err := unitTest(mr, "repo-path", "cov-dir", tc.testDirs) - if err != nil { - t.Fatal(err) - } - if diff := cmp.Diff(tc.want, mr.calledMethods); diff != "" { - t.Errorf("unitTest triggered different called methods(-want, +got): %s", diff) - } - - }) - } - -} diff --git a/.ci/magician/cov/interfaces.go b/.ci/magician/cov/interfaces.go deleted file mode 100644 index 266a991c8cb6..000000000000 --- a/.ci/magician/cov/interfaces.go +++ /dev/null @@ -1,6 +0,0 @@ -package cov - -type ExecRunner interface { - Mkdir(path string) error - Run(name string, args []string, env map[string]string) (string, error) -} diff --git a/.ci/magician/cov/merger.go b/.ci/magician/cov/merger.go deleted file mode 100644 index 792ca4cea4eb..000000000000 --- a/.ci/magician/cov/merger.go +++ /dev/null @@ -1,160 +0,0 @@ -package cov - -import ( - "fmt" - "os" - "path/filepath" - "strings" - "text/template" -) - -// Merger stores coverage related folders and files with a command line runner. -// File structure is: -// workdir/unit-test-cov/ -// workdir/vcr-test-cov/ -// workdir/merged-test-cov/ -// workdir/cov.txt -// workdir/cov.html -type Merger struct { - rnr ExecRunner - workDir string - UnitTestCovDir string - VcrTestCovDir string - MergedDir string -} - -func NewTestCovMerger(rnr ExecRunner, workDir string) (*Merger, error) { - unitTestDir := filepath.Join(workDir, "unit-test-cov") - vcrTestDir := filepath.Join(workDir, "vcr-test-cov") - mergedDir := filepath.Join(workDir, "merged-test-cov") - for _, dir := range []string{unitTestDir, vcrTestDir, mergedDir} { - if err := rnr.Mkdir(dir); err != nil { - return nil, fmt.Errorf("failed to create dir %s: %w", dir, err) - } - } - return &Merger{ - workDir: workDir, - rnr: rnr, - UnitTestCovDir: unitTestDir, - VcrTestCovDir: vcrTestDir, - MergedDir: mergedDir, - }, nil -} - -func (m *Merger) HTMLCovPath() string { - return filepath.Join(m.workDir, "cov.html") -} - -func (m *Merger) Merge() error { - if isFolderEmpty(m.UnitTestCovDir) && isFolderEmpty(m.VcrTestCovDir) { - return fmt.Errorf("no coverage data found in provided folders") - } - - covTxtPath := filepath.Join(m.workDir, "cov.txt") - covHTMLPath := m.HTMLCovPath() - - if _, err := m.rnr.Run( - "go", - []string{ - "tool", - "covdata", - "merge", - fmt.Sprintf("-i=%s,%s", m.UnitTestCovDir, m.VcrTestCovDir), - "-o=" + m.MergedDir, - }, - nil, - ); err != nil { - return fmt.Errorf("failed to merge coverage data: %s", err) - } - - if _, err := m.rnr.Run( - "go", - []string{ - "tool", - "covdata", - "textfmt", - "-i=" + m.MergedDir, - "-o=" + covTxtPath, - }, - nil, - ); err != nil { - return fmt.Errorf("failed to convert coverage data to text format: %s", err) - } - - if _, err := m.rnr.Run( - "go", - []string{ - "tool", - "cover", - "-html=" + covTxtPath, - "-o=" + covHTMLPath, - }, - nil, - ); err != nil { - return fmt.Errorf("failed to convert coverage data to text format: %s", err) - } - return nil -} - -func (m *Merger) UploadToGCS(gcsPrefix string, buildID string) (string, error) { - bucketName := strings.TrimPrefix(gcsPrefix, "gs://") - gcsPath := fmt.Sprintf("gs://%s/%s/", bucketName, buildID) - fmt.Printf("Uploading coverage result to %s\n", gcsPath) - args := []string{"-m", "cp", m.HTMLCovPath(), gcsPath} - if _, err := m.rnr.Run("gsutil", args, nil); err != nil { - fmt.Println(err) - return "", fmt.Errorf("error upload cov html: %w", err) - } - return fmt.Sprintf("https://storage.cloud.google.com/%s/%s/cov.html", bucketName, buildID), nil -} - -func (m *Merger) PackageCovComment() (string, error) { - out, err := m.rnr.Run( - "go", - []string{ - "tool", - "covdata", - "percent", - "-i=" + m.MergedDir, - }, - nil, - ) - if err != nil { - return "", err - } - - covList := strings.Split(strings.TrimSpace(out), "\n") - - commentTemplate := ` -
-Click here to see Test Coverage Metrics -
- -
-
- ` - - // Create a new template and parse the letter into it. - sb := new(strings.Builder) - t := template.Must(template.New("commentTemplate").Parse(commentTemplate)) - err = t.Execute(sb, covList) - if err != nil { - return "", err - } - return strings.TrimSpace(sb.String()), nil -} - -func isFolderEmpty(dirPath string) bool { - file, err := os.Open(dirPath) - if err != nil { - return true - } - defer file.Close() - - _, err = file.Readdirnames(1) - return err != nil -} diff --git a/.ci/magician/cov/merger_test.go b/.ci/magician/cov/merger_test.go deleted file mode 100644 index 6217ef6bee99..000000000000 --- a/.ci/magician/cov/merger_test.go +++ /dev/null @@ -1,166 +0,0 @@ -package cov - -import ( - "fmt" - "os" - "path/filepath" - "strings" - "testing" - - "github.com/google/go-cmp/cmp" -) - -type MockRunner interface { - ExecRunner -} - -type ParameterList []any - -type mockRunner struct { - dirs []string - commands []ParameterList - cmdResults map[string]string -} - -func (r *mockRunner) Mkdir(path string) error { - r.dirs = append(r.dirs, path) - return nil -} - -func (r *mockRunner) Run(name string, args []string, env map[string]string) (string, error) { - r.commands = append(r.commands, ParameterList{name, args}) - cmd := fmt.Sprintf("%s %v", name, args) - if result, ok := r.cmdResults[cmd]; ok { - return result, nil - } - return "", nil -} - -func TestNewTestCovMerger(t *testing.T) { - rnr := &mockRunner{} - _, err := NewTestCovMerger(rnr, "/tmp") - if err != nil { - t.Fatal(err) - } - if diff := cmp.Diff([]string{"/tmp/unit-test-cov", "/tmp/vcr-test-cov", "/tmp/merged-test-cov"}, rnr.dirs); diff != "" { - t.Errorf("NewTestCovMerger did not create expected folders: (-want, +got) = %s", diff) - } -} - -func TestMergeFail(t *testing.T) { - workdir := t.TempDir() - - rnr := &mockRunner{} - merger, err := NewTestCovMerger(rnr, workdir) - if err != nil { - t.Fatal(err) - } - err = merger.Merge() - if err == nil { - t.Fatal("expect failure since folders are empty, but got nil err") - } - - if !strings.Contains(err.Error(), "no coverage data found") { - t.Errorf("Merge() got unexpected error: %s", err) - } - -} - -func TestMerge(t *testing.T) { - workdir := t.TempDir() - err := os.MkdirAll(filepath.Join(workdir, "unit-test-cov"), 0755) - if err != nil { - t.Fatal(err) - } - - file, err := os.Create(filepath.Join(workdir, "unit-test-cov", "cov.data")) - if err != nil { - t.Fatal(err) - } - defer file.Close() - - rnr := &mockRunner{} - merger := Merger{ - UnitTestCovDir: filepath.Join(workdir, "unit-test-cov"), - VcrTestCovDir: filepath.Join(workdir, "vcr-test-cov"), - MergedDir: filepath.Join(workdir, "merged-test-cov"), - workDir: workdir, - rnr: rnr, - } - - if err := merger.Merge(); err != nil { - t.Fatal(err) - } - - want := []ParameterList{ - {"go", []string{"tool", "covdata", "merge", "-i=" + workdir + "/unit-test-cov," + workdir + "/vcr-test-cov", "-o=" + workdir + "/merged-test-cov"}}, - {"go", []string{"tool", "covdata", "textfmt", "-i=" + workdir + "/merged-test-cov", "-o=" + workdir + "/cov.txt"}}, - {"go", []string{"tool", "cover", "-html=" + workdir + "/cov.txt", "-o=" + workdir + "/cov.html"}}, - } - if diff := cmp.Diff(want, rnr.commands); diff != "" { - t.Errorf("Merge got different commands: %s", diff) - } -} - -func TestUploadToGCS(t *testing.T) { - workdir := os.TempDir() - rnr := &mockRunner{} - merger := Merger{ - rnr: rnr, - workDir: workdir, - } - - got, err := merger.UploadToGCS("gs://bucket/path", "12345") - if err != nil { - t.Fatal(err) - } - - want := "https://storage.cloud.google.com/bucket/path/12345/cov.html" - if got != want { - t.Errorf("UploadToGCS got = %s, want = %s", got, want) - } - - wantCommands := []ParameterList{ - {"gsutil", []string{"-m", "cp", filepath.Join(workdir, "cov.html"), "gs://bucket/path/12345/"}}, - } - if diff := cmp.Diff(wantCommands, rnr.commands); diff != "" { - t.Errorf("UploadToGCS got different commands: %s", diff) - } -} - -func TestPackageCovComment(t *testing.T) { - workdir := os.TempDir() - rnr := &mockRunner{ - cmdResults: map[string]string{ - "go [tool covdata percent -i=" + filepath.Join(workdir, "merged-test-cov]"): "pkg1 10%\npkg2 20%\n\n", - }, - } - merger := Merger{ - rnr: rnr, - workDir: workdir, - MergedDir: filepath.Join(workdir, "merged-test-cov"), - } - - got, err := merger.PackageCovComment() - if err != nil { - t.Fatal(err) - } - - want := strings.TrimSpace(` -
-Click here to see Test Coverage Metrics -
- -
-
- `) - if got != want { - t.Errorf("PackageCovComment got = %s, want = %s", got, want) - } -} diff --git a/.ci/magician/vcr/tester.go b/.ci/magician/vcr/tester.go index 57b701cf0fbe..6f01ee352357 100644 --- a/.ci/magician/vcr/tester.go +++ b/.ci/magician/vcr/tester.go @@ -193,12 +193,10 @@ func (vt *Tester) LogPath(mode Mode, version provider.Version) string { } type RunOptions struct { - Mode Mode - Version provider.Version - TestDirs []string - Tests []string - EnableTestCoverage bool - TestCovDir string + Mode Mode + Version provider.Version + TestDirs []string + Tests []string } // Run the vcr tests in the given mode and provider version and return the result. @@ -254,13 +252,6 @@ func (vt *Tester) Run(opt RunOptions) (Result, error) { "-ldflags=-X=github.com/hashicorp/terraform-provider-google-beta/version.ProviderVersion=acc", "-vet=off", ) - if opt.Mode == Replaying && opt.EnableTestCoverage { - args = append(args, []string{ - "-cover", - "-args", - "-test.gocoverdir=" + opt.TestCovDir, - }...) - } env := map[string]string{ "VCR_PATH": cassettePath, "VCR_MODE": opt.Mode.Upper(), @@ -365,7 +356,7 @@ func (vt *Tester) RunParallel(opt RunOptions) (Result, error) { for _, testDir := range opt.TestDirs { for _, test := range opt.Tests { running <- struct{}{} - go vt.runInParallel(opt, testDir, test, logPath, cassettePath, running, wg, outputs, errs) + go vt.runInParallel(opt.Mode, opt.Version, testDir, test, logPath, cassettePath, running, wg, outputs, errs) } } @@ -396,7 +387,7 @@ func (vt *Tester) RunParallel(opt RunOptions) (Result, error) { return collectResult(output), testErr } -func (vt *Tester) runInParallel(opt RunOptions, testDir, test, logPath, cassettePath string, running <-chan struct{}, wg *sync.WaitGroup, outputs chan<- string, errs chan<- error) { +func (vt *Tester) runInParallel(mode Mode, version provider.Version, testDir, test, logPath, cassettePath string, running <-chan struct{}, wg *sync.WaitGroup, outputs chan<- string, errs chan<- error) { args := []string{ "test", testDir, @@ -409,14 +400,6 @@ func (vt *Tester) runInParallel(opt RunOptions, testDir, test, logPath, cassette "-ldflags=-X=github.com/hashicorp/terraform-provider-google-beta/version.ProviderVersion=acc", "-vet=off", } - mode := opt.Mode - if mode == Replaying && opt.EnableTestCoverage { - args = append(args, []string{ - "-cover", - "-args", - "-test.gocoverdir=" + opt.TestCovDir, - }...) - } env := map[string]string{ "VCR_PATH": cassettePath, "VCR_MODE": mode.Upper(), diff --git a/docs/content/reference/metadata.md b/docs/content/reference/metadata.md index f97b9bc17955..055581388acb 100644 --- a/docs/content/reference/metadata.md +++ b/docs/content/reference/metadata.md @@ -31,10 +31,6 @@ The version of the API used for this resource e.g., "v2". The API "resource type kind" used for this resource e.g., "Function". -### `cai_asset_name_format` - -The custom CAI asset name format for this resource is typically specified (e.g., //cloudsql.googleapis.com/projects/{{project}}/instances/{{name}}). If this format is not provided, the Terraform resource ID format is used instead. - ### `api_variant_patterns` The API URL patterns used by this resource that represent variants e.g., "folders/{folder}/feeds/{feed}". Each pattern must match the value defined in the API exactly. The use of `api_variant_patterns` is only meaningful when the resource type has multiple parent types available. diff --git a/mmv1/api/compiler.go b/mmv1/api/compiler.go index f4229345271d..1ec9354f060f 100644 --- a/mmv1/api/compiler.go +++ b/mmv1/api/compiler.go @@ -23,9 +23,8 @@ import ( func Compile(yamlPath string, obj interface{}, overrideDir string) { objYaml, err := os.ReadFile(yamlPath) - if err != nil { - log.Fatalf("Cannot open the file: %s", yamlPath) + log.Fatalf("Cannot open the file: %v", objYaml) } if overrideDir != "" { diff --git a/mmv1/loader/custom_errors.go b/mmv1/api/custom_errors.go similarity index 96% rename from mmv1/loader/custom_errors.go rename to mmv1/api/custom_errors.go index ac7c193f35fa..9145c2fd6283 100644 --- a/mmv1/loader/custom_errors.go +++ b/mmv1/api/custom_errors.go @@ -1,4 +1,4 @@ -package loader +package api import "fmt" diff --git a/mmv1/api/resource/examples.go b/mmv1/api/resource/examples.go index 582895917887..11f8663b3e30 100644 --- a/mmv1/api/resource/examples.go +++ b/mmv1/api/resource/examples.go @@ -192,6 +192,7 @@ func (e *Examples) UnmarshalYAML(value *yaml.Node) error { if e.ConfigPath == "" { e.ConfigPath = DefaultConfigPath(e.Name) } + e.SetHCLText() return nil } @@ -260,7 +261,7 @@ func (e *Examples) ValidateExternalProviders() { } // Executes example templates for documentation and tests -func (e *Examples) LoadHCLText(baseDir string) { +func (e *Examples) SetHCLText() { originalVars := e.Vars originalTestEnvVars := e.TestEnvVars docTestEnvVars := make(map[string]string) @@ -287,7 +288,7 @@ func (e *Examples) LoadHCLText(baseDir string) { docTestEnvVars[key] = docs_defaults[e.TestEnvVars[key]] } e.TestEnvVars = docTestEnvVars - e.DocumentationHCLText = e.ExecuteTemplate(baseDir) + e.DocumentationHCLText = e.ExecuteTemplate() e.DocumentationHCLText = regexp.MustCompile(`\n\n$`).ReplaceAllString(e.DocumentationHCLText, "\n") // Remove region tags @@ -328,7 +329,7 @@ func (e *Examples) LoadHCLText(baseDir string) { e.Vars = testVars e.TestEnvVars = testTestEnvVars - e.TestHCLText = e.ExecuteTemplate(baseDir) + e.TestHCLText = e.ExecuteTemplate() e.TestHCLText = regexp.MustCompile(`\n\n$`).ReplaceAllString(e.TestHCLText, "\n") // Remove region tags e.TestHCLText = re1.ReplaceAllString(e.TestHCLText, "") @@ -340,8 +341,8 @@ func (e *Examples) LoadHCLText(baseDir string) { e.TestEnvVars = originalTestEnvVars } -func (e *Examples) ExecuteTemplate(baseDir string) string { - templateContent, err := os.ReadFile(filepath.Join(baseDir, e.ConfigPath)) +func (e *Examples) ExecuteTemplate() string { + templateContent, err := os.ReadFile(e.ConfigPath) if err != nil { glog.Exit(err) } @@ -355,6 +356,7 @@ func (e *Examples) ExecuteTemplate(baseDir string) string { validateRegexForContents(varRegex, fileContentString, e.ConfigPath, "vars", e.Vars) templateFileName := filepath.Base(e.ConfigPath) + tmpl, err := template.New(templateFileName).Funcs(google.TemplateFunctions).Parse(fileContentString) if err != nil { glog.Exit(err) @@ -423,9 +425,7 @@ func (e *Examples) SetOiCSHCLText() { } e.Vars = testVars - // SetOiCSHCLText is generated from the provider, assume base directory is - // always relative for this case - e.OicsHCLText = e.ExecuteTemplate("") + e.OicsHCLText = e.ExecuteTemplate() e.OicsHCLText = regexp.MustCompile(`\n\n$`).ReplaceAllString(e.OicsHCLText, "\n") // Remove region tags diff --git a/mmv1/api/type.go b/mmv1/api/type.go index 184d89917fd1..6a1c845a2dee 100644 --- a/mmv1/api/type.go +++ b/mmv1/api/type.go @@ -450,8 +450,10 @@ func (t Type) Lineage() string { return fmt.Sprintf("%s.%s", t.ParentMetadata.Lineage(), google.Underscore(t.Name)) } -// Returns the actual Terraform lineage for the field, formatted for resource metadata. -// This will return a simple dot notation path, like: foo_field.bar_field +// Returns a dot notation path to where the field is nested within the parent +// object. eg: parent.meta.label.foo +// This format is intended for resource metadata, to be used for connecting a Terraform +// type with a corresponding API type. func (t Type) MetadataLineage() string { if t.ParentMetadata == nil || t.ParentMetadata.FlattenObject { return google.Underscore(t.Name) @@ -465,28 +467,29 @@ func (t Type) MetadataLineage() string { return fmt.Sprintf("%s.%s", t.ParentMetadata.MetadataLineage(), google.Underscore(t.Name)) } -// Returns the default Terraform lineage for the field, based on converting MetadataApiLineage -// to snake_case. This is used to determine whether an explicit Terraform field name is required. -// This will return a simple dot notation path like: foo_field.bar_field +// Returns a dot notation path to where the field is nested within the parent +// object. eg: parent.meta.label.foo +// This format converts the API field names directly to snake_case, which can be compared against the MetadataLineage +// to determine whether to include an explicit Terraform field name. func (t Type) MetadataDefaultLineage() string { - apiLineage := t.MetadataApiLineage() - parts := strings.Split(apiLineage, ".") - var snakeParts []string - for _, p := range parts { - snakeParts = append(snakeParts, google.Underscore(p)) + apiName := t.ApiName + if t.ParentMetadata == nil { + return google.Underscore(apiName) + } + + if t.ParentMetadata.IsA("Array") { + return t.ParentMetadata.MetadataDefaultLineage() } - return strings.Join(snakeParts, ".") + + return fmt.Sprintf("%s.%s", t.ParentMetadata.MetadataDefaultLineage(), google.Underscore(apiName)) } -// Returns the actual API lineage for the field (that is, using API names), formatted for -// resource metadata. This will return a simple dot notation path, like: fooField.barField +// Returns a dot notation path to where the field is nested within the parent +// object. eg: parent.meta.label.foo // This format is intended for to represent an API type. func (t Type) MetadataApiLineage() string { apiName := t.ApiName if t.ParentMetadata == nil { - if !t.UrlParamOnly && t.ResourceMetadata.ApiResourceField != "" { - apiName = fmt.Sprintf("%s.%s", t.ResourceMetadata.ApiResourceField, apiName) - } return apiName } diff --git a/mmv1/api/type_test.go b/mmv1/api/type_test.go index 753a57f59217..87d76d41a0ba 100644 --- a/mmv1/api/type_test.go +++ b/mmv1/api/type_test.go @@ -372,38 +372,6 @@ func TestMetadataApiLineage(t *testing.T) { } root.SetDefault(&Resource{}) - fineGrainedRoot := Type{ - Name: "root", - Type: "NestedObject", - Properties: []*Type{ - { - Name: "foo", - Type: "NestedObject", - Properties: []*Type{ - { - Name: "bars", - Type: "Array", - ItemType: &Type{ - Type: "NestedObject", - Properties: []*Type{ - { - Name: "fooBar", - Type: "String", - }, - }, - }, - }, - }, - }, - { - Name: "baz", - ApiName: "bazbaz", - Type: "String", - }, - }, - } - fineGrainedRoot.SetDefault(&Resource{ApiResourceField: "whatever"}) - cases := []struct { description string obj Type @@ -434,31 +402,6 @@ func TestMetadataApiLineage(t *testing.T) { obj: *root.Properties[1], expected: "root.bazbaz", }, - { - description: "fine-grained root type", - obj: fineGrainedRoot, - expected: "whatever.root", - }, - { - description: "fine-grained sub type", - obj: *fineGrainedRoot.Properties[0], - expected: "whatever.root.foo", - }, - { - description: "fine-grained array", - obj: *fineGrainedRoot.Properties[0].Properties[0], - expected: "whatever.root.foo.bars", - }, - { - description: "fine-grained array of objects", - obj: *fineGrainedRoot.Properties[0].Properties[0].ItemType.Properties[0], - expected: "whatever.root.foo.bars.fooBar", - }, - { - description: "fine-grained with api name", - obj: *fineGrainedRoot.Properties[1], - expected: "whatever.root.bazbaz", - }, } for _, tc := range cases { diff --git a/mmv1/api/utils/utils.go b/mmv1/api/utils/utils.go index cee8e44788a9..ecc8ff59b366 100644 --- a/mmv1/api/utils/utils.go +++ b/mmv1/api/utils/utils.go @@ -1,8 +1,6 @@ package utils -import ( - "reflect" -) +import "reflect" // IsEmpty checks if a value is meaningfully empty in a recursive way func IsEmpty(v interface{}) bool { diff --git a/mmv1/loader/file_ops.go b/mmv1/loader/file_ops.go deleted file mode 100644 index c9a2c97dc3f2..000000000000 --- a/mmv1/loader/file_ops.go +++ /dev/null @@ -1,14 +0,0 @@ -package loader - -import ( - "errors" - "os" - "path/filepath" -) - -func Exists(paths ...string) bool { - fullPath := filepath.Join(paths...) - _, err := os.Stat(fullPath) - exists := !errors.Is(err, os.ErrNotExist) - return exists -} diff --git a/mmv1/main.go b/mmv1/main.go index 8d71982674f1..60c6480a0fab 100644 --- a/mmv1/main.go +++ b/mmv1/main.go @@ -75,7 +75,11 @@ func GenerateProducts(product, resource, providerName, version, outputPath, over log.Printf("Building %s version", version) log.Printf("Building %s provider", providerName) - loader := loader.NewLoader(loader.Config{Version: version, OverrideDirectory: overrideDirectory}) + loader := loader.Loader{ + OverrideDirectory: overrideDirectory, + Version: version, + } + loadedProducts := loader.LoadProducts() var productsToGenerate []string diff --git a/mmv1/openapi_generate/parser.go b/mmv1/openapi_generate/parser.go index f2f16b3edf8b..6adfd87a51bc 100644 --- a/mmv1/openapi_generate/parser.go +++ b/mmv1/openapi_generate/parser.go @@ -269,7 +269,7 @@ func buildResource(filePath, resourcePath, resourceName string, root *openapi3.T example.PrimaryResourceId = "example" example.Vars = map[string]string{"resource_name": "test-resource"} - resource.Examples = []*r.Examples{&example} + resource.Examples = []r.Examples{example} resourceNameBytes := []byte(resourceName) // Write the status as an encoded string to flag when a YAML file has been diff --git a/mmv1/products/accesscontextmanager/AccessPolicy.yaml b/mmv1/products/accesscontextmanager/AccessPolicy.yaml index f0a7b9e57fd2..33c80d365346 100644 --- a/mmv1/products/accesscontextmanager/AccessPolicy.yaml +++ b/mmv1/products/accesscontextmanager/AccessPolicy.yaml @@ -33,7 +33,6 @@ docs: id_format: '{{name}}' base_url: 'accessPolicies' self_link: 'accessPolicies/{{name}}' -cai_asset_name_format: 'accessPolicies/{{name}}' update_verb: 'PATCH' update_mask: true import_format: diff --git a/mmv1/products/bigtable/AppProfile.yaml b/mmv1/products/bigtable/AppProfile.yaml index 9df692150511..61a71571806c 100644 --- a/mmv1/products/bigtable/AppProfile.yaml +++ b/mmv1/products/bigtable/AppProfile.yaml @@ -35,7 +35,6 @@ timeouts: update_minutes: 20 delete_minutes: 20 custom_code: - constants: 'templates/terraform/constants/bigtable_app_profile_routing.go.tmpl' extra_schema_entry: 'templates/terraform/extra_schema_entry/bigtable_app_profile.go.tmpl' encoder: 'templates/terraform/encoders/bigtable_app_profile.go.tmpl' pre_update: 'templates/terraform/pre_update/bigtable_app_profile.go.tmpl' diff --git a/mmv1/products/bigtable/product.yaml b/mmv1/products/bigtable/product.yaml index 22be289fa4d1..fad51306e1b8 100644 --- a/mmv1/products/bigtable/product.yaml +++ b/mmv1/products/bigtable/product.yaml @@ -19,4 +19,3 @@ versions: base_url: 'https://bigtableadmin.googleapis.com/v2/' scopes: - 'https://www.googleapis.com/auth/bigtable' -cai_asset_service: 'bigtable.googleapis.com' diff --git a/mmv1/products/billing/ProjectInfo.yaml b/mmv1/products/billing/ProjectInfo.yaml index 7fbf5001ca56..2c861183eb23 100644 --- a/mmv1/products/billing/ProjectInfo.yaml +++ b/mmv1/products/billing/ProjectInfo.yaml @@ -23,7 +23,6 @@ references: docs: id_format: 'projects/{{project}}' base_url: 'projects/{{project}}/billingInfo' -cai_asset_name_format: 'projects/{{project}}/billingInfo' create_verb: 'PUT' delete_verb: 'PUT' import_format: diff --git a/mmv1/products/binaryauthorization/Policy.yaml b/mmv1/products/binaryauthorization/Policy.yaml index 5bed579e683d..592dd3fcdafe 100644 --- a/mmv1/products/binaryauthorization/Policy.yaml +++ b/mmv1/products/binaryauthorization/Policy.yaml @@ -23,7 +23,6 @@ docs: id_format: 'projects/{{project}}' base_url: 'projects/{{project}}/policy' self_link: 'projects/{{project}}/policy' -cai_asset_name_format: 'projects/{{project}}/policy' create_verb: 'PUT' delete_verb: 'PUT' import_format: diff --git a/mmv1/products/cloudasset/FolderFeed.yaml b/mmv1/products/cloudasset/FolderFeed.yaml index 72c6664925be..1291acf6e195 100644 --- a/mmv1/products/cloudasset/FolderFeed.yaml +++ b/mmv1/products/cloudasset/FolderFeed.yaml @@ -42,7 +42,6 @@ custom_code: supports_indirect_user_project_override: true include_in_tgc_next_DO_NOT_USE: true cai_base_url: 'folders/{{folder}}/feeds' -cai_asset_name_format: 'folders/{{folder}}/feeds/{{feed_id}}' tgc_ignore_terraform_encoder: true examples: - name: 'cloud_asset_folder_feed' diff --git a/mmv1/products/cloudasset/OrganizationFeed.yaml b/mmv1/products/cloudasset/OrganizationFeed.yaml index c28e89d26f03..ab36431c93d5 100644 --- a/mmv1/products/cloudasset/OrganizationFeed.yaml +++ b/mmv1/products/cloudasset/OrganizationFeed.yaml @@ -42,7 +42,6 @@ custom_code: supports_indirect_user_project_override: true include_in_tgc_next_DO_NOT_USE: true cai_base_url: 'organizations/{{org_id}}/feeds' -cai_asset_name_format: 'organizations/{{org_id}}/feeds/{{feed_id}}' tgc_ignore_terraform_encoder: true examples: - name: 'cloud_asset_organization_feed' diff --git a/mmv1/products/cloudasset/ProjectFeed.yaml b/mmv1/products/cloudasset/ProjectFeed.yaml index aee4b0807ef6..7b9cf2e33195 100644 --- a/mmv1/products/cloudasset/ProjectFeed.yaml +++ b/mmv1/products/cloudasset/ProjectFeed.yaml @@ -40,7 +40,6 @@ custom_code: custom_import: 'templates/terraform/custom_import/cloud_asset_feed.go.tmpl' include_in_tgc_next_DO_NOT_USE: true cai_base_url: 'projects/{{project}}/feeds' -cai_asset_name_format: 'projects/{{project}}/feeds/{{feed_id}}' tgc_ignore_terraform_encoder: true examples: - name: 'cloud_asset_project_feed' diff --git a/mmv1/products/cloudrun/DomainMapping.yaml b/mmv1/products/cloudrun/DomainMapping.yaml index d0899e1231ee..7bc3a80cee43 100644 --- a/mmv1/products/cloudrun/DomainMapping.yaml +++ b/mmv1/products/cloudrun/DomainMapping.yaml @@ -24,7 +24,6 @@ docs: id_format: 'locations/{{location}}/namespaces/{{project}}/domainmappings/{{name}}' base_url: 'apis/domains.cloudrun.com/v1/namespaces/{{project}}/domainmappings' cai_base_url: 'projects/{{project}}/locations/{{location}}/DomainMappings' -cai_asset_name_format: 'projects/{{project}}/locations/{{location}}/domainmappings/{{name}}' immutable: true import_format: - 'locations/{{location}}/namespaces/{{project}}/domainmappings/{{name}}' diff --git a/mmv1/products/cloudrun/Service.yaml b/mmv1/products/cloudrun/Service.yaml index 856517ad3b17..efc3d4418452 100644 --- a/mmv1/products/cloudrun/Service.yaml +++ b/mmv1/products/cloudrun/Service.yaml @@ -27,7 +27,6 @@ docs: id_format: 'locations/{{location}}/namespaces/{{project}}/services/{{name}}' base_url: 'apis/serving.knative.dev/v1/namespaces/{{project}}/services' cai_base_url: 'projects/{{project}}/locations/{{location}}/services' -cai_asset_name_format: 'projects/{{project}}/locations/{{location}}/services/{{name}}' import_format: - 'locations/{{location}}/namespaces/{{project}}/services/{{name}}' datasource: diff --git a/mmv1/products/compute/FirewallPolicyAssociation.yaml b/mmv1/products/compute/FirewallPolicyAssociation.yaml index 9af2b6a4ca61..883978848c79 100644 --- a/mmv1/products/compute/FirewallPolicyAssociation.yaml +++ b/mmv1/products/compute/FirewallPolicyAssociation.yaml @@ -14,7 +14,6 @@ --- name: 'FirewallPolicyAssociation' api_resource_type_kind: FirewallPolicy -api_resource_field: 'associations' kind: 'compute#firewallPolicyAssociation' description: | Allows associating hierarchical firewall policies with the target where they are applied. This allows creating policies and rules in a different location than they are applied. diff --git a/mmv1/products/compute/FirewallPolicyRule.yaml b/mmv1/products/compute/FirewallPolicyRule.yaml index aa4fa5441db9..230625d28de7 100644 --- a/mmv1/products/compute/FirewallPolicyRule.yaml +++ b/mmv1/products/compute/FirewallPolicyRule.yaml @@ -14,7 +14,6 @@ --- name: 'FirewallPolicyRule' api_resource_type_kind: FirewallPolicy -api_resource_field: 'rules' kind: 'compute#firewallPolicyRule' description: | Represents a rule that describes one or more match conditions along with the action to be taken when traffic matches this condition (allow or deny). diff --git a/mmv1/products/compute/InstanceSettings.yaml b/mmv1/products/compute/InstanceSettings.yaml index 5b58366ac2d0..1818f9aca839 100644 --- a/mmv1/products/compute/InstanceSettings.yaml +++ b/mmv1/products/compute/InstanceSettings.yaml @@ -29,7 +29,6 @@ update_url: 'projects/{{project}}/zones/{{zone}}/instanceSettings?update_mask=*' update_verb: 'PATCH' import_format: - 'projects/{{project}}/zones/{{zone}}/instanceSettings' -cai_asset_name_format: 'projects/{{project}}/zones/{{zone}}/instanceSettings/InstanceSettings' timeouts: insert_minutes: 20 update_minutes: 20 diff --git a/mmv1/products/compute/NetworkFirewallPolicyAssociation.yaml b/mmv1/products/compute/NetworkFirewallPolicyAssociation.yaml index d31876edcca3..dc8b27530382 100644 --- a/mmv1/products/compute/NetworkFirewallPolicyAssociation.yaml +++ b/mmv1/products/compute/NetworkFirewallPolicyAssociation.yaml @@ -14,7 +14,6 @@ --- name: 'NetworkFirewallPolicyAssociation' api_resource_type_kind: FirewallPolicy -api_resource_field: 'associations' kind: 'compute#firewallPolicyAssociation' description: | The Compute NetworkFirewallPolicyAssociation resource diff --git a/mmv1/products/compute/NetworkFirewallPolicyPacketMirroringRule.yaml b/mmv1/products/compute/NetworkFirewallPolicyPacketMirroringRule.yaml index 9e8c232a60e8..5631a6c00439 100644 --- a/mmv1/products/compute/NetworkFirewallPolicyPacketMirroringRule.yaml +++ b/mmv1/products/compute/NetworkFirewallPolicyPacketMirroringRule.yaml @@ -14,7 +14,6 @@ --- name: 'NetworkFirewallPolicyPacketMirroringRule' api_resource_type_kind: FirewallPolicy -api_resource_field: 'packetMirroringRules' kind: 'compute#packetMirroringRule' min_version: 'beta' description: | diff --git a/mmv1/products/compute/NetworkFirewallPolicyRule.yaml b/mmv1/products/compute/NetworkFirewallPolicyRule.yaml index 3547b8c344e0..6a249217f6bb 100644 --- a/mmv1/products/compute/NetworkFirewallPolicyRule.yaml +++ b/mmv1/products/compute/NetworkFirewallPolicyRule.yaml @@ -14,7 +14,6 @@ --- name: 'NetworkFirewallPolicyRule' api_resource_type_kind: FirewallPolicy -api_resource_field: 'rules' kind: 'compute#firewallPolicyRule' description: | Represents a rule that describes one or more match conditions along with the action to be taken when traffic matches this condition (allow or deny). diff --git a/mmv1/products/compute/NodeGroup.yaml b/mmv1/products/compute/NodeGroup.yaml index 02d0db656c09..3a854983c1db 100644 --- a/mmv1/products/compute/NodeGroup.yaml +++ b/mmv1/products/compute/NodeGroup.yaml @@ -39,7 +39,6 @@ async: resource_inside_response: false collection_url_key: 'items' custom_code: - constants: 'templates/terraform/constants/compute_node_group.go.tmpl' pre_create: 'templates/terraform/pre_create/compute_node_group_url_replace.go.tmpl' sweeper: url_substitutions: diff --git a/mmv1/products/compute/OrganizationSecurityPolicyAssociation.yaml b/mmv1/products/compute/OrganizationSecurityPolicyAssociation.yaml index 3f316dacc0d5..26487f435321 100644 --- a/mmv1/products/compute/OrganizationSecurityPolicyAssociation.yaml +++ b/mmv1/products/compute/OrganizationSecurityPolicyAssociation.yaml @@ -14,7 +14,6 @@ --- name: 'OrganizationSecurityPolicyAssociation' api_resource_type_kind: SecurityPolicy -api_resource_field: 'associations' description: | An association for the OrganizationSecurityPolicy. min_version: 'beta' diff --git a/mmv1/products/compute/OrganizationSecurityPolicyRule.yaml b/mmv1/products/compute/OrganizationSecurityPolicyRule.yaml index 025d997e65e4..4f5e748eced0 100644 --- a/mmv1/products/compute/OrganizationSecurityPolicyRule.yaml +++ b/mmv1/products/compute/OrganizationSecurityPolicyRule.yaml @@ -14,7 +14,6 @@ --- name: 'OrganizationSecurityPolicyRule' api_resource_type_kind: SecurityPolicy -api_resource_field: 'rules' description: | A rule for the OrganizationSecurityPolicy. min_version: 'beta' diff --git a/mmv1/products/compute/PublicAdvertisedPrefix.yaml b/mmv1/products/compute/PublicAdvertisedPrefix.yaml index d5d4673a6d87..7bb00b7ba536 100644 --- a/mmv1/products/compute/PublicAdvertisedPrefix.yaml +++ b/mmv1/products/compute/PublicAdvertisedPrefix.yaml @@ -54,15 +54,6 @@ examples: # PAPs have very low quota limits and a shared testing range so serialized tests exist in: # resource_compute_public_advertised_prefix_test.go exclude_test: true - - name: 'public_advertised_prefixes_ipv6_access_type' - primary_resource_id: 'prefixes' - vars: - prefixes_name: 'my-pap' - test_env_vars: - desc: 'PAP_DESCRIPTION' - # PAPs have very low quota limits and a shared testing range so serialized tests exist in: - # resource_compute_public_advertised_prefix_test.go - exclude_test: true parameters: properties: - name: 'description' @@ -81,6 +72,7 @@ properties: - name: 'dnsVerificationIp' type: String description: The IPv4 address to be used for reverse DNS verification. + required: true - name: 'ipCidrRange' type: String description: @@ -99,20 +91,6 @@ properties: enum_values: - 'GLOBAL' - 'REGIONAL' - - name: 'ipv6AccessType' - type: Enum - description: | - The internet access type for IPv6 Public Advertised Prefixes. It can be - set to one of following: - * EXTERNAL: Default access type. The prefix will be announced to the - internet. All children PDPs will have access type as EXTERNAL. - * INTERNAL: The prefix won’t be announced to the internet. Prefix will - be used privately within Google Cloud. All children PDPs will have - access type as INTERNAL. - default_from_api: true - enum_values: - - 'EXTERNAL' - - 'INTERNAL' - name: 'sharedSecret' type: String description: | diff --git a/mmv1/products/compute/RegionDisk.yaml b/mmv1/products/compute/RegionDisk.yaml index 6f683b300774..96b2149eac39 100644 --- a/mmv1/products/compute/RegionDisk.yaml +++ b/mmv1/products/compute/RegionDisk.yaml @@ -58,7 +58,6 @@ iam_policy: - 'projects/{{project}}/regions/{{region}}/disks/{{name}}' - '{{name}}' custom_code: - constants: 'templates/terraform/constants/region_disk.go.tmpl' encoder: 'templates/terraform/encoders/disk.tmpl' decoder: 'templates/terraform/decoders/disk.tmpl' update_encoder: 'templates/terraform/update_encoder/hyper_disk.go.tmpl' diff --git a/mmv1/products/compute/RegionNetworkFirewallPolicyAssociation.yaml b/mmv1/products/compute/RegionNetworkFirewallPolicyAssociation.yaml index fc5af6f0ba71..7810c00254bc 100644 --- a/mmv1/products/compute/RegionNetworkFirewallPolicyAssociation.yaml +++ b/mmv1/products/compute/RegionNetworkFirewallPolicyAssociation.yaml @@ -14,7 +14,6 @@ --- name: 'RegionNetworkFirewallPolicyAssociation' api_resource_type_kind: FirewallPolicy -api_resource_field: 'associations' kind: 'compute#firewallPolicyAssociation' description: | The Compute NetworkFirewallPolicyAssociation resource diff --git a/mmv1/products/compute/RegionNetworkFirewallPolicyRule.yaml b/mmv1/products/compute/RegionNetworkFirewallPolicyRule.yaml index 398e65482e7f..08c7290e7764 100644 --- a/mmv1/products/compute/RegionNetworkFirewallPolicyRule.yaml +++ b/mmv1/products/compute/RegionNetworkFirewallPolicyRule.yaml @@ -14,7 +14,6 @@ --- name: 'RegionNetworkFirewallPolicyRule' api_resource_type_kind: FirewallPolicy -api_resource_field: 'rules' kind: 'compute#firewallPolicyRule' description: | Represents a rule that describes one or more match conditions along with the action to be taken when traffic matches this condition (allow or deny). diff --git a/mmv1/products/compute/RegionSecurityPolicyRule.yaml b/mmv1/products/compute/RegionSecurityPolicyRule.yaml index 5b36c31fd5e0..1f0f8ab7a71b 100644 --- a/mmv1/products/compute/RegionSecurityPolicyRule.yaml +++ b/mmv1/products/compute/RegionSecurityPolicyRule.yaml @@ -14,7 +14,6 @@ --- name: 'RegionSecurityPolicyRule' api_resource_type_kind: SecurityPolicy -api_resource_field: 'rules' description: | A rule for the RegionSecurityPolicy. references: diff --git a/mmv1/products/compute/Reservation.yaml b/mmv1/products/compute/Reservation.yaml index c59b70c17e35..6bbb701a6b24 100644 --- a/mmv1/products/compute/Reservation.yaml +++ b/mmv1/products/compute/Reservation.yaml @@ -46,7 +46,6 @@ async: resource_inside_response: false collection_url_key: 'items' custom_code: - constants: 'templates/terraform/constants/reservation.go.tmpl' update_encoder: 'templates/terraform/update_encoder/reservation.go.tmpl' pre_update: 'templates/terraform/pre_update/shared_reservation_update.go.tmpl' sweeper: diff --git a/mmv1/products/compute/RouterNat.yaml b/mmv1/products/compute/RouterNat.yaml index b9fcc01199dd..8c35ac4e8a62 100644 --- a/mmv1/products/compute/RouterNat.yaml +++ b/mmv1/products/compute/RouterNat.yaml @@ -14,7 +14,6 @@ --- name: 'RouterNat' api_resource_type_kind: Router -api_resource_field: 'nats' description: | A NAT service created in a router. diff --git a/mmv1/products/compute/SecurityPolicyRule.yaml b/mmv1/products/compute/SecurityPolicyRule.yaml index 2d7e6433b4b4..1b80486b6dbc 100644 --- a/mmv1/products/compute/SecurityPolicyRule.yaml +++ b/mmv1/products/compute/SecurityPolicyRule.yaml @@ -14,7 +14,6 @@ --- name: 'SecurityPolicyRule' api_resource_type_kind: SecurityPolicy -api_resource_field: 'rules' description: | A rule for the SecurityPolicy. references: diff --git a/mmv1/products/dataproc/AutoscalingPolicy.yaml b/mmv1/products/dataproc/AutoscalingPolicy.yaml index c8cf76ae6b7e..e81468ea54be 100644 --- a/mmv1/products/dataproc/AutoscalingPolicy.yaml +++ b/mmv1/products/dataproc/AutoscalingPolicy.yaml @@ -23,7 +23,6 @@ base_url: 'projects/{{project}}/locations/{{location}}/autoscalingPolicies' self_link: 'projects/{{project}}/locations/{{location}}/autoscalingPolicies/{{policy_id}}' import_format: - 'projects/{{project}}/locations/{{location}}/autoscalingPolicies/{{policy_id}}' -cai_asset_name_format: 'projects/{{project}}/regions/{{location}}/autoscalingPolicies/{{policy_id}}' timeouts: insert_minutes: 20 update_minutes: 20 diff --git a/mmv1/products/dns/ManagedZone.yaml b/mmv1/products/dns/ManagedZone.yaml index cdc7010f59fb..742b629faccf 100644 --- a/mmv1/products/dns/ManagedZone.yaml +++ b/mmv1/products/dns/ManagedZone.yaml @@ -37,7 +37,6 @@ iam_policy: - 'projects/{{project}}/managedZones/{{managed_zone}}' - '{{project}}/{{managed_zone}}' custom_code: - constants: 'templates/terraform/constants/managed_dns_zone.go.tmpl' update_encoder: 'templates/terraform/update_encoder/managed_dns_zone.go.tmpl' pre_delete: 'templates/terraform/pre_delete/managed_dns_zone.go.tmpl' examples: diff --git a/mmv1/products/iam2/DenyPolicy.yaml b/mmv1/products/iam2/DenyPolicy.yaml index b661fea09dfd..f0d8fbfcbb63 100644 --- a/mmv1/products/iam2/DenyPolicy.yaml +++ b/mmv1/products/iam2/DenyPolicy.yaml @@ -26,7 +26,6 @@ base_url: 'policies/{{parent}}/denypolicies' create_url: 'policies/{{parent}}/denypolicies?policyId={{name}}' import_format: - '{{parent}}/{{name}}' -cai_asset_name_format: '{{parent}}/denypolicies/{{name}}' timeouts: insert_minutes: 20 update_minutes: 20 diff --git a/mmv1/products/logging/Metric.yaml b/mmv1/products/logging/Metric.yaml index 86eddaac4ae7..04a748a71323 100644 --- a/mmv1/products/logging/Metric.yaml +++ b/mmv1/products/logging/Metric.yaml @@ -27,7 +27,6 @@ id_format: '{{name}}' base_url: 'projects/{{project}}/metrics' # The % in self_link indicates that the name value should be URL-encoded. self_link: 'projects/{{project}}/metrics/{{%name}}' -cai_asset_name_format: 'projects/{{project}}/metrics/{{%name}}' mutex: 'customMetric/{{project}}' import_format: - '{{name}}' diff --git a/mmv1/products/metastore/Database.yaml b/mmv1/products/metastore/Database.yaml index 2e966896eaed..e0b820a70656 100644 --- a/mmv1/products/metastore/Database.yaml +++ b/mmv1/products/metastore/Database.yaml @@ -40,7 +40,6 @@ examples: - name: 'dataproc_metastore_service_database_iam' primary_resource_id: 'dpms_service' primary_resource_name: 'fmt.Sprintf("tf-test-metastore-srv-%s", context["random_suffix"]), "testdb"' - external_providers: ["time"] parameters: properties: - name: 'name' diff --git a/mmv1/products/metastore/Table.yaml b/mmv1/products/metastore/Table.yaml index 42840ae7ecd5..12576fa69358 100644 --- a/mmv1/products/metastore/Table.yaml +++ b/mmv1/products/metastore/Table.yaml @@ -40,7 +40,6 @@ examples: - name: 'dataproc_metastore_service_table_iam' primary_resource_id: 'dpms_service' primary_resource_name: 'fmt.Sprintf("tf-test-metastore-srv-%s", context["random_suffix"]), "testdb", "testtbl"' - external_providers: ["time"] parameters: properties: - name: 'name' diff --git a/mmv1/products/netapp/Volume.yaml b/mmv1/products/netapp/Volume.yaml index a82ea27c6102..c095d1e2483d 100644 --- a/mmv1/products/netapp/Volume.yaml +++ b/mmv1/products/netapp/Volume.yaml @@ -620,67 +620,6 @@ properties: description: | Total hot tier data rounded down to the nearest GiB used by the volume. This field is only used for flex Service Level output: true - - name: 'cacheParameters' - type: NestedObject - description: |- - Cache parameters for the volume. - properties: - - name: 'peerVolumeName' - type: String - description: | - Required. Name of the origin volume for the cache volume. - - name: 'peerClusterName' - type: String - description: | - Required. Name of the origin volume's ONTAP cluster. - - name: 'peerSvmName' - type: String - description: | - Required. Name of the origin volume's SVM. - - name: 'peerIpAddresses' - type: Array - description: | - Required. List of IC LIF addresses of the origin volume's ONTAP cluster. - item_type: - type: String - - name: 'enableGlobalFileLock' - type: Boolean - description: | - Optional. Field indicating whether cache volume as global file lock enabled. - - name: 'peeringCommandExpiryTime' - type: String - description: | - Optional. Expiration time for the peering command to be executed on user's ONTAP. A timestamp in RFC3339 UTC "Zulu" format. Examples: "2023-06-22T09:13:01.617Z". - default_from_api: true - - name: 'cacheState' - type: String - description: | - State of the cache volume indicating the peering status. - output: true - - name: 'command' - type: String - description: | - Copy-paste-able commands to be used on user's ONTAP to accept peering requests. - output: true - - name: 'passphrase' - type: String - description: | - Temporary passphrase generated to accept cluster peering command. - output: true - - name: 'stateDetails' - type: String - description: | - Detailed description of the current cache state. - output: true - - name: 'cacheConfig' - type: NestedObject - description: |- - Optional. Configuration of the cache volume. - properties: - - name: 'cifsChangeNotifyEnabled' - type: Boolean - description: | - Optional. Flag indicating whether a CIFS change notification is enabled for the FlexCache volume. - name: 'blockDevices' type: Array description: | diff --git a/mmv1/products/spanner/Database.yaml b/mmv1/products/spanner/Database.yaml index d7b7188f4f3b..a55393817cbb 100644 --- a/mmv1/products/spanner/Database.yaml +++ b/mmv1/products/spanner/Database.yaml @@ -37,7 +37,6 @@ import_format: - 'instances/{{instance}}/databases/{{name}}' - '{{project}}/{{instance}}/{{name}}' - '{{instance}}/{{name}}' -cai_asset_name_format: 'projects/{{project}}/instances/{{instance}}/databases/{{name}}' timeouts: insert_minutes: 20 update_minutes: 20 diff --git a/mmv1/products/spanner/Instance.yaml b/mmv1/products/spanner/Instance.yaml index 85d5ca06b241..5b453628b69b 100644 --- a/mmv1/products/spanner/Instance.yaml +++ b/mmv1/products/spanner/Instance.yaml @@ -28,7 +28,6 @@ import_format: - 'projects/{{project}}/instances/{{name}}' - '{{project}}/{{name}}' - '{{name}}' -cai_asset_name_format: 'projects/{{project}}/instances/{{name}}' timeouts: insert_minutes: 20 update_minutes: 20 diff --git a/mmv1/products/storage/Folder.yaml b/mmv1/products/storage/Folder.yaml index 52809f129890..95ceb368b8ca 100644 --- a/mmv1/products/storage/Folder.yaml +++ b/mmv1/products/storage/Folder.yaml @@ -43,7 +43,6 @@ references: 'Official Documentation': 'https://cloud.google.com/storage/docs/folders-overview' api: 'https://cloud.google.com/storage/docs/json_api/v1/folders' custom_code: - constants: templates/terraform/constants/storage_folder.go.tmpl custom_import: templates/terraform/custom_import/storage_folder.go.tmpl custom_update: templates/terraform/custom_update/storage_folder_update.go.tmpl custom_delete: templates/terraform/custom_delete/storage_folder_delete.go.tmpl diff --git a/mmv1/provider/template_data.go b/mmv1/provider/template_data.go index e7993ff9e405..f88286634864 100644 --- a/mmv1/provider/template_data.go +++ b/mmv1/provider/template_data.go @@ -347,8 +347,7 @@ func FixImports(outputPath string, dumpDiffs bool) { }) if hasFiles { - log.Printf("Fixing go import paths") - cmd := exec.Command("echo", args...) + cmd := exec.Command("goimports", args...) cmd.Dir = outputPath cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr diff --git a/mmv1/provider/terraform.go b/mmv1/provider/terraform.go index ebd395c797d6..32424a58ea89 100644 --- a/mmv1/provider/terraform.go +++ b/mmv1/provider/terraform.go @@ -299,7 +299,7 @@ func (t *Terraform) GenerateIamPolicy(object api.Resource, templateData Template templateData.GenerateIamPolicyFile(targetFilePath, object) // Only generate test if testable examples exist. - examples := google.Reject(object.Examples, func(e *resource.Examples) bool { + examples := google.Reject(object.Examples, func(e resource.Examples) bool { return e.ExcludeTest }) if len(examples) != 0 { diff --git a/mmv1/provider/terraform_tgc_next.go b/mmv1/provider/terraform_tgc_next.go index 4d4fe10e756a..c403caeaac0e 100644 --- a/mmv1/provider/terraform_tgc_next.go +++ b/mmv1/provider/terraform_tgc_next.go @@ -372,7 +372,7 @@ func (tgc *TerraformGoogleConversionNext) generateResourcesForVersion(products [ TerraformName: object.TerraformName(), ResourceName: object.ResourceName(), AliasName: object.ResourceName(), - CaiAssetNameFormat: object.GetCaiAssetNameTemplate(), + CaiAssetNameFormat: object.GetCaiAssetNameFormat(), } tgc.ResourcesForVersion = append(tgc.ResourcesForVersion, resourceIdentifier) diff --git a/mmv1/templates/terraform/constants/bigtable_app_profile_routing.go.tmpl b/mmv1/templates/terraform/constants/bigtable_app_profile_routing.go.tmpl deleted file mode 100644 index d60c838978a2..000000000000 --- a/mmv1/templates/terraform/constants/bigtable_app_profile_routing.go.tmpl +++ /dev/null @@ -1 +0,0 @@ -import "google.golang.org/api/bigtableadmin/v2" diff --git a/mmv1/templates/terraform/constants/compute_certificate.go.tmpl b/mmv1/templates/terraform/constants/compute_certificate.go.tmpl index dfce2a1f51c1..f5f6aae3c09d 100644 --- a/mmv1/templates/terraform/constants/compute_certificate.go.tmpl +++ b/mmv1/templates/terraform/constants/compute_certificate.go.tmpl @@ -1,8 +1,3 @@ -import ( - "crypto/sha256" - "encoding/hex" -) - // sha256DiffSuppress // if old is the hex-encoded sha256 sum of new, treat them as equal func sha256DiffSuppress(_, old, new string, _ *schema.ResourceData) bool { diff --git a/mmv1/templates/terraform/constants/compute_forwarding_rule.go.tmpl b/mmv1/templates/terraform/constants/compute_forwarding_rule.go.tmpl index d8e1d47eb059..17d3697ffb1d 100644 --- a/mmv1/templates/terraform/constants/compute_forwarding_rule.go.tmpl +++ b/mmv1/templates/terraform/constants/compute_forwarding_rule.go.tmpl @@ -1,5 +1,3 @@ -import "net" - func forwardingRuleCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { log.Println("[DEBUG] [PSC] Reached forwardingRuleCustomizeDiff function") diff --git a/mmv1/templates/terraform/constants/compute_node_group.go.tmpl b/mmv1/templates/terraform/constants/compute_node_group.go.tmpl deleted file mode 100644 index 6b6ddd1b8bdd..000000000000 --- a/mmv1/templates/terraform/constants/compute_node_group.go.tmpl +++ /dev/null @@ -1,3 +0,0 @@ -import "errors" - -var _ = errors.New diff --git a/mmv1/templates/terraform/constants/compute_route.go.tmpl b/mmv1/templates/terraform/constants/compute_route.go.tmpl index 2f3b121fa26c..915d204a137f 100644 --- a/mmv1/templates/terraform/constants/compute_route.go.tmpl +++ b/mmv1/templates/terraform/constants/compute_route.go.tmpl @@ -1,5 +1,3 @@ -import "net" - // Use this method when the field accepts either an IP address or a // self_link referencing a resource (such as google_compute_route's // next_hop_ilb) diff --git a/mmv1/templates/terraform/constants/disk.tmpl b/mmv1/templates/terraform/constants/disk.tmpl index e5e3b2354978..36a4041ce642 100644 --- a/mmv1/templates/terraform/constants/disk.tmpl +++ b/mmv1/templates/terraform/constants/disk.tmpl @@ -1,6 +1,3 @@ -import "errors" - -var _ = errors.New {{- if ne $.Compiler "terraformgoogleconversion-codegen" }} // diffsuppress for hyperdisk provisioned_iops diff --git a/mmv1/templates/terraform/constants/managed_dns_zone.go.tmpl b/mmv1/templates/terraform/constants/managed_dns_zone.go.tmpl deleted file mode 100644 index 2d8a3b6daaaa..000000000000 --- a/mmv1/templates/terraform/constants/managed_dns_zone.go.tmpl +++ /dev/null @@ -1,3 +0,0 @@ -import "google.golang.org/api/dns/v1" - -var _ = dns.NewService diff --git a/mmv1/templates/terraform/constants/region_disk.go.tmpl b/mmv1/templates/terraform/constants/region_disk.go.tmpl deleted file mode 100644 index 71c2bdbfb256..000000000000 --- a/mmv1/templates/terraform/constants/region_disk.go.tmpl +++ /dev/null @@ -1,3 +0,0 @@ -import "errors" - -var _ = errors.New \ No newline at end of file diff --git a/mmv1/templates/terraform/constants/reservation.go.tmpl b/mmv1/templates/terraform/constants/reservation.go.tmpl deleted file mode 100644 index f6ffb20d4509..000000000000 --- a/mmv1/templates/terraform/constants/reservation.go.tmpl +++ /dev/null @@ -1,3 +0,0 @@ -import "net/url" - -var _ = url.Parse diff --git a/mmv1/templates/terraform/constants/storage_folder.go.tmpl b/mmv1/templates/terraform/constants/storage_folder.go.tmpl deleted file mode 100644 index 813f3144724a..000000000000 --- a/mmv1/templates/terraform/constants/storage_folder.go.tmpl +++ /dev/null @@ -1,9 +0,0 @@ -import ( - "runtime" - "github.com/gammazero/workerpool" -) - -var ( - _ = runtime.GOARCH - _ = workerpool.New -) diff --git a/mmv1/templates/terraform/constants/subnetwork.tmpl b/mmv1/templates/terraform/constants/subnetwork.tmpl index e9a7aa0d5382..9969642edc58 100644 --- a/mmv1/templates/terraform/constants/subnetwork.tmpl +++ b/mmv1/templates/terraform/constants/subnetwork.tmpl @@ -1,8 +1,3 @@ -import ( - "net" - "github.com/apparentlymart/go-cidr/cidr" -) - // Whether the IP CIDR change shrinks the block. func IsShrinkageIpCidr(_ context.Context, old, new, _ interface{}) bool { _, oldCidr, oldErr := net.ParseCIDR(old.(string)) diff --git a/mmv1/templates/terraform/constants/vpn_tunnel.tmpl b/mmv1/templates/terraform/constants/vpn_tunnel.tmpl index 5b603a62f78b..1b25e0ae770d 100644 --- a/mmv1/templates/terraform/constants/vpn_tunnel.tmpl +++ b/mmv1/templates/terraform/constants/vpn_tunnel.tmpl @@ -1,5 +1,3 @@ -import "net" - // validatePeerAddr returns false if a tunnel's peer_ip property // is invalid. Currently, only addresses that collide with RFC // 5735 (https://tools.ietf.org/html/rfc5735) fail validation. diff --git a/mmv1/templates/terraform/custom_expand/containerattached_cluster_authorization_user.go.tmpl b/mmv1/templates/terraform/custom_expand/containerattached_cluster_authorization_user.go.tmpl index 64696f718a25..4d3eba6ea01b 100644 --- a/mmv1/templates/terraform/custom_expand/containerattached_cluster_authorization_user.go.tmpl +++ b/mmv1/templates/terraform/custom_expand/containerattached_cluster_authorization_user.go.tmpl @@ -20,30 +20,27 @@ type attachedClusterGroup struct { } // The custom expander transforms input into something like this: -// -// authorization { -// admin_users [ -// { username = "user1" }, -// { username = "user2" } -// ] -// admin_groups [ -// { group = "group1" }, -// { group = "group2" }, -// ] -// } -// +// authorization { +// admin_users [ +// { username = "user1" }, +// { username = "user2" } +// ] +// admin_groups [ +// { group = "group1" }, +// { group = "group2" }, +// ] +// } // The custom flattener transforms input back into something like this: -// -// authorization { -// admin_users = [ -// "user1", -// "user2" -// ] -// admin_groups = [ -// "group1", -// "group2" -// ], -// } +// authorization { +// admin_users = [ +// "user1", +// "user2" +// ] +// admin_groups = [ +// "group1", +// "group2" +// ], +// } func expand{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { diff --git a/mmv1/templates/terraform/custom_flatten/containerattached_cluster_authorization_user.go.tmpl b/mmv1/templates/terraform/custom_flatten/containerattached_cluster_authorization_user.go.tmpl index afdadfed7db7..7a145d0ade70 100644 --- a/mmv1/templates/terraform/custom_flatten/containerattached_cluster_authorization_user.go.tmpl +++ b/mmv1/templates/terraform/custom_flatten/containerattached_cluster_authorization_user.go.tmpl @@ -12,30 +12,27 @@ */ -}} // The custom expander transforms input into something like this: -// -// authorization { -// admin_users [ -// { username = "user1" }, -// { username = "user2" } -// ] -// admin_groups [ -// { group = "group1" }, -// { group = "group2" }, -// ] -// } -// +// authorization { +// admin_users [ +// { username = "user1" }, +// { username = "user2" } +// ] +// admin_groups [ +// { group = "group1" }, +// { group = "group2" }, +// ] +// } // The custom flattener transforms input back into something like this: -// -// authorization { -// admin_users = [ -// "user1", -// "user2" -// ] -// admin_groups = [ -// "group1", -// "group2" -// ], -// } +// authorization { +// admin_users = [ +// "user1", +// "user2" +// ] +// admin_groups = [ +// "group1", +// "group2" +// ], +// } func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil || len(v.(map[string]interface{})) == 0 { return nil diff --git a/mmv1/templates/terraform/datasource.go.tmpl b/mmv1/templates/terraform/datasource.go.tmpl index d9d330948aa8..edd29d3c1dd5 100644 --- a/mmv1/templates/terraform/datasource.go.tmpl +++ b/mmv1/templates/terraform/datasource.go.tmpl @@ -19,56 +19,38 @@ package {{ lower $.ProductMetadata.Name }} import ( + "fmt" "log" "net/http" "reflect" +{{- if $.SupportsIndirectUserProjectOverride }} "regexp" +{{- end }} +{{- if or (and (not $.Immutable) ($.UpdateMask)) $.LegacyLongFormProject }} "strings" +{{- end }} "time" - "github.com/hashicorp/errwrap" - "github.com/hashicorp/go-cty/cty" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" +{{/* # We list all the v2 imports here, because we run 'goimports' to guess the correct */}} +{{/* # set of imports, which will never guess the major version correctly. */}} + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" + "github.com/hashicorp/go-cty/cty" "{{ $.ImportPath }}/tpgresource" transport_tpg "{{ $.ImportPath }}/transport" "{{ $.ImportPath }}/verify" +{{ if $.FlattenedProperties }} "google.golang.org/api/googleapi" -) - -var ( - _ = fmt.Sprintf - _ = log.Print - _ = http.Get - _ = reflect.ValueOf - _ = regexp.Match - _ = strings.Trim - _ = time.Now - _ = errwrap.Wrap - _ = cty.BoolVal - _ = diag.Diagnostic{} - _ = customdiff.All - _ = id.UniqueId - _ = logging.LogLevel - _ = retry.Retry - _ = schema.Noop - _ = validation.All - _ = structure.ExpandJsonFromString - _ = terraform.State{} - _ = tpgresource.SetLabels - _ = transport_tpg.Config{} - _ = verify.ValidateEnum - _ = googleapi.Error{} +{{- end}} ) func DataSource{{ .ResourceName -}}() *schema.Resource { diff --git a/mmv1/templates/terraform/examples/base_configs/datasource_test_file.go.tmpl b/mmv1/templates/terraform/examples/base_configs/datasource_test_file.go.tmpl index 38ecbae6ea8d..d97844de1675 100644 --- a/mmv1/templates/terraform/examples/base_configs/datasource_test_file.go.tmpl +++ b/mmv1/templates/terraform/examples/base_configs/datasource_test_file.go.tmpl @@ -28,12 +28,6 @@ import ( "{{ $.ImportPath }}/tpgresource" ) -var ( - _ = fmt.Sprintf - _ = envvar.TestEnvVar - _ = tpgresource.SetLabels -) - {{ if $.Res.TestExamples }} {{ $e := index $.Res.TestExamples 0 }} func TestAccDataSource{{ $.Res.ResourceName }}_basic(t *testing.T) { diff --git a/mmv1/templates/terraform/examples/base_configs/iam_test_file.go.tmpl b/mmv1/templates/terraform/examples/base_configs/iam_test_file.go.tmpl index 965c57c9cb11..4bb4d9d3a9a6 100644 --- a/mmv1/templates/terraform/examples/base_configs/iam_test_file.go.tmpl +++ b/mmv1/templates/terraform/examples/base_configs/iam_test_file.go.tmpl @@ -7,23 +7,16 @@ package {{ lower $.ProductMetadata.Name }}_test import ( "fmt" - "strings" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "{{ $.ImportPath }}/acctest" "{{ $.ImportPath }}/envvar" + {{- if $.IamPolicy.IamConditionsRequestType }} "{{ $.ImportPath }}/tpgresource" + {{- end }} ) - -var ( - _ = fmt.Sprintf - _ = strings.Trim - _ = envvar.TestEnvVar - _ = tpgresource.SetLabels -) - {{ $example := $.FirstTestExample }} func TestAcc{{ $.ResourceName }}IamBindingGenerated(t *testing.T) { t.Parallel() diff --git a/mmv1/templates/terraform/examples/base_configs/test_file.go.tmpl b/mmv1/templates/terraform/examples/base_configs/test_file.go.tmpl index 712dbdd7815b..b9efdcdabe03 100644 --- a/mmv1/templates/terraform/examples/base_configs/test_file.go.tmpl +++ b/mmv1/templates/terraform/examples/base_configs/test_file.go.tmpl @@ -18,38 +18,24 @@ package {{ $.Res.PackageName }}_test import ( +{{- if not $.Res.ExcludeDelete }} + {{- if not $.Res.CustomCode.TestCheckDestroy }} "fmt" - "log" - "strconv" + {{- end }} "strings" +{{- end }} "testing" - "time" "github.com/hashicorp/terraform-plugin-testing/helper/resource" +{{- if not $.Res.ExcludeDelete }} "github.com/hashicorp/terraform-plugin-testing/terraform" +{{- end }} "{{ $.ImportPath }}/acctest" "{{ $.ImportPath }}/envvar" "{{ $.ImportPath }}/tpgresource" transport_tpg "{{ $.ImportPath }}/transport" - - "google.golang.org/api/googleapi" ) - -var ( - _ = fmt.Sprintf - _ = log.Print - _ = strconv.Atoi - _ = strings.Trim - _ = time.Now - _ = resource.TestMain - _ = terraform.NewState - _ = envvar.TestEnvVar - _ = tpgresource.SetLabels - _ = transport_tpg.Config{} - _ = googleapi.Error{} -) - {{ range $e := $.Res.TestExamples }} func TestAcc{{ $e.TestSlug $.Res.ProductMetadata.Name $.Res.Name }}(t *testing.T) { {{- if $e.SkipTest }} diff --git a/mmv1/templates/terraform/examples/dataproc_metastore_service_database_iam.tf.tmpl b/mmv1/templates/terraform/examples/dataproc_metastore_service_database_iam.tf.tmpl index 9b28511efeb9..3f5a4f846a27 100644 --- a/mmv1/templates/terraform/examples/dataproc_metastore_service_database_iam.tf.tmpl +++ b/mmv1/templates/terraform/examples/dataproc_metastore_service_database_iam.tf.tmpl @@ -57,11 +57,3 @@ resource "google_dataproc_job" "hive" { ] } } - -# There is no simple way to wait on the Dataproc job to be SUCCESS -# rather than RUNNING. -resource "time_sleep" "wait_hive_job" { - create_duration = "90s" - depends_on = [google_dataproc_job.hive] -} - diff --git a/mmv1/templates/terraform/examples/dataproc_metastore_service_table_iam.tf.tmpl b/mmv1/templates/terraform/examples/dataproc_metastore_service_table_iam.tf.tmpl index 9fdd749e918d..4b253a9e4938 100644 --- a/mmv1/templates/terraform/examples/dataproc_metastore_service_table_iam.tf.tmpl +++ b/mmv1/templates/terraform/examples/dataproc_metastore_service_table_iam.tf.tmpl @@ -59,11 +59,3 @@ resource "google_dataproc_job" "hive" { ] } } - -# There is no simple way to wait on the Dataproc job to be SUCCESS -# rather than RUNNING. -resource "time_sleep" "wait_hive_job" { - create_duration = "90s" - depends_on = [google_dataproc_job.hive] -} - diff --git a/mmv1/templates/terraform/examples/public_advertised_prefixes_ipv6_access_type.tf.tmpl b/mmv1/templates/terraform/examples/public_advertised_prefixes_ipv6_access_type.tf.tmpl deleted file mode 100644 index 3724c232f40e..000000000000 --- a/mmv1/templates/terraform/examples/public_advertised_prefixes_ipv6_access_type.tf.tmpl +++ /dev/null @@ -1,7 +0,0 @@ -resource "google_compute_public_advertised_prefix" "{{$.PrimaryResourceId}}" { - name = "{{index $.Vars "prefixes_name"}}" - description = "{{index $.TestEnvVars "desc"}}" - ip_cidr_range = "2001:db8::/32" - pdp_scope = "REGIONAL" - ipv6_access_type = "INTERNAL" -} \ No newline at end of file diff --git a/mmv1/templates/terraform/iam_policy.go.tmpl b/mmv1/templates/terraform/iam_policy.go.tmpl index 64a8eefaf932..3d8408921949 100644 --- a/mmv1/templates/terraform/iam_policy.go.tmpl +++ b/mmv1/templates/terraform/iam_policy.go.tmpl @@ -22,8 +22,6 @@ package {{ lower $.ProductMetadata.Name }} import ( "fmt" - "regexp" - "strings" "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -34,13 +32,6 @@ import ( transport_tpg "{{ $.ImportPath }}/transport" ) -var ( - _ = regexp.Match - _ = strings.Trim - _ = errwrap.Wrap - _ = schema.Noop -) - var {{ $.ResourceName }}IamSchema = map[string]*schema.Schema{ {{- range $i, $param := $.IamResourceParams }} "{{ underscore $param }}": { @@ -235,13 +226,13 @@ func (u *{{ $.ResourceName }}IamUpdater) GetResourceIamPolicy() (*cloudresourcem {{- end }} }) if err != nil { - return nil, fmt.Errorf("Error retrieving IAM policy for %s: %w", u.DescribeResource(), err) + return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{"{{"}}err{{"}}"}}", u.DescribeResource()), err) } out := &cloudresourcemanager.Policy{} err = tpgresource.Convert(policy, out) if err != nil { - return nil, fmt.Errorf("Cannot convert a policy to a resource manager policy: %w", err) + return nil, errwrap.Wrapf("Cannot convert a policy to a resource manager policy: {{"{{"}}err{{"}}"}}", err) } return out, nil @@ -299,7 +290,7 @@ func (u *{{ $.ResourceName }}IamUpdater) SetResourceIamPolicy(policy *cloudresou {{- end }} }) if err != nil { - return fmt.Errorf("Error setting IAM policy for %s: %w", u.DescribeResource(), err) + return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{"{{"}}err{{"}}"}}", u.DescribeResource()), err) } return nil diff --git a/mmv1/templates/terraform/metadata.yaml.tmpl b/mmv1/templates/terraform/metadata.yaml.tmpl index 7fd7cd41dfac..6771d8aa804f 100644 --- a/mmv1/templates/terraform/metadata.yaml.tmpl +++ b/mmv1/templates/terraform/metadata.yaml.tmpl @@ -4,9 +4,6 @@ source_file: '{{ $.SourceYamlFile }}' api_service_name: '{{ $.ProductMetadata.ServiceName }}' api_version: '{{ or $.ProductMetadata.ServiceVersion $.ServiceVersion }}' api_resource_type_kind: '{{ or $.ApiResourceTypeKind $.Name }}' -{{- if $.CAIFormatOverride }} -cai_asset_name_format: '{{ $.CAIFormatOverride }}' -{{- end }} {{- if gt (len $.ApiVariantPatterns) 0 }} api_variant_patterns: {{- range $v := $.ApiVariantPatterns }} diff --git a/mmv1/templates/terraform/operation.go.tmpl b/mmv1/templates/terraform/operation.go.tmpl index 91b3694824af..d31554165a0e 100644 --- a/mmv1/templates/terraform/operation.go.tmpl +++ b/mmv1/templates/terraform/operation.go.tmpl @@ -22,26 +22,10 @@ import ( "encoding/json" "errors" "fmt" - "log" - "strings" "time" "{{ $.ImportPath }}/tpgresource" transport_tpg "{{ $.ImportPath }}/transport" - - "google.golang.org/api/googleapi" -) - -var ( - _ = json.Marshal - _ = errors.New - _ = fmt.Sprintf - _ = log.Print - _ = strings.Trim - _ = time.Now - _ = tpgresource.SetLabels - _ = transport_tpg.Config{} - _ = googleapi.Error{} ) type {{ $.ProductMetadata.Name }}OperationWaiter struct { diff --git a/mmv1/templates/terraform/resource.go.tmpl b/mmv1/templates/terraform/resource.go.tmpl index 92c9aad94ea4..9027489adaac 100644 --- a/mmv1/templates/terraform/resource.go.tmpl +++ b/mmv1/templates/terraform/resource.go.tmpl @@ -20,76 +20,44 @@ package {{ lower $.ProductMetadata.Name }} import ( - "bytes" - "context" - "encoding/base64" - "encoding/json" + "fmt" "log" "net/http" "reflect" +{{- if $.SupportsIndirectUserProjectOverride }} "regexp" - "slices" - "sort" - "strconv" +{{- end }} +{{- if or (and (not $.Immutable) ($.UpdateMask)) $.LegacyLongFormProject }} "strings" +{{- end }} "time" - "github.com/hashicorp/errwrap" - "github.com/hashicorp/go-cty/cty" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" +{{/* # We list all the v2 imports here, because we run 'goimports' to guess the correct */}} +{{/* # set of imports, which will never guess the major version correctly. */}} + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" + "github.com/hashicorp/go-cty/cty" "{{ $.ImportPath }}/tpgresource" transport_tpg "{{ $.ImportPath }}/transport" "{{ $.ImportPath }}/verify" +{{ if $.FlattenedProperties }} "google.golang.org/api/googleapi" +{{- end}} ) {{if $.CustomCode.Constants -}} {{- $.CustomTemplate $.CustomCode.Constants true -}} {{- end}} -var ( - _ = bytes.Clone - _ = context.WithCancel - _ = base64.NewDecoder - _ = json.Marshal - _ = fmt.Sprintf - _ = log.Print - _ = http.Get - _ = reflect.ValueOf - _ = regexp.Match - _ = slices.Min([]int{1}) - _ = sort.IntSlice{} - _ = strconv.Atoi - _ = strings.Trim - _ = time.Now - _ = errwrap.Wrap - _ = cty.BoolVal - _ = diag.Diagnostic{} - _ = customdiff.All - _ = id.UniqueId - _ = logging.LogLevel - _ = retry.Retry - _ = schema.Noop - _ = validation.All - _ = structure.ExpandJsonFromString - _ = terraform.State{} - _ = tpgresource.SetLabels - _ = transport_tpg.Config{} - _ = verify.ValidateEnum - _ = googleapi.Error{} -) - func Resource{{ $.ResourceName -}}() *schema.Resource { return &schema.Resource{ Create: resource{{ $.ResourceName -}}Create, diff --git a/mmv1/templates/tgc/resource_converter.go.tmpl b/mmv1/templates/tgc/resource_converter.go.tmpl index ea16f589e815..d637ea2b8469 100644 --- a/mmv1/templates/tgc/resource_converter.go.tmpl +++ b/mmv1/templates/tgc/resource_converter.go.tmpl @@ -17,75 +17,36 @@ package {{ lower $.ProductMetadata.Name }} import ( - "bytes" - "context" - "encoding/base64" - "encoding/json" - "fmt" - "log" - "reflect" - "regexp" - "slices" - "sort" - "strconv" - "strings" - "time" - - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" +{{/* We list all the v2 imports here and unstable imports, because we run 'goimports' to guess the correct + set of imports, which will never guess the major version correctly. */ -}} + "github.com/apparentlymart/go-cidr/cidr" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" + "google.golang.org/api/bigtableadmin/v2" + "google.golang.org/api/googleapi" "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/cai" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" "github.com/hashicorp/terraform-provider-google-beta/google-beta/verify" - - "google.golang.org/api/googleapi" -) - -{{if $.CustomCode.Constants -}} - {{- $.CustomTemplate $.CustomCode.Constants true -}} -{{- end}} - -var ( - _ = bytes.Clone - _ = context.WithCancel - _ = base64.StdEncoding - _ = fmt.Sprintf - _ = json.Marshal - _ = log.Print - _ = reflect.ValueOf - _ = regexp.Match - _ = slices.Min([]int{1}) - _ = sort.IntSlice{} - _ = strconv.Atoi - _ = strings.Trim - _ = time.Now - _ = diag.Diagnostic{} - _ = customdiff.All - _ = id.UniqueId - _ = logging.LogLevel - _ = retry.Retry - _ = schema.Noop - _ = structure.ExpandJsonFromString - _ = validation.All - _ = terraform.State{} - _ = tpgresource.SetLabels - _ = transport_tpg.Config{} - _ = verify.ProjectRegex - _ = googleapi.Error{} ) {{- $caiProductBaseUrl := $.CaiProductBaseUrl }} {{- $productBackendName := $.CaiProductBackendName $caiProductBaseUrl }} {{- $apiVersion := $.CaiApiVersion $productBackendName $caiProductBaseUrl}} +{{if $.CustomCode.Constants -}} + {{- $.CustomTemplate $.CustomCode.Constants true -}} +{{- end}} + const {{ $.ResourceName -}}AssetType string = "{{ $productBackendName }}.googleapis.com/{{ $.Name -}}" func ResourceConverter{{ $.ResourceName -}}() cai.ResourceConverter { @@ -96,7 +57,7 @@ func ResourceConverter{{ $.ResourceName -}}() cai.ResourceConverter { } func Get{{ $.ResourceName -}}CaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { - name, err := cai.AssetName(d, config, "{{ $.GetCaiAssetNameTemplate }}") + name, err := cai.AssetName(d, config, "{{ $.CaiAssetNameTemplate $productBackendName }}") if err != nil { return []cai.Asset{}, err } diff --git a/mmv1/templates/tgc_next/cai2hcl/convert_resource.go.tmpl b/mmv1/templates/tgc_next/cai2hcl/convert_resource.go.tmpl index 420f14280d6e..981945977cd6 100644 --- a/mmv1/templates/tgc_next/cai2hcl/convert_resource.go.tmpl +++ b/mmv1/templates/tgc_next/cai2hcl/convert_resource.go.tmpl @@ -17,6 +17,11 @@ package converters import ( "strings" +{{- range $resourceType, $resources := $.ResourcesByCaiResourceType}} + {{- if gt (len $resources) 1 }} + "github.com/hashicorp/terraform-provider-google/google/services/{{ (index $resources 0).ServiceName }}" + {{- end }} +{{- end }} "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/cai2hcl/models" "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/caiasset" ) diff --git a/mmv1/templates/tgc_next/cai2hcl/resource_converters.go.tmpl b/mmv1/templates/tgc_next/cai2hcl/resource_converters.go.tmpl index ae8d0fd07504..bd0ea487622b 100644 --- a/mmv1/templates/tgc_next/cai2hcl/resource_converters.go.tmpl +++ b/mmv1/templates/tgc_next/cai2hcl/resource_converters.go.tmpl @@ -29,10 +29,8 @@ package converters import ( "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/cai2hcl/models" - {{- range $caiResourceType, $resources := $.ResourcesByCaiResourceType}} - {{- range $object := $resources }} - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/{{ $object.ServiceName }}" - {{- end }} + {{- range $service := $.Products }} + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/{{ lower $service.Name }}" {{- end }} "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/resourcemanager" diff --git a/mmv1/templates/tgc_next/services/resource.go.tmpl b/mmv1/templates/tgc_next/services/resource.go.tmpl index 73f9703f7b8e..38e464e58b24 100644 --- a/mmv1/templates/tgc_next/services/resource.go.tmpl +++ b/mmv1/templates/tgc_next/services/resource.go.tmpl @@ -17,53 +17,26 @@ package {{ lower $.ProductMetadata.Name }} import ( - "bytes" - "context" - "fmt" - "log" - "reflect" - "regexp" - "sort" - "strconv" - "strings" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/apparentlymart/go-cidr/cidr" "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/tgcresource" "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/tpgresource" transport_tpg "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/transport" "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/verify" ) -{{if $.CustomCode.Constants -}} - {{- $.CustomTemplate $.CustomCode.Constants true -}} -{{- end}} - -var ( - _ = bytes.Clone - _ = context.WithCancel - _ = fmt.Sprintf - _ = log.Print - _ = reflect.ValueOf - _ = regexp.Match - _ = sort.IntSlice{} - _ = strconv.Atoi - _ = strings.Trim - _ = schema.Noop - _ = validation.All - _ = tgcresource.RemoveTerraformAttributionLabel - _ = tpgresource.GetRegion - _ = transport_tpg.Config{} - _ = verify.ProjectRegex -) - {{ if $.DefineAssetTypeForResourceInProduct -}} const {{ $.CaiResourceType -}}AssetType string = "{{ $.CaiAssetType }}" {{- end }} const {{ $.ResourceName -}}SchemaName string = "{{ $.TerraformName }}" +{{if $.CustomCode.Constants -}} + {{- $.CustomTemplate $.CustomCode.Constants true -}} +{{- end}} + func Resource{{ $.ResourceName -}}() *schema.Resource { return &schema.Resource{ Schema: map[string]*schema.Schema{ diff --git a/mmv1/templates/tgc_next/tfplan2cai/resource_converters.go.tmpl b/mmv1/templates/tgc_next/tfplan2cai/resource_converters.go.tmpl index 1de33339c1fa..f38e81dfb41b 100644 --- a/mmv1/templates/tgc_next/tfplan2cai/resource_converters.go.tmpl +++ b/mmv1/templates/tgc_next/tfplan2cai/resource_converters.go.tmpl @@ -29,8 +29,8 @@ package converters import ( "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/tfplan2cai/converters/cai" - {{- range $object := $.ResourcesForVersion }} - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/{{ $object.ServiceName }}" + {{- range $service := $.Products }} + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/{{ lower $service.Name }}" {{- end }} "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/resourcemanager" ) diff --git a/mmv1/third_party/terraform/acctest/tgc_utils.go b/mmv1/third_party/terraform/acctest/tgc_utils.go index 5b27f962dbee..96895909d59b 100644 --- a/mmv1/third_party/terraform/acctest/tgc_utils.go +++ b/mmv1/third_party/terraform/acctest/tgc_utils.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "log" - "net/url" "regexp" "strings" "testing" @@ -55,7 +54,6 @@ var serviceWithProjectNumber = map[string]struct{}{ "discoveryengine": {}, "documentai": {}, "healthcare": {}, - "iambeta": {}, "iap": {}, "identityplatform": {}, "logging": {}, @@ -142,11 +140,6 @@ func CollectAllTgcMetadata(tgcPayload TgcMetadataPayload) resource.TestCheckFunc } caiAssetName := replacePlaceholders(caiAssetNameFormat, paramsMap) - - if _, ok := serviceWithProjectNumber[metadata.Service]; ok { - caiAssetName = strings.Replace(caiAssetName, projectId, projectNumber, 1) - } - metadata.CaiAssetNames = []string{caiAssetName} } @@ -189,19 +182,13 @@ func extractIdentifiers(url string) []string { // It replaces all instances of {{key}} in the template with the // corresponding value from the parameters map. func replacePlaceholders(template string, params map[string]any) string { - re := regexp.MustCompile("{{([%[:word:]]+)}}") + re := regexp.MustCompile(`\{\{([a-zA-Z0-9_]+)\}\}`) result := re.ReplaceAllStringFunc(template, func(match string) string { key := strings.Trim(match, "{}") - // The % indicates that the name value should be URL-encoded. - key, shouldBeEncoded := strings.CutPrefix(key, "%") if value, ok := params[key]; ok { - v := value.(string) - if !shouldBeEncoded { - return v - } - return url.PathEscape(v) + return value.(string) } return match diff --git a/mmv1/third_party/terraform/fwprovider/framework_provider.go.tmpl b/mmv1/third_party/terraform/fwprovider/framework_provider.go.tmpl index ebf55a9af2ba..1201a9b99f75 100644 --- a/mmv1/third_party/terraform/fwprovider/framework_provider.go.tmpl +++ b/mmv1/third_party/terraform/fwprovider/framework_provider.go.tmpl @@ -380,7 +380,7 @@ func (p *FrameworkProvider) Functions(_ context.Context) []func() function.Funct // EphemeralResources defines the resources that are of ephemeral type implemented in the provider. func (p *FrameworkProvider) EphemeralResources(_ context.Context) []func() ephemeral.EphemeralResource { return []func() ephemeral.EphemeralResource{ - resourcemanager.GoogleEphemeralClientConfig, + resourcemanager.GoogleEphemeralClientConfig, resourcemanager.GoogleEphemeralServiceAccountAccessToken, resourcemanager.GoogleEphemeralServiceAccountIdToken, resourcemanager.GoogleEphemeralServiceAccountJwt, diff --git a/mmv1/third_party/terraform/services/bigtable/resource_bigtable_table_meta.yaml b/mmv1/third_party/terraform/services/bigtable/resource_bigtable_table_meta.yaml index 7741b5a39df8..05af3c33596d 100644 --- a/mmv1/third_party/terraform/services/bigtable/resource_bigtable_table_meta.yaml +++ b/mmv1/third_party/terraform/services/bigtable/resource_bigtable_table_meta.yaml @@ -3,7 +3,6 @@ generation_type: 'handwritten' api_service_name: 'bigtableadmin.googleapis.com' api_version: 'v2' api_resource_type_kind: 'Table' -cai_asset_name_format: '//bigtable.googleapis.com/projects/{{project}}/instances/{{instance_name}}/tables/{{name}}' fields: - api_field: 'automatedBackupPolicy.frequency' - api_field: 'automatedBackupPolicy.retentionPeriod' diff --git a/mmv1/third_party/terraform/services/resourcemanager/resource_google_service_account_meta.yaml b/mmv1/third_party/terraform/services/resourcemanager/resource_google_service_account_meta.yaml index 917a5d9830f3..82454e64748f 100644 --- a/mmv1/third_party/terraform/services/resourcemanager/resource_google_service_account_meta.yaml +++ b/mmv1/third_party/terraform/services/resourcemanager/resource_google_service_account_meta.yaml @@ -3,7 +3,6 @@ generation_type: 'handwritten' api_service_name: 'iam.googleapis.com' api_version: 'v1' api_resource_type_kind: 'ServiceAccount' -cai_asset_name_format: '//iam.googleapis.com/projects/{{project}}/serviceAccounts/{{unique_id}}' fields: - field: 'account_id' - field: 'create_ignore_already_exists' diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_meta.yaml b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_meta.yaml index 7286fc63df0f..e06e8e7f9536 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_meta.yaml +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_meta.yaml @@ -3,7 +3,6 @@ generation_type: 'handwritten' api_service_name: 'sqladmin.googleapis.com' api_version: 'v1beta4' api_resource_type_kind: 'DatabaseInstance' -cai_asset_name_format: '//cloudsql.googleapis.com/projects/{{project}}/instances/{{name}}' fields: - api_field: 'availableMaintenanceVersions' - field: 'backupdr_backup' diff --git a/mmv1/third_party/tgc/resource_converters.go.tmpl b/mmv1/third_party/tgc/resource_converters.go.tmpl index dcf712adb631..7cbfaada4282 100644 --- a/mmv1/third_party/tgc/resource_converters.go.tmpl +++ b/mmv1/third_party/tgc/resource_converters.go.tmpl @@ -28,72 +28,19 @@ package google import ( - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/cai" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/accesscontextmanager" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/alloydb" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/apigee" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/apikeys" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/appengine" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/artifactregistry" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/beyondcorp" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/bigquery" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/bigqueryanalyticshub" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/bigqueryconnection" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/bigquerydatapolicy" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/bigquerydatapolicyv2" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/bigtable" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/binaryauthorization" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/clouddeploy" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/cloudfunctions" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/cloudfunctions2" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/cloudrun" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/cloudrunv2" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/cloudtasks" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/colab" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/composer" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/compute" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/container" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/containeranalysis" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/datacatalog" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/dataflow" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/datafusion" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/dataplex" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/dataproc" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/dataprocmetastore" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/datastream" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/dns" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/filestore" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/firebase" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/gemini" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/gkebackup" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/gkehub" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/gkehub2" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/healthcare" + "sort" + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/appengine" + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/container" + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/compute" "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/iambeta" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/iamworkforcepool" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/iap" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/kms" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/logging" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/monitoring" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/notebooks" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/orgpolicy" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/privateca" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/pubsub" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/pubsublite" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/redis" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/resourcemanager" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/secretmanager" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/secretmanagerregional" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/securesourcemanager" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/securitycenter" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/securitycenterv2" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/servicemanagement" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/spanner" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/sql" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/storage" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/vertexai" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/vpcaccess" - "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/workbench" + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/kms" + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/resourcemanager" + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/spanner" + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/secretmanagerregional" + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/securesourcemanager" + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/securitycenterv2" + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/services/storage" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" ) @@ -140,6 +87,7 @@ func ResourceConverters() map[string][]cai.ResourceConverter { "google_compute_target_https_proxy": {compute.ResourceConverterComputeTargetHttpsProxy()}, "google_compute_target_ssl_proxy": {compute.ResourceConverterComputeTargetSslProxy()}, "google_compute_target_pool": {compute.ResourceConverterComputeTargetPool()}, + "google_iam_workload_identity_pool_provider": {iambeta.ResourceConverterIAMBetaWorkloadIdentityPoolProvider()}, "google_composer_environment": {composer.ResourceConverterComposerEnvironment()}, "google_compute_region_commitment": {compute.ResourceConverterCommitment()}, "google_dataflow_job": {dataflow.ResourceDataflowJob()}, diff --git a/mmv1/third_party/tgc/tests/data/example_cloud_run_mapping.json b/mmv1/third_party/tgc/tests/data/example_cloud_run_mapping.json index 4872280b5268..279d350f61d1 100644 --- a/mmv1/third_party/tgc/tests/data/example_cloud_run_mapping.json +++ b/mmv1/third_party/tgc/tests/data/example_cloud_run_mapping.json @@ -1,6 +1,6 @@ [ { - "name": "//run.googleapis.com/projects/{{.Provider.project}}/locations/us-central1/domainmappings/tf-test-domain-meep.gcp.tfacc.hashicorptest.com", + "name": "//run.googleapis.com/projects/{{.Provider.project}}/locations/us-central1/DomainMappings/tf-test-domain-meep.gcp.tfacc.hashicorptest.com", "asset_type": "run.googleapis.com/DomainMapping", "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}", "resource": { diff --git a/mmv1/third_party/tgc/tests/data/example_gke_hub_feature.json b/mmv1/third_party/tgc/tests/data/example_gke_hub_feature.json index 32a8c6e08cd4..ac42f14ca322 100644 --- a/mmv1/third_party/tgc/tests/data/example_gke_hub_feature.json +++ b/mmv1/third_party/tgc/tests/data/example_gke_hub_feature.json @@ -1,6 +1,6 @@ [ { - "name": "//gkehub.googleapis.com/projects/{{.Provider.project}}/locations/global/features/multiclusterservicediscovery", + "name": "//gkehub.googleapis.com/projects/{{.Provider.project}}/locations/global/features/multiclusterservicediscovery?return_partial_success=true", "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}", "asset_type": "gkehub.googleapis.com/Feature", "resource": { diff --git a/mmv1/third_party/tgc/tests/data/example_google_dataproc_autoscaling_policy.json b/mmv1/third_party/tgc/tests/data/example_google_dataproc_autoscaling_policy.json index 4ec88d79ca30..e634f62eb2d6 100644 --- a/mmv1/third_party/tgc/tests/data/example_google_dataproc_autoscaling_policy.json +++ b/mmv1/third_party/tgc/tests/data/example_google_dataproc_autoscaling_policy.json @@ -34,7 +34,7 @@ "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}" }, { - "name": "//dataproc.googleapis.com/projects/{{.Provider.project}}/regions/us-central1/autoscalingPolicies/dataproc-policy1", + "name": "//dataproc.googleapis.com/projects/{{.Provider.project}}/locations/us-central1/autoscalingPolicies/dataproc-policy1", "asset_type": "dataproc.googleapis.com/AutoscalingPolicy", "resource": { "version": "v1beta2", diff --git a/mmv1/third_party/tgc/tests/data/google_iam_workload_identity_pool_provider.json b/mmv1/third_party/tgc/tests/data/google_iam_workload_identity_pool_provider.json new file mode 100644 index 000000000000..f43a5b2d0cbf --- /dev/null +++ b/mmv1/third_party/tgc/tests/data/google_iam_workload_identity_pool_provider.json @@ -0,0 +1,47 @@ +[ + { + "name": "//iam.googleapis.com/projects/{{.Provider.project}}/locations/global/workloadIdentityPools/gg-asset-44602-7df7/providers/gg-asset-44602-7df7", + "asset_type": "iam.googleapis.com/WorkloadIdentityPoolProvider", + "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}", + "resource": { + "version": "v1", + "discovery_document_uri": "https://iam.googleapis.com/$discovery/rest", + "discovery_name": "WorkloadIdentityPoolProvider", + "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}", + "data": { + "aws": { + "accountId": "111111111111" + }, + "description": "AWS provider for gg-asset-44602-7df7", + "displayName": "gg-asset-44602-7df7" + } + } + } +] +, + { + "name": "//iam.googleapis.com/projects/{{.Provider.project}}/locations/global/workloadIdentityPools/gg-asset-45050-bcd4/providers/gg-asset-45050-bcd4", + "asset_type": "iam.googleapis.com/WorkloadIdentityPoolProvider", + "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}", + "resource": { + "version": "v1", + "discovery_document_uri": "https://iam.googleapis.com/$discovery/rest", + "discovery_name": "WorkloadIdentityPoolProvider", + "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}", + "data": { + "attributeCondition": "assertion.repository_owner == 'google'", + "attributeMapping": { + "attribute.actor": "assertion.actor", + "attribute.repository": "assertion.repository", + "google.subject": "assertion.sub" + }, + "description": "OIDC provider for gg-asset-45050-bcd4", + "disabled": true, + "displayName": "gg-asset-45050-bcd4", + "oidc": { + "issuerUri": "https://oidc.gg-asset-45050-bcd4.com" + } + } + } + } +] \ No newline at end of file diff --git a/mmv1/third_party/tgc/tests/data/google_iam_workload_identity_pool_provider.tf b/mmv1/third_party/tgc/tests/data/google_iam_workload_identity_pool_provider.tf new file mode 100644 index 000000000000..d7e69e472654 --- /dev/null +++ b/mmv1/third_party/tgc/tests/data/google_iam_workload_identity_pool_provider.tf @@ -0,0 +1,57 @@ +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = ">= 4.54.0" + } + } +} + +provider "google" { + project = "{{.Provider.project}}" +} + +resource "google_iam_workload_identity_pool" "gg_asset_44602_7df7" { + project = "{{.Provider.project}}" + workload_identity_pool_id = "gg-asset-44602-7df7" + display_name = "gg-asset-44602-7df7" + description = "Workload Identity Pool for gg-asset-44602-7df7" +} + +resource "google_iam_workload_identity_pool_provider" "gg_asset_44602_7df7" { + project = "{{.Provider.project}}" + workload_identity_pool_id = google_iam_workload_identity_pool.gg_asset_44602_7df7.workload_identity_pool_id + workload_identity_pool_provider_id = "gg-asset-44602-7df7" + display_name = "gg-asset-44602-7df7" + description = "AWS provider for gg-asset-44602-7df7" + aws { + account_id = "111111111111" + } +} + +resource "google_iam_workload_identity_pool" "gg_asset_45050_bcd4" { + project = "{{.Provider.project}}" + workload_identity_pool_id = "gg-asset-45050-bcd4" + display_name = "gg-asset-45050-bcd4" + description = "Workload Identity Pool for gg-asset-45050-bcd4" + disabled = false +} + +resource "google_iam_workload_identity_pool_provider" "gg_asset_45050_bcd4" { + project = "{{.Provider.project}}" + workload_identity_pool_id = google_iam_workload_identity_pool.gg_asset_45050_bcd4.workload_identity_pool_id + workload_identity_pool_provider_id = "gg-asset-45050-bcd4" + display_name = "gg-asset-45050-bcd4" + description = "OIDC provider for gg-asset-45050-bcd4" + disabled = true + attribute_mapping = { + "google.subject" = "assertion.sub" + "attribute.actor" = "assertion.actor" + "attribute.repository" = "assertion.repository" + } + attribute_condition = "assertion.repository_owner == 'google'" + + oidc { + issuer_uri = "https://oidc.gg-asset-45050-bcd4.com" + } +} diff --git a/mmv1/third_party/tgc/tests/source/cli_test.go.tmpl b/mmv1/third_party/tgc/tests/source/cli_test.go.tmpl index 4812a3922989..1b85a8e152be 100644 --- a/mmv1/third_party/tgc/tests/source/cli_test.go.tmpl +++ b/mmv1/third_party/tgc/tests/source/cli_test.go.tmpl @@ -1,10 +1,15 @@ package test import ( + "bytes" + "encoding/json" "fmt" "log" "os" + "os/exec" "path/filepath" + "regexp" + "strings" "testing" "github.com/google/go-cmp/cmp" diff --git a/mmv1/third_party/tgc/tests/source/iam_test.go.tmpl b/mmv1/third_party/tgc/tests/source/iam_test.go.tmpl index 862a5c5dbf84..93c904368e82 100644 --- a/mmv1/third_party/tgc/tests/source/iam_test.go.tmpl +++ b/mmv1/third_party/tgc/tests/source/iam_test.go.tmpl @@ -1,13 +1,11 @@ package test import ( - "encoding/json" "fmt" "net/http" "net/http/httptest" "os" "path/filepath" - "strings" "testing" crmv1 "google.golang.org/api/cloudresourcemanager/v1" diff --git a/mmv1/third_party/tgc/tests/source/read_test.go.tmpl b/mmv1/third_party/tgc/tests/source/read_test.go.tmpl index b658322a28d4..9fbf31f63139 100644 --- a/mmv1/third_party/tgc/tests/source/read_test.go.tmpl +++ b/mmv1/third_party/tgc/tests/source/read_test.go.tmpl @@ -2,6 +2,7 @@ package test import ( "context" + "encoding/json" "log" "os" "path/filepath" diff --git a/mmv1/third_party/tgc_next/pkg/cai2hcl/converters/utils/utils.go b/mmv1/third_party/tgc_next/pkg/cai2hcl/converters/utils/utils.go index 80bd7d8fba52..43ee26a9d3a9 100644 --- a/mmv1/third_party/tgc_next/pkg/cai2hcl/converters/utils/utils.go +++ b/mmv1/third_party/tgc_next/pkg/cai2hcl/converters/utils/utils.go @@ -25,7 +25,7 @@ func ParseFieldValue(url string, name string) string { } /* - ParseUrlParamValuesFromAssetName uses GetCaiAssetNameTemplate to parse hclData from assetName, filtering out all outputFields + ParseUrlParamValuesFromAssetName uses CaiAssetNameTemplate to parse hclData from assetName, filtering out all outputFields template: //bigquery.googleapis.com/projects/{{project}}/datasets/{{dataset_id}} assetName: //bigquery.googleapis.com/projects/my-project/datasets/my-dataset