Skip to content

Commit a8fd825

Browse files
authored
Merge pull request #11088 from c2thorn/sync-main-FEATURE-BRANCH-6.0.0
Sync main feature branch 6.0.0 - 7/1
2 parents 22e1ca9 + 6f92b89 commit a8fd825

File tree

325 files changed

+13131
-1968
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

325 files changed

+13131
-1968
lines changed

.ci/gcb-push-downstream.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ steps:
3535
id: tpg-sync
3636
waitFor: ["build-magician-binary"]
3737
args:
38-
- wait-for-commit
38+
- 'wait-for-commit'
3939
- 'tpg-sync'
4040
- $BRANCH_NAME
4141
- $COMMIT_SHA
@@ -46,7 +46,7 @@ steps:
4646
id: tpgb-sync
4747
waitFor: ["build-magician-binary"]
4848
args:
49-
- wait-for-commit
49+
- 'wait-for-commit'
5050
- 'tpgb-sync'
5151
- $BRANCH_NAME
5252
- $COMMIT_SHA
@@ -57,7 +57,7 @@ steps:
5757
id: tgc-sync
5858
waitFor: ["build-magician-binary"]
5959
args:
60-
- wait-for-commit
60+
- 'wait-for-commit'
6161
- 'tgc-sync'
6262
- $BRANCH_NAME
6363
- $COMMIT_SHA
@@ -68,7 +68,7 @@ steps:
6868
id: tf-oics-sync
6969
waitFor: ["build-magician-binary"]
7070
args:
71-
- wait-for-commit
71+
- 'wait-for-commit'
7272
- 'tf-oics-sync'
7373
- $BRANCH_NAME
7474
- $COMMIT_SHA

.ci/magician/cmd/generate_downstream.go

+18
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ func execGenerateDownstream(baseBranch, command, repo, version, ref string, gh G
9898
baseBranch = "main"
9999
}
100100

101+
var syncBranchPrefix string
102+
if repo == "terraform" {
103+
if version == "beta" {
104+
syncBranchPrefix = "tpgb-sync"
105+
} else if version == "ga" {
106+
syncBranchPrefix = "tpg-sync"
107+
}
108+
} else if repo == "terraform-google-conversion" {
109+
syncBranchPrefix = "tgc-sync"
110+
} else if repo == "tf-oics" {
111+
syncBranchPrefix = "tf-oics-sync"
112+
}
113+
syncBranch := getSyncBranch(syncBranchPrefix, baseBranch)
114+
if syncBranchHasCommit(ref, syncBranch, rnr) {
115+
fmt.Printf("Sync branch %s already has commit %s, skipping generation\n", syncBranch, ref)
116+
os.Exit(0)
117+
}
118+
101119
mmLocalPath := filepath.Join(rnr.GetCWD(), "..", "..")
102120
mmCopyPath := filepath.Join(mmLocalPath, "..", fmt.Sprintf("mm-%s-%s-%s", repo, version, command))
103121
if _, err := rnr.Run("cp", []string{"-rp", mmLocalPath, mmCopyPath}, nil); err != nil {

.ci/magician/cmd/sync_branch.go

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func execSyncBranchCmd(syncBranchPrefix, baseBranch, sha, githubToken string, ru
5858
syncBranch := getSyncBranch(syncBranchPrefix, baseBranch)
5959
fmt.Println("SYNC_BRANCH: ", syncBranch)
6060

61+
if syncBranchHasCommit(sha, syncBranch, runner) {
62+
fmt.Printf("Commit %s already in sync branch %s, skipping sync\n", sha, syncBranch)
63+
return nil
64+
}
65+
6166
_, err := runner.Run("git", []string{"push", fmt.Sprintf("https://modular-magician:%[email protected]/GoogleCloudPlatform/magic-modules", githubToken), fmt.Sprintf("%s:%s", sha, syncBranch)}, nil)
6267
return err
6368
}

.ci/magician/cmd/wait_for_commit.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ func execWaitForCommit(syncBranchPrefix, baseBranch, sha string, runner source.R
4848
fmt.Println("SYNC_BRANCH: ", syncBranch)
4949

5050
if syncBranchHasCommit(sha, syncBranch, runner) {
51-
return fmt.Errorf("found %s in history of %s - dying to avoid double-generating that commit", sha, syncBranch)
51+
fmt.Printf("found %s in history of %s - skipping wait\n", sha, syncBranch)
52+
return nil
5253
}
5354

5455
for {
@@ -68,7 +69,7 @@ func execWaitForCommit(syncBranchPrefix, baseBranch, sha string, runner source.R
6869
}
6970
fmt.Println("sync branch is at: ", syncHead)
7071
fmt.Println("current commit is: ", sha)
71-
72+
7273
if _, err := runner.Run("git", []string{"fetch", "origin", syncBranch}, nil); err != nil {
7374
return err
7475
}

.ci/magician/github/membership.go

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ var (
8282
startDate: newDate(2024, 5, 22, pdtLoc),
8383
endDate: newDate(2024, 5, 28, pdtLoc),
8484
},
85+
{
86+
id: "melinath",
87+
startDate: newDate(2024, 6, 26, pdtLoc),
88+
endDate: newDate(2024, 7, 22, pdtLoc),
89+
},
8590
}
8691
)
8792

.ci/magician/vcr/tester.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ func (vt *Tester) FetchCassettes(version provider.Version, baseBranch, prNumber
9797
}
9898
cassettePath = filepath.Join(vt.baseDir, "cassettes", version.String())
9999
vt.rnr.Mkdir(cassettePath)
100-
if baseBranch != "FEATURE-BRANCH-major-release-5.0.0" {
100+
if baseBranch != "FEATURE-BRANCH-major-release-6.0.0" {
101+
// pull main cassettes (major release uses branch specific casssettes as primary ones)
101102
bucketPath := fmt.Sprintf("gs://ci-vcr-cassettes/%sfixtures/*", version.BucketPath())
102103
if err := vt.fetchBucketPath(bucketPath, cassettePath); err != nil {
103104
fmt.Println("Error fetching cassettes: ", err)

docs/content/develop/breaking-changes/make-a-breaking-change.md

+7-17
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ The general process for contributing a breaking change to the
6262

6363
1. Make the `main` branch forwards-compatible with the major release
6464
2. Add deprecations and warnings to the `main` branch of `magic-modules`
65-
3. Add upgrade guide entries to the `main` branch of `magic-modules`
65+
3. Add upgrade guide entries to the `FEATURE-BRANCH-major-release-6.0.0` branch of `magic-modules`
6666
4. Make the breaking change on `FEATURE-BRANCH-major-release-{{% param "majorVersion" %}}`
6767

6868
These are covered in more detail in the following sections. The upgrade guide
@@ -169,20 +169,7 @@ The deprecation message will automatically show up in the resource documentation
169169
Other breaking changes should be called out in the docs for the impacted field
170170
or resource. It is also great to log warnings at runtime if possible.
171171
172-
### Add upgrade guide entries to the `main` branch of `magic-modules`
173-
174-
Upgrade guide entries should be added to
175-
[{{< param upgradeGuide >}}](https://github.com/GoogleCloudPlatform/magic-modules/blob/main/mmv1/third_party/terraform/website/docs/guides/{{< param upgradeGuide >}}).
176-
Entries should focus on the changes that users need to make when upgrading
177-
to `{{% param "majorVersion" %}}`, rather than how to write configurations
178-
after upgrading.
179-
180-
See [Terraform provider for Google Cloud 5.0.0 Upgrade Guide](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/version_5_upgrade)
181-
and other upgrade guides for examples.
182-
183-
The upgrade guide and the actual breaking change will be merged only after both are completed.
184-
185-
### Make the breaking change on `FEATURE-BRANCH-major-release-{{% param "majorVersion" %}}`
172+
### Make the change on `FEATURE-BRANCH-major-release-{{% param "majorVersion" %}}`
186173

187174
When working on your breaking change, make sure that your base branch
188175
is `FEATURE-BRANCH-major-release-{{% param "majorVersion" %}}`. This
@@ -207,14 +194,17 @@ with the following changes:
207194
are present on the major release branch. Changes to the `main` branch will be
208195
merged into the major release branch every Monday.
209196
1. Make the breaking change.
197+
1. Add the upgrade guide entries to
198+
[{{< param upgradeGuide >}}](https://github.com/GoogleCloudPlatform/magic-modules/blob/FEATURE-BRANCH-major-release-6.0.0/mmv1/third_party/terraform/website/docs/guides/{{< param upgradeGuide >}}). Entries should focus on the changes that users need to make when upgrading
199+
to `{{% param "majorVersion" %}}`, rather than how to write configurations
200+
after upgrading. See [Terraform provider for Google Cloud 5.0.0 Upgrade Guide](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/version_5_upgrade)
201+
and other upgrade guides for examples.
210202
1. Remove any deprecation notices and warnings (including in documentation) not already removed by the breaking change.
211203
1. When you create your pull request,
212204
[change the base branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-base-branch-of-a-pull-request)
213205
to `FEATURE-BRANCH-major-release-{{% param "majorVersion" %}}`
214206
1. To resolve merge conflicts with `git rebase` or `git merge`, use `FEATURE-BRANCH-major-release-{{% param "majorVersion" %}}` instead of `main`.
215207

216-
The upgrade guide and the actual breaking change will be merged only after both are completed.
217-
218208
## What's next?
219209

220210
- [Run tests]({{< ref "/develop/test/run-tests.md" >}})

mmv1/api/resource.go

+54-26
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"fmt"
1717
"maps"
1818
"regexp"
19-
"strings"
2019
"sort"
20+
"strings"
2121

2222
"github.com/GoogleCloudPlatform/magic-modules/mmv1/api/product"
2323
"github.com/GoogleCloudPlatform/magic-modules/mmv1/api/resource"
@@ -593,9 +593,6 @@ func buildEffectiveLabelsField(name string, labels *Type) *Type {
593593
"including the %s configured through Terraform, other clients and services.", name, name)
594594

595595
t := "KeyValueEffectiveLabels"
596-
if name == "annotations" {
597-
t = "KeyValueEffectiveAnnotations"
598-
}
599596

600597
n := fmt.Sprintf("effective%s", strings.Title(name))
601598

@@ -671,6 +668,10 @@ func getLabelsFieldNote(title string) string {
671668
title, title, title)
672669
}
673670

671+
func (r Resource) StateMigrationFile() string {
672+
return fmt.Sprintf("templates/terraform/state_migrations/go/%s_%s.go.tmpl", google.Underscore(r.ProductMetadata.Name), google.Underscore(r.Name))
673+
}
674+
674675
// ====================
675676
// Version-related methods
676677
// ====================
@@ -948,10 +949,7 @@ func ImportIdFormats(importFormat, identity []string, baseUrl string) []string {
948949
var idFormats []string
949950
if len(importFormat) == 0 {
950951
underscoredBaseUrl := baseUrl
951-
// TODO Q2: underscore base url needed?
952-
// underscored_base_url = base_url.gsub(
953-
// /{{[[:word:]]+}}/, &:underscore
954-
// )
952+
955953
if len(identity) == 0 {
956954
idFormats = []string{fmt.Sprintf("%s/{{name}}", underscoredBaseUrl)}
957955
} else {
@@ -960,7 +958,7 @@ func ImportIdFormats(importFormat, identity []string, baseUrl string) []string {
960958
transformedIdentity = append(transformedIdentity, fmt.Sprintf("{{%s}}", id))
961959
}
962960
identityPath := strings.Join(transformedIdentity, "/")
963-
idFormats = []string{fmt.Sprintf("%s/%s", underscoredBaseUrl, identityPath)}
961+
idFormats = []string{fmt.Sprintf("%s/%s", underscoredBaseUrl, google.Underscore(identityPath))}
964962
}
965963
} else {
966964
idFormats = importFormat
@@ -985,15 +983,9 @@ func ImportIdFormats(importFormat, identity []string, baseUrl string) []string {
985983
// `{{project}}/{{%name}}` as there is no way to differentiate between
986984
// project-name/resource-name and resource-name/with-slash
987985
if !strings.Contains(idFormats[0], "%") {
988-
idFormats = append(idFormats, shortIdFormat, shortIdDefaultProjectFormat)
989-
if shortIdDefaultProjectFormat != shortIdDefaultFormat {
990-
idFormats = append(idFormats, shortIdDefaultFormat)
991-
}
986+
idFormats = append(idFormats, shortIdFormat, shortIdDefaultProjectFormat, shortIdDefaultFormat)
992987
}
993988

994-
idFormats = google.Reject(slices.Compact(idFormats), func(i string) bool {
995-
return i == ""
996-
})
997989
slices.SortFunc(idFormats, func(a, b string) int {
998990
i := strings.Count(a, "/")
999991
j := strings.Count(b, "/")
@@ -1003,7 +995,25 @@ func ImportIdFormats(importFormat, identity []string, baseUrl string) []string {
1003995
return i - j
1004996
})
1005997
slices.Reverse(idFormats)
1006-
return idFormats
998+
999+
// Remove duplicates from idFormats
1000+
uniq := make([]string, len(idFormats))
1001+
uniq[0] = idFormats[0]
1002+
i := 1
1003+
j := 1
1004+
for j < len(idFormats) {
1005+
format := idFormats[j]
1006+
if format != uniq[i-1] {
1007+
uniq[i] = format
1008+
i++
1009+
}
1010+
j++
1011+
}
1012+
1013+
uniq = google.Reject(slices.Compact(uniq), func(i string) bool {
1014+
return i == ""
1015+
})
1016+
return uniq
10071017
}
10081018

10091019
func (r Resource) IgnoreReadPropertiesToString(e resource.Examples) string {
@@ -1014,7 +1024,7 @@ func (r Resource) IgnoreReadPropertiesToString(e resource.Examples) string {
10141024
}
10151025
}
10161026
for _, tp := range e.IgnoreReadExtra {
1017-
props = append(props, fmt.Sprintf("\"%s\"", google.Underscore(tp)))
1027+
props = append(props, fmt.Sprintf("\"%s\"", tp))
10181028
}
10191029
for _, tp := range r.IgnoreReadLabelsFields(r.PropertiesWithExcluded()) {
10201030
props = append(props, fmt.Sprintf("\"%s\"", google.Underscore(tp)))
@@ -1379,6 +1389,9 @@ func (r Resource) GetPropertyUpdateMasksGroups(properties []*Type, maskPrefix st
13791389

13801390
// Formats whitespace in the style of the old Ruby generator's descriptions in documentation
13811391
func (r Resource) FormatDocDescription(desc string, indent bool) string {
1392+
if desc == "" {
1393+
return ""
1394+
}
13821395
returnString := desc
13831396
if indent {
13841397
returnString = strings.ReplaceAll(returnString, "\n\n", "\n")
@@ -1387,7 +1400,7 @@ func (r Resource) FormatDocDescription(desc string, indent bool) string {
13871400
// fix removing for ruby -> go transition diffs
13881401
returnString = strings.ReplaceAll(returnString, "\n \n **Note**: This field is non-authoritative,", "\n\n **Note**: This field is non-authoritative,")
13891402

1390-
return strings.TrimSuffix(returnString, "\n ")
1403+
return fmt.Sprintf("\n %s", strings.TrimSuffix(returnString, "\n "))
13911404
}
13921405
return strings.TrimSuffix(returnString, "\n")
13931406
}
@@ -1455,8 +1468,8 @@ func (r Resource) propertiesWithCustomUpdate(properties []*Type) []*Type {
14551468
})
14561469
}
14571470

1458-
func (r Resource) PropertiesByCustomUpdate() map[UpdateGroup][]*Type {
1459-
customUpdateProps := r.propertiesWithCustomUpdate(r.RootProperties())
1471+
func (r Resource) PropertiesByCustomUpdate(properties []*Type) map[UpdateGroup][]*Type {
1472+
customUpdateProps := r.propertiesWithCustomUpdate(properties)
14601473
groupedCustomUpdateProps := map[UpdateGroup][]*Type{}
14611474
for _, prop := range customUpdateProps {
14621475
groupedProperty := UpdateGroup{UpdateUrl: prop.UpdateUrl,
@@ -1477,21 +1490,28 @@ func (r Resource) PropertiesByCustomUpdateGroups() []UpdateGroup {
14771490
UpdateId: prop.UpdateId,
14781491
FingerprintName: prop.FingerprintName}
14791492

1480-
if slices.Contains(updateGroups, groupedProperty){
1493+
if slices.Contains(updateGroups, groupedProperty) {
14811494
continue
14821495
}
14831496
updateGroups = append(updateGroups, groupedProperty)
14841497
}
1485-
sort.Slice(updateGroups, func(i, j int) bool { return updateGroups[i].UpdateId < updateGroups[i].UpdateId })
1498+
sort.Slice(updateGroups, func(i, j int) bool {
1499+
a := updateGroups[i]
1500+
b := updateGroups[j]
1501+
if a.UpdateVerb != b.UpdateVerb {
1502+
return a.UpdateVerb > b.UpdateVerb
1503+
}
1504+
return a.UpdateId < b.UpdateId
1505+
})
14861506
return updateGroups
14871507
}
14881508

14891509
func (r Resource) FieldSpecificUpdateMethods() bool {
1490-
return (len(r.PropertiesByCustomUpdate()) > 0)
1510+
return (len(r.PropertiesByCustomUpdate(r.RootProperties())) > 0)
14911511
}
14921512

1493-
func (r Resource) CustomUpdatePropertiesByKey(updateUrl string, updateId string, fingerprintName string, updateVerb string) []*Type {
1494-
groupedProperties := r.PropertiesByCustomUpdate()
1513+
func (r Resource) CustomUpdatePropertiesByKey(properties []*Type, updateUrl string, updateId string, fingerprintName string, updateVerb string) []*Type {
1514+
groupedProperties := r.PropertiesByCustomUpdate(properties)
14951515
groupedProperty := UpdateGroup{UpdateUrl: updateUrl,
14961516
UpdateVerb: updateVerb,
14971517
UpdateId: updateId,
@@ -1526,3 +1546,11 @@ func (r Resource) VersionedProvider(exampleVersion string) bool {
15261546
}
15271547
return vp != "" && vp != "ga"
15281548
}
1549+
1550+
func (r Resource) StateUpgradersCount() []int {
1551+
var nums []int
1552+
for i := r.StateUpgradeBaseSchemaVersion; i < r.SchemaVersion; i++ {
1553+
nums = append(nums, i)
1554+
}
1555+
return nums
1556+
}

mmv1/api/resource.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,11 @@ def all_nested_properties(props)
396396
def convert_go_file(file)
397397
dir, base = File.split(file)
398398
base.slice! '.erb'
399-
"#{dir}/go/#{base}.tmpl"
399+
if dir.end_with?('terraform')
400+
"#{dir}/#{base}.go.tmpl"
401+
else
402+
"#{dir}/go/#{base}.tmpl"
403+
end
400404
end
401405

402406
# All settable properties in the resource.

mmv1/api/resource/docs.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ type Docs struct {
3333
Note string
3434

3535
// attr_reader :
36-
RequiredProperties string
36+
RequiredProperties string `yaml:"required_properties"`
3737

3838
// attr_reader :
39-
OptionalProperties string
39+
OptionalProperties string `yaml:"optional_properties"`
4040

4141
// attr_reader :
4242
Attributes string

mmv1/api/resource/examples.go

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ func (e *Examples) SetHCLText() {
204204
}
205205
e.TestEnvVars = docTestEnvVars
206206
e.DocumentationHCLText = ExecuteTemplate(e, e.ConfigPath, true)
207+
e.DocumentationHCLText = regexp.MustCompile(`\n\n$`).ReplaceAllString(e.DocumentationHCLText, "\n")
207208

208209
// Remove region tags
209210
re1 := regexp.MustCompile(`# \[[a-zA-Z_ ]+\]\n`)

0 commit comments

Comments
 (0)