Skip to content

Commit

Permalink
Merge branch 'GoogleCloudPlatform:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
gurusai-voleti authored Oct 4, 2024
2 parents bd8f3d6 + c39d3e8 commit df07e05
Show file tree
Hide file tree
Showing 67 changed files with 431 additions and 523 deletions.
9 changes: 9 additions & 0 deletions .ci/infra/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,15 @@ resource "google_project_iam_member" "healthcare_agent_storage_object_admin" {
member = "serviceAccount:service-${google_project.proj.number}@gcp-sa-healthcare.iam.gserviceaccount.com"
}

# TestAccHealthcarePipelineJob_healthcarePipelineJobMappingReconDestExample
# TestAccHealthcarePipelineJob_healthcarePipelineJobReconciliationExample
# TestAccHealthcarePipelineJob_healthcarePipelineJobWhistleMappingExample
resource "google_project_iam_member" "healthcare_agent_fhir_resource_editor" {
project = google_project.proj.project_id
role = "roles/healthcare.fhirResourceEditor"
member = "serviceAccount:service-${google_project.proj.number}@gcp-sa-healthcare.iam.gserviceaccount.com"
}

# TestAccVertexAIEndpoint_vertexAiEndpointNetwork
# TestAccVertexAIFeaturestoreEntitytype_vertexAiFeaturestoreEntitytypeExample
# TestAccVertexAIFeaturestoreEntitytype_vertexAiFeaturestoreEntitytypeWithBetaFieldsExample
Expand Down
4 changes: 4 additions & 0 deletions mmv1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var yamlTempMode = flag.Bool("yaml-temp", false, "copy text over from ruby yaml
var handwrittenTempFiles = flag.String("handwritten-temp", "", "copy specific handwritten files over from .erb to go .tmpl.temp comma separated")
var templateTempFiles = flag.String("template-temp", "", "copy specific templates over from .erb to go .tmpl.temp comma separated")

var showImportDiffs = flag.Bool("show-import-diffs", false, "write go import diffs to stdout")

func main() {

flag.Parse()
Expand Down Expand Up @@ -193,6 +195,8 @@ func main() {
if generateCode {
providerToGenerate.CompileCommonFiles(*outputPath, productsForVersion, "")
}

provider.FixImports(*outputPath, *showImportDiffs)
}

func GenerateProduct(productChannel chan string, providerToGenerate provider.Provider, productsForVersionChannel chan *api.Product, startTime time.Time, productsToGenerate []string, resourceToGenerate, overrideDirectory string, generateCode, generateDocs bool) {
Expand Down
2 changes: 2 additions & 0 deletions mmv1/products/firebase/Project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ custom_code:
constants: 'templates/terraform/constants/firebase_project.go.tmpl'
pre_create: 'templates/terraform/pre_create/firebase_project.go.tmpl'
exclude_sweeper: true
# The generated resource converter is not used. Instead, a handwritten converter is used.
exclude_tgc: true
examples:
- name: 'firebase_project_basic'
primary_resource_id: 'default'
Expand Down
53 changes: 45 additions & 8 deletions mmv1/provider/template_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ package provider

import (
"bytes"
"errors"
"fmt"
"go/format"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"

"text/template"

Expand All @@ -48,6 +50,8 @@ var BETA_VERSION = "beta"
var ALPHA_VERSION = "alpha"
var PRIVATE_VERSION = "private"

var goimportFiles sync.Map

func NewTemplateData(outputFolder string, versionName string) *TemplateData {
td := TemplateData{OutputFolder: outputFolder, VersionName: versionName}

Expand Down Expand Up @@ -208,20 +212,15 @@ func (td *TemplateData) GenerateFile(filePath, templatePath string, input any, g
} else {
sourceByte = formattedByte
}
if !strings.Contains(templatePath, "third_party/terraform") {
goimportFiles.Store(filePath, struct{}{})
}
}

err = os.WriteFile(filePath, sourceByte, 0644)
if err != nil {
glog.Exit(err)
}

if goFormat && !strings.Contains(templatePath, "third_party/terraform") {
cmd := exec.Command("goimports", "-w", filepath.Base(filePath))
cmd.Dir = filepath.Dir(filePath)
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
}
}

func (td *TemplateData) ImportPath() string {
Expand All @@ -233,6 +232,44 @@ func (td *TemplateData) ImportPath() string {
return "github.com/hashicorp/terraform-provider-google-beta/google-beta"
}

func FixImports(outputPath string, dumpDiffs bool) {
log.Printf("Fixing go import paths")

baseArgs := []string{"-w"}
if dumpDiffs {
baseArgs = []string{"-d", "-w"}
}

// -w and -d are mutually exclusive; if dumpDiffs is requested we need to run twice.
for _, base := range baseArgs {
hasFiles := false
args := []string{base}
goimportFiles.Range(func(filePath, _ any) bool {
p, err := filepath.Rel(outputPath, filePath.(string))
if err != nil {
log.Fatal(err)
}
args = append(args, p)
hasFiles = true
return true
})

if hasFiles {
cmd := exec.Command("goimports", args...)
cmd.Dir = outputPath
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) && len(exitErr.Stderr) > 0 {
glog.Error(string(exitErr.Stderr))
}
log.Fatal(err)
}
}
}
}

type TestInput struct {
Res api.Resource
ImportPath string
Expand Down
Loading

0 comments on commit df07e05

Please sign in to comment.