Skip to content

Commit 76ba0f9

Browse files
Merge pull request #11499 from c2thorn/sync-main-FEATURE-BRANCH-6.0.0 (#2692)
Sync main feature branch 6.0.0 - 8/20 [upstream:5e11f505141cbb2581f1c5cf330af01e3ad0465b] Signed-off-by: Modular Magician <[email protected]>
1 parent b315273 commit 76ba0f9

18 files changed

+1201
-56
lines changed

go.mod

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ require (
1111
github.com/hashicorp/hcl/v2 v2.20.1
1212
github.com/hashicorp/terraform-json v0.22.1
1313
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0
14-
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240820164214-0ac834396a40
14+
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240820232428-04b789c2f9b2
1515
github.com/mitchellh/go-homedir v1.1.0 // indirect
1616
github.com/pkg/errors v0.9.1
1717
github.com/stretchr/testify v1.9.0
1818
github.com/zclconf/go-cty v1.14.4
1919
go.uber.org/zap v1.21.0
20-
google.golang.org/api v0.190.0
20+
google.golang.org/api v0.191.0
2121
)
2222

2323
require github.com/spf13/cobra v1.7.0
@@ -26,14 +26,14 @@ require (
2626
bitbucket.org/creachadair/stringset v0.0.11 // indirect
2727
cel.dev/expr v0.15.0 // indirect
2828
cloud.google.com/go v0.115.0 // indirect
29-
cloud.google.com/go/auth v0.7.3 // indirect
29+
cloud.google.com/go/auth v0.8.0 // indirect
3030
cloud.google.com/go/auth/oauth2adapt v0.2.3 // indirect
31-
cloud.google.com/go/bigtable v1.27.2-0.20240730134218-123c88616251 // indirect
31+
cloud.google.com/go/bigtable v1.29.0 // indirect
3232
cloud.google.com/go/compute/metadata v0.5.0 // indirect
3333
cloud.google.com/go/iam v1.1.12 // indirect
3434
cloud.google.com/go/longrunning v0.5.11 // indirect
3535
cloud.google.com/go/monitoring v1.20.3 // indirect
36-
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.70.0 // indirect
36+
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.71.0 // indirect
3737
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
3838
github.com/agext/levenshtein v1.2.3 // indirect
3939
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
@@ -111,11 +111,11 @@ require (
111111
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 // indirect
112112
golang.org/x/mod v0.17.0 // indirect
113113
golang.org/x/net v0.27.0 // indirect
114-
golang.org/x/oauth2 v0.21.0 // indirect
115-
golang.org/x/sync v0.7.0 // indirect
114+
golang.org/x/oauth2 v0.22.0 // indirect
115+
golang.org/x/sync v0.8.0 // indirect
116116
golang.org/x/sys v0.22.0 // indirect
117117
golang.org/x/text v0.16.0 // indirect
118-
golang.org/x/time v0.5.0 // indirect
118+
golang.org/x/time v0.6.0 // indirect
119119
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
120120
google.golang.org/appengine v1.6.8 // indirect
121121
google.golang.org/genproto v0.0.0-20240730163845-b1a4ccb954bf // indirect

go.sum

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ cel.dev/expr v0.15.0/go.mod h1:TRSuuV7DlVCE/uwv5QbAiW/v8l5O8C4eEPHeu7gf7Sg=
55
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
66
cloud.google.com/go v0.115.0 h1:CnFSK6Xo3lDYRoBKEcAtia6VSC837/ZkJuRduSFnr14=
77
cloud.google.com/go v0.115.0/go.mod h1:8jIM5vVgoAEoiVxQ/O4BFTfHqulPZgs/ufEzMcFMdWU=
8-
cloud.google.com/go/auth v0.7.3 h1:98Vr+5jMaCZ5NZk6e/uBgf60phTk/XN84r8QEWB9yjY=
9-
cloud.google.com/go/auth v0.7.3/go.mod h1:HJtWUx1P5eqjy/f6Iq5KeytNpbAcGolPhOgyop2LlzA=
8+
cloud.google.com/go/auth v0.8.0 h1:y8jUJLl/Fg+qNBWxP/Hox2ezJvjkrPb952PC1p0G6A4=
9+
cloud.google.com/go/auth v0.8.0/go.mod h1:qGVp/Y3kDRSDZ5gFD/XPUfYQ9xW1iI7q8RIRoCyBbJc=
1010
cloud.google.com/go/auth/oauth2adapt v0.2.3 h1:MlxF+Pd3OmSudg/b1yZ5lJwoXCEaeedAguodky1PcKI=
1111
cloud.google.com/go/auth/oauth2adapt v0.2.3/go.mod h1:tMQXOfZzFuNuUxOypHlQEXgdfX5cuhwU+ffUuXRJE8I=
12-
cloud.google.com/go/bigtable v1.27.2-0.20240730134218-123c88616251 h1:OF+V7OrVPhsXy++iTHewE4VD1kv6ikWQJbRIiq1/Kjc=
13-
cloud.google.com/go/bigtable v1.27.2-0.20240730134218-123c88616251/go.mod h1:avmXcmxVbLJAo9moICRYMgDyTTPoV0MA0lHKnyqV4fQ=
12+
cloud.google.com/go/bigtable v1.29.0 h1:2CnFjKPwjpZMZdTi2RpppvxzD80zKzDYrLYEQw/NnAs=
13+
cloud.google.com/go/bigtable v1.29.0/go.mod h1:5p909nNdWaNUcWs6KGZO8mI5HUovstlmrIi7+eA5PTQ=
1414
cloud.google.com/go/compute/metadata v0.5.0 h1:Zr0eK8JbFv6+Wi4ilXAR8FJ3wyNdpxHKJNPos6LTZOY=
1515
cloud.google.com/go/compute/metadata v0.5.0/go.mod h1:aHnloV2TPI38yx4s9+wAZhHykWvVCfu7hQbF+9CWoiY=
1616
cloud.google.com/go/iam v1.1.12 h1:JixGLimRrNGcxvJEQ8+clfLxPlbeZA6MuRJ+qJNQ5Xw=
@@ -22,8 +22,8 @@ cloud.google.com/go/monitoring v1.20.3/go.mod h1:GPIVIdNznIdGqEjtRKQWTLcUeRnPjZW
2222
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
2323
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
2424
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
25-
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.70.0 h1:dqqxHZYK0tlzViFqAbKzMIkfboQVWYN1CTEM2sjBtmQ=
26-
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.70.0/go.mod h1:pL2Qt5HT+x6xrTd806oMiM3awW6kNIXB/iiuClz6m6k=
25+
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.71.0 h1:vRKCLiR3faPmXAoqSdwXLv28/kygggzaKXzgdm6GXhg=
26+
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.71.0/go.mod h1:pL2Qt5HT+x6xrTd806oMiM3awW6kNIXB/iiuClz6m6k=
2727
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
2828
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
2929
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg=
@@ -190,8 +190,8 @@ github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 h1:qHprzXy/As0rxedphECBEQAh
190190
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0/go.mod h1:H+8tjs9TjV2w57QFVSMBQacf8k/E1XwLXGCARgViC6A=
191191
github.com/hashicorp/terraform-plugin-testing v1.5.1 h1:T4aQh9JAhmWo4+t1A7x+rnxAJHCDIYW9kXyo4sVO92c=
192192
github.com/hashicorp/terraform-plugin-testing v1.5.1/go.mod h1:dg8clO6K59rZ8w9EshBmDp1CxTIPu3yA4iaDpX1h5u0=
193-
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240820164214-0ac834396a40 h1:93h8huZYFPlN4E5gvLW+GhLZxSnC1+dfsja3AW2kY4E=
194-
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240820164214-0ac834396a40/go.mod h1:mbLHS7zKRfkaFt9qpT/cmmwnrB5NSdnz1jpDoAZd6A0=
193+
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240820232428-04b789c2f9b2 h1:MffSs5GmWnt6PxnJctKByXuN+xU3JJpfo6P7bkNXNig=
194+
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240820232428-04b789c2f9b2/go.mod h1:IkI2dOHongwQ2RIUyitBH4rDJvYBuClAoFCheApCTpY=
195195
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
196196
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
197197
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
@@ -361,17 +361,17 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
361361
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
362362
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
363363
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
364-
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
365-
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
364+
golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
365+
golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
366366
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
367367
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
368368
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
369369
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
370370
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
371371
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
372372
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
373-
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
374-
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
373+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
374+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
375375
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
376376
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
377377
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -403,8 +403,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
403403
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
404404
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
405405
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
406-
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
407-
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
406+
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
407+
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
408408
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
409409
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
410410
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
@@ -422,8 +422,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
422422
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
423423
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
424424
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
425-
google.golang.org/api v0.190.0 h1:ASM+IhLY1zljNdLu19W1jTmU6A+gMk6M46Wlur61s+Q=
426-
google.golang.org/api v0.190.0/go.mod h1:QIr6I9iedBLnfqoD6L6Vze1UvS5Hzj5r2aUBOaZnLHo=
425+
google.golang.org/api v0.191.0 h1:cJcF09Z+4HAB2t5qTQM1ZtfL/PemsLFkcFG67qq2afk=
426+
google.golang.org/api v0.191.0/go.mod h1:tD5dsFGxFza0hnQveGfVk9QQYKcfp+VzgRqyXFxE0+E=
427427
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
428428
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
429429
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=

tfplan2cai/ancestrymanager/ancestrymanager.go

+34-26
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ import (
1818
"go.uber.org/zap"
1919
)
2020

21+
const (
22+
projectPrefix = "projects/"
23+
folderPrefix = "folders/"
24+
orgPrefix = "organizations/"
25+
unknownOrg = orgPrefix + "unknown"
26+
)
27+
2128
// AncestryManager is the interface that fetch ancestors for a resource.
2229
type AncestryManager interface {
2330
// Ancestors returns a list of ancestors.
@@ -73,8 +80,11 @@ func (m *manager) initAncestryCache(entries map[string]string) error {
7380
if err != nil {
7481
return err
7582
}
76-
// ancestry path should include the item itself
77-
if ancestors[0] != key {
83+
// The ancestry path should include the item itself, unless both the key and ancestor
84+
// have the projects/ prefix, indicating the key is a project ID and the ancestry is
85+
// project number. CAI ancestors use the project number, so that is preferred if it
86+
// is available.
87+
if ancestors[0] != key && !(strings.HasPrefix(key, projectPrefix) && strings.HasPrefix(ancestors[0], projectPrefix)) {
7888
ancestors = append([]string{key}, ancestors...)
7989
}
8090
m.store(key, ancestors)
@@ -88,7 +98,7 @@ func parseAncestryKey(val string) (string, error) {
8898
ix := strings.LastIndex(key, "/")
8999
if ix == -1 {
90100
// If not containing /, then treat it as a project.
91-
return fmt.Sprintf("projects/%s", key), nil
101+
return projectPrefix + key, nil
92102
} else {
93103
k := key[:ix]
94104
if k == "projects" || k == "folders" || k == "organizations" {
@@ -127,24 +137,15 @@ func (m *manager) fetchAncestors(config *transport_tpg.Config, tfData tpgresourc
127137

128138
orgID, orgOK := getOrganizationFromResource(tfData)
129139
if orgOK {
130-
orgKey = orgID
131-
if !strings.HasPrefix(orgKey, "organizations/") {
132-
orgKey = fmt.Sprintf("organizations/%s", orgKey)
133-
}
140+
orgKey = ensurePrefix(orgID, orgPrefix)
134141
}
135142
folderID, folderOK := getFolderFromResource(tfData)
136143
if folderOK {
137-
folderKey = folderID
138-
if !strings.HasPrefix(folderKey, "folders/") {
139-
folderKey = fmt.Sprintf("folders/%s", folderKey)
140-
}
144+
folderKey = ensurePrefix(folderID, folderPrefix)
141145
}
142146
project, _ := m.getProjectFromResource(tfData, config, cai)
143147
if project != "" {
144-
projectKey = project
145-
if !strings.HasPrefix(projectKey, "projects/") {
146-
projectKey = fmt.Sprintf("projects/%s", project)
147-
}
148+
projectKey = ensurePrefix(project, projectPrefix)
148149
}
149150

150151
switch cai.Type {
@@ -154,7 +155,7 @@ func (m *manager) fetchAncestors(config *transport_tpg.Config, tfData tpgresourc
154155
} else if orgOK {
155156
key = orgKey
156157
} else {
157-
return []string{"organizations/unknown"}, nil
158+
return []string{unknownOrg}, nil
158159
}
159160
case "cloudresourcemanager.googleapis.com/Organization":
160161
if !orgOK {
@@ -168,7 +169,7 @@ func (m *manager) fetchAncestors(config *transport_tpg.Config, tfData tpgresourc
168169
} else if projectKey != "" {
169170
key = projectKey
170171
} else {
171-
return []string{"organizations/unknown"}, nil
172+
return []string{unknownOrg}, nil
172173
}
173174
case "cloudresourcemanager.googleapis.com/Project", "cloudbilling.googleapis.com/ProjectBillingInfo":
174175
// for google_project and google_project_iam resources
@@ -183,7 +184,7 @@ func (m *manager) fetchAncestors(config *transport_tpg.Config, tfData tpgresourc
183184
// only folder_id or org_id is allowed for google_project
184185
if orgOK {
185186
// no need to use API to fetch ancestors
186-
ancestors = append(ancestors, fmt.Sprintf("organizations/%s", orgID))
187+
ancestors = append(ancestors, orgPrefix+orgID)
187188
return ancestors, nil
188189
}
189190
if folderOK {
@@ -199,13 +200,13 @@ func (m *manager) fetchAncestors(config *transport_tpg.Config, tfData tpgresourc
199200

200201
// neither folder_id nor org_id is specified
201202
if projectKey == "" {
202-
return []string{"organizations/unknown"}, nil
203+
return []string{unknownOrg}, nil
203204
}
204205
key = projectKey
205206

206207
default:
207208
if projectKey == "" {
208-
return []string{"organizations/unknown"}, nil
209+
return []string{unknownOrg}, nil
209210
}
210211
key = projectKey
211212
}
@@ -220,16 +221,16 @@ func (m *manager) getAncestorsWithCache(key string) ([]string, error) {
220221
ancestors = append(ancestors, cachedAncestors...)
221222
break
222223
}
223-
if strings.HasPrefix(cur, "organizations/") {
224+
if strings.HasPrefix(cur, orgPrefix) {
224225
ancestors = append(ancestors, cur)
225226
break
226227
}
227228
if m.resourceManagerV3 == nil || m.resourceManagerV1 == nil {
228229
return nil, fmt.Errorf("resourceManager required to fetch ancestry for %s from the API", cur)
229230
}
230-
if strings.HasPrefix(cur, "projects") {
231+
if strings.HasPrefix(cur, projectPrefix) {
231232
// fall back to use v1 API GetAncestry to avoid requiring extra folder permission
232-
projectID := strings.TrimPrefix(cur, "projects/")
233+
projectID := strings.TrimPrefix(cur, projectPrefix)
233234
var resp *crmv1.GetAncestryResponse
234235
var err error
235236
err = transport_tpg.Retry(transport_tpg.RetryOptions{
@@ -325,9 +326,9 @@ func normalizeAncestry(val string) string {
325326
old string
326327
new string
327328
}{
328-
{"organization/", "organizations/"},
329-
{"folder/", "folders/"},
330-
{"project/", "projects/"},
329+
{"organization/", orgPrefix},
330+
{"folder/", folderPrefix},
331+
{"project/", projectPrefix},
331332
} {
332333
val = strings.ReplaceAll(val, r.old, r.new)
333334
}
@@ -383,3 +384,10 @@ type NoOpAncestryManager struct{}
383384
func (*NoOpAncestryManager) Ancestors(config *transport_tpg.Config, tfData tpgresource.TerraformResourceData, cai *resources.Asset) ([]string, string, error) {
384385
return nil, "", nil
385386
}
387+
388+
func ensurePrefix(s, pre string) string {
389+
if strings.HasPrefix(s, pre) {
390+
return s
391+
}
392+
return pre + s
393+
}

tfplan2cai/ancestrymanager/ancestrymanager_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,8 @@ func TestParseAncestryPath_Fail(t *testing.T) {
10321032
}
10331033

10341034
func TestInitAncestryCache(t *testing.T) {
1035+
t.Parallel()
1036+
10351037
tests := []struct {
10361038
name string
10371039
entries map[string]string
@@ -1082,9 +1084,23 @@ func TestInitAncestryCache(t *testing.T) {
10821084
"organizations/123": {"organizations/123"},
10831085
},
10841086
},
1087+
{
1088+
name: "project id key with project number ancestry",
1089+
entries: map[string]string{
1090+
"projects/test-proj": "organizations/456/projects/123",
1091+
},
1092+
want: map[string][]string{
1093+
"projects/test-proj": {"projects/123", "organizations/456"},
1094+
"projects/123": {"projects/123", "organizations/456"},
1095+
"organizations/456": {"organizations/456"},
1096+
},
1097+
},
10851098
}
10861099
for _, test := range tests {
1100+
test := test
10871101
t.Run(test.name, func(t *testing.T) {
1102+
t.Parallel()
1103+
10881104
m := &manager{
10891105
ancestorCache: make(map[string][]string),
10901106
}

tfplan2cai/converters/google/resources/resource_converters.go

+3
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ func ResourceConverters() map[string][]cai.ResourceConverter {
339339
"google_iap_web_iam_policy": {iap.ResourceConverterIapWebIamPolicy()},
340340
"google_iap_web_iam_binding": {iap.ResourceConverterIapWebIamBinding()},
341341
"google_iap_web_iam_member": {iap.ResourceConverterIapWebIamMember()},
342+
"google_kms_ekm_connection_iam_policy": {kms.ResourceConverterKMSEkmConnectionIamPolicy()},
343+
"google_kms_ekm_connection_iam_binding": {kms.ResourceConverterKMSEkmConnectionIamBinding()},
344+
"google_kms_ekm_connection_iam_member": {kms.ResourceConverterKMSEkmConnectionIamMember()},
342345
"google_logging_log_view_iam_policy": {logging.ResourceConverterLoggingLogViewIamPolicy()},
343346
"google_logging_log_view_iam_binding": {logging.ResourceConverterLoggingLogViewIamBinding()},
344347
"google_logging_log_view_iam_member": {logging.ResourceConverterLoggingLogViewIamMember()},

tfplan2cai/converters/google/resources/services/bigquery/iam_bigquery_table.go

-5
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ func (u *BigQueryTableIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.
145145
return nil, err
146146
}
147147
var obj map[string]interface{}
148-
obj = map[string]interface{}{
149-
"options": map[string]interface{}{
150-
"requestedPolicyVersion": 1,
151-
},
152-
}
153148

154149
userAgent, err := tpgresource.GenerateUserAgentString(u.d, u.Config.UserAgent)
155150
if err != nil {

tfplan2cai/converters/google/resources/services/cloudquotas/cloudquotas_quota_preference.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func expandCloudQuotasQuotaPreferenceQuotaConfigGrantedValue(v interface{}, d tp
179179
}
180180

181181
func expandCloudQuotasQuotaPreferenceQuotaConfigTraceId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
182-
return v, nil
182+
return nil, nil
183183
}
184184

185185
func expandCloudQuotasQuotaPreferenceQuotaConfigAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {

tfplan2cai/converters/google/resources/services/compute/compute_subnetwork.go

+32
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package compute
1717
import (
1818
"context"
1919
"fmt"
20+
"log"
2021
"net"
2122
"reflect"
2223

@@ -48,6 +49,37 @@ func IsShrinkageIpCidr(_ context.Context, old, new, _ interface{}) bool {
4849
return true
4950
}
5051

52+
func sendSecondaryIpRangeIfEmptyDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
53+
// on create, return immediately as we don't need to determine if the value is empty or not
54+
if diff.Id() == "" {
55+
return nil
56+
}
57+
58+
sendZero := diff.Get("send_secondary_ip_range_if_empty").(bool)
59+
if !sendZero {
60+
return nil
61+
}
62+
63+
configSecondaryIpRange := diff.GetRawConfig().GetAttr("secondary_ip_range")
64+
if !configSecondaryIpRange.IsKnown() {
65+
return nil
66+
}
67+
configValueIsEmpty := configSecondaryIpRange.IsNull() || configSecondaryIpRange.LengthInt() == 0
68+
69+
stateSecondaryIpRange := diff.GetRawState().GetAttr("secondary_ip_range")
70+
if !stateSecondaryIpRange.IsKnown() {
71+
return nil
72+
}
73+
stateValueIsEmpty := stateSecondaryIpRange.IsNull() || stateSecondaryIpRange.LengthInt() == 0
74+
75+
if configValueIsEmpty && !stateValueIsEmpty {
76+
log.Printf("[DEBUG] setting secondary_ip_range to newly empty")
77+
diff.SetNew("secondary_ip_range", make([]interface{}, 0))
78+
}
79+
80+
return nil
81+
}
82+
5183
const ComputeSubnetworkAssetType string = "compute.googleapis.com/Subnetwork"
5284

5385
func ResourceConverterComputeSubnetwork() cai.ResourceConverter {

0 commit comments

Comments
 (0)