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
scott-mitchell authored May 20, 2024
2 parents f52b17a + 6461ee1 commit 670868c
Show file tree
Hide file tree
Showing 69 changed files with 4,430 additions and 372 deletions.
1 change: 1 addition & 0 deletions .github/workflows/scheduled-pr-reminders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

jobs:
send-pr-reminders:
if: github.repository == 'GoogleCloudPlatform/magic-modules'
runs-on: ubuntu-latest
permissions:
pull-requests: write
Expand Down
29 changes: 0 additions & 29 deletions .github/workflows/unit-test-go-changelog.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: membership-checker
name: unit-test-magician

permissions: read-all

Expand All @@ -16,7 +16,7 @@ jobs:
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '^1.21'
- name: Run membership checker unit tests
- name: Run magician unit tests
run: |
cd .ci/magician
go test ./... -v
106 changes: 106 additions & 0 deletions .github/workflows/unit-test-tools.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: unit-test-tools

permissions: read-all

on:
pull_request:
paths:
- 'tools/**'
- '.github/workflows/unit-test-tools.yml'

jobs:
diff-processor:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '^1.21.0'

- name: Build diff-processor with TPG
run: |
cd tools/diff-processor
make clone OWNER_REPO=hashicorp/terraform-provider-google DEPTH=1
make build OLD_REF=main NEW_REF=main
- name: Test diff-processor with TPG
run: |
cd tools/diff-processor
go test -v ./...
env:
SERVICES_DIR: tools/diff-processor/new/google/services

- name: Build diff-processor with TPGB
run: |
cd tools/diff-processor
make clone OWNER_REPO=hashicorp/terraform-provider-google-beta DEPTH=1
make build OLD_REF=main NEW_REF=main
- name: Test diff-processor with TPGB
run: |
cd tools/diff-processor
go test -v ./...
env:
SERVICES_DIR: tools/diff-processor/new/google/services

go-changelog:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '^1.21.0'

- name: Build go-changelog
run: |
cd tools/go-changelog/cmd/changelog-pr-body-check
go build
- name: Test go-changelog
run: |
cd tools/go-changelog
go test -v ./...
issue-labeler:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '^1.21.0'

- name: Build issue-labeler
run: |
cd tools/issue-labeler
go build
- name: Test issue-labeler
run: |
cd tools/issue-labeler
go test -v ./...
template-check:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '^1.21.0'

- name: Build template-check
run: |
cd tools/template-check
go build
- name: Test template-check
run: |
cd tools/template-check
go test -v ./...
46 changes: 0 additions & 46 deletions .github/workflows/unit-tests-diff-processor.yml

This file was deleted.

67 changes: 64 additions & 3 deletions mmv1/api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,8 +1072,8 @@ func (r Resource) ExtractIdentifiers(url string) []string {
return result
}

func (r Resource) ImportIdFormatsFromIam() string {
var importFormat, transformed []string
func (r Resource) RawImportIdFormatsFromIam() []string {
var importFormat []string

if r.IamPolicy != nil {
importFormat = r.IamPolicy.ImportFormat
Expand All @@ -1082,7 +1082,13 @@ func (r Resource) ImportIdFormatsFromIam() string {
importFormat = r.ImportFormat
}

importIdFormats := ImportIdFormats(importFormat, r.Identity, r.BaseUrl)
return ImportIdFormats(importFormat, r.Identity, r.BaseUrl)
}

func (r Resource) ImportIdRegexesFromIam() string {
var transformed []string

importIdFormats := r.RawImportIdFormatsFromIam()
for _, s := range importIdFormats {
s = google.Format2Regex(s)
s = strings.ReplaceAll(s, "<name>", fmt.Sprintf("<%s>", r.IamParentResourceName()))
Expand All @@ -1092,6 +1098,47 @@ func (r Resource) ImportIdFormatsFromIam() string {
return strings.Join(transformed[:], "\", \"")
}

func (r Resource) ImportIdFormatsFromIam() []string {
importIdFormats := r.RawImportIdFormatsFromIam()
var transformed []string
for _, s := range importIdFormats {
transformed = append(transformed, strings.ReplaceAll(s, "%", ""))
}
return transformed
}

func (r Resource) FirstIamImportIdFormat() string {
importIdFormats := r.ImportIdFormatsFromIam()
if len(importIdFormats) == 0 {
return ""
}
first := importIdFormats[0]
first = strings.ReplaceAll(first, "{{name}}", fmt.Sprintf("{{%s}}", google.Underscore(r.Name)))
return first
}

func (r Resource) IamTerraformName() string {
return fmt.Sprintf("%s_iam", r.TerraformName())
}

func (r Resource) IamSelfLinkProperties() []*Type {
var selfLink string
if r.IamPolicy != nil {
selfLink = r.IamPolicy.SelfLink
}
if selfLink == "" {
selfLink = r.SelfLinkUrl()
}

params := r.ExtractIdentifiers(selfLink)

urlProperties := google.Select(r.AllUserProperties(), func(p *Type) bool {
return slices.Contains(params, p.Name)
})

return urlProperties
}

func OrderProperties(props []*Type) []*Type {
req := google.Select(props, func(p *Type) bool {
return p.Required
Expand All @@ -1113,6 +1160,20 @@ func CompareByName(a, b *Type) int {
return strings.Compare(a.Name, b.Name)
}

func (r Resource) GetPropertyUpdateMasksGroups() map[string][]string {
maskGroups := map[string][]string{}
for _, prop := range r.AllUserProperties() {
if (prop.FlattenObject) {
prop.GetNestedPropertyUpdateMasksGroups(maskGroups, prop.ApiName)
}else if (len(prop.UpdateMaskFields) > 0){
maskGroups[google.Underscore(prop.Name)] = prop.UpdateMaskFields
}else{
maskGroups[google.Underscore(prop.Name)] = []string{prop.ApiName}
}
}
return maskGroups
}

func (r Resource) CustomTemplate(templatePath string) string {
return resource.ExecuteTemplate(&r, templatePath)
}
25 changes: 24 additions & 1 deletion mmv1/api/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/GoogleCloudPlatform/magic-modules/mmv1/api/product"
"github.com/GoogleCloudPlatform/magic-modules/mmv1/api/resource"
"github.com/GoogleCloudPlatform/magic-modules/mmv1/google"
"golang.org/x/exp/slices"
)

// Represents a property type
Expand Down Expand Up @@ -411,13 +412,17 @@ func (t Type) TerraformLineage() string {
return fmt.Sprintf("%s.0.%s", t.ParentMetadata.TerraformLineage(), google.Underscore(t.Name))
}

func (t Type) EnumValuesToString(quoteSeperator string) string {
func (t Type) EnumValuesToString(quoteSeperator string, addEmpty bool) string {
var values []string

for _, val := range t.EnumValues {
values = append(values, fmt.Sprintf("%s%s%s", quoteSeperator, val, quoteSeperator))
}

if addEmpty && !slices.Contains(values, "\"\"") && !t.Required {
values = append(values, "\"\"")
}

return strings.Join(values, ", ")
}

Expand Down Expand Up @@ -687,6 +692,10 @@ func (t Type) Deprecated() bool {
return t.DeprecationMessage != ""
}

func (t *Type) GetDescription() string {
return strings.TrimRight(t.Description, "\n")
}

// // private

// // A constant value to be provided as field
Expand Down Expand Up @@ -1283,6 +1292,20 @@ func (t Type) NamespaceProperty() string {
//
// end

// new utility function for recursive calls to GetPropertyUpdateMasksGroups

func (t Type) GetNestedPropertyUpdateMasksGroups(maskGroups map[string][]string, maskPrefix string) {
for _, prop := range t.AllProperties() {
if (prop.FlattenObject) {
prop.GetNestedPropertyUpdateMasksGroups(maskGroups, prop.ApiName)
}else if (len(prop.UpdateMaskFields) > 0){
maskGroups[google.Underscore(prop.Name)] = prop.UpdateMaskFields
}else{
maskGroups[google.Underscore(prop.Name)] = []string{maskPrefix + prop.ApiName}
}
}
}

func (t Type) CustomTemplate(templatePath string) string {
return resource.ExecuteTemplate(&t, templatePath)
}
Expand Down
Loading

0 comments on commit 670868c

Please sign in to comment.