Skip to content

Commit c79d42b

Browse files
authored
Merge branch 'GoogleCloudPlatform:main' into colab-schedule
2 parents 078088b + deae311 commit c79d42b

File tree

255 files changed

+6765
-369
lines changed

Some content is hidden

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

255 files changed

+6765
-369
lines changed

.github/workflows/build-downstream.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
# Cache Go modules
3434
- name: Cache Go modules
35-
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
35+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
3636
with:
3737
path: ~/go/pkg/mod
3838
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

.github/workflows/downstreams.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- 'FEATURE-BRANCH-*'
99
merge_group:
1010
types: [checks_requested]
11-
11+
pull_request:
1212

1313
concurrency:
1414
group: ${{ github.event_name == 'merge_group' && format('merge-group-{0}', github.event.merge_group.head_sha) || github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || format('commit-{0}', github.sha) }}

docs/content/code-review/create-pr.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ VCR test failures that do not immediately seem related to your PR are most likel
5252
git checkout modular-magician/auto-pr-PR_NUMBER
5353
make test
5454
make lint
55-
make testacc TEST=./google/services/container TESTARGS='-run=TestAccContainerNodePool'
55+
make testacc TEST=./google/services/container TESTARGS='-run=TestAccContainerNodePool_basic$$'
5656
```
5757
Replace PR_NUMBER with your PR's ID.
5858
{{< /tab >}}
@@ -65,7 +65,7 @@ VCR test failures that do not immediately seem related to your PR are most likel
6565
git checkout modular-magician/auto-pr-PR_NUMBER
6666
make test
6767
make lint
68-
make testacc TEST=./google/services/container TESTARGS='-run=TestAccContainerNodePool'
68+
make testacc TEST=./google/services/container TESTARGS='-run=TestAccContainerNodePool_basic$$'
6969
```
7070
Replace PR_NUMBER with your PR's ID.
7171
{{< /tab >}}

docs/content/test/run-tests.md

+43-4
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,22 @@ aliases:
5959

6060
1. Run acceptance tests for only modified resources. (Full test runs can take over 9 hours.) See [Go's documentation](https://pkg.go.dev/cmd/go#hdr-Testing_flags) for more information about `-run` and other flags.
6161
62+
```bash
63+
make testacc TEST=./google/services/container TESTARGS='-run=TestAccContainerNodePool_basic$$'
64+
```
65+
66+
To run all tests matching, e.g., `TestAccContainerNodePool*`, omit the trailing `$$`:
67+
6268
```bash
6369
make testacc TEST=./google/services/container TESTARGS='-run=TestAccContainerNodePool'
6470
```
6571
66-
> **Note:** Acceptance tests create actual infrastructure which can incur costs. Acceptance tests may not clean up after themselves if interrupted, so you may want to check for stray resources and / or billing charges.
72+
> **Note:** Acceptance tests create actual infrastructure which can incur costs. Acceptance tests may not clean up after themselves if interrupted, so you may want to check for stray resources and / or billing charges.
6773
6874
1. Optional: Save verbose test output (including API requests and responses) to a file for analysis.
6975
7076
```bash
71-
TF_LOG=DEBUG make testacc TEST=./google/services/container TESTARGS='-run=TestAccContainerNodePool_basic' > output.log
77+
TF_LOG=DEBUG make testacc TEST=./google/services/container TESTARGS='-run=TestAccContainerNodePool_basic$$' > output.log
7278
```
7379
7480
1. Optional: Debug tests with [Delve](https://github.com/go-delve/delve). See [`dlv test` documentation](https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_test.md) for information about available flags.
@@ -95,12 +101,19 @@ aliases:
95101
```bash
96102
make testacc TEST=./google-beta/services/container TESTARGS='-run=TestAccContainerNodePool'
97103
```
98-
> **Note:** Acceptance tests create actual infrastructure which can incur costs. Acceptance tests may not clean up after themselves if interrupted, so you may want to check for stray resources and / or billing charges.
104+
105+
To run all tests matching, e.g., `TestAccContainerNodePool*`, omit the trailing `$$`:
106+
107+
```bash
108+
make testacc TEST=./google-beta/services/container TESTARGS='-run=TestAccContainerNodePool'
109+
```
110+
111+
> **Note:** Acceptance tests create actual infrastructure which can incur costs. Acceptance tests may not clean up after themselves if interrupted, so you may want to check for stray resources and / or billing charges.
99112

100113
1. Optional: Save verbose test output to a file for analysis.
101114

102115
```bash
103-
TF_LOG=DEBUG make testacc TEST=./google-beta/services/container TESTARGS='-run=TestAccContainerNodePool_basic' > output.log
116+
TF_LOG=DEBUG make testacc TEST=./google-beta/services/container TESTARGS='-run=TestAccContainerNodePool_basic$$' > output.log
104117
```
105118

106119
1. Optional: Debug tests with [Delve](https://github.com/go-delve/delve). See [`dlv test` documentation](https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_test.md) for information about available flags.
@@ -290,6 +303,32 @@ Configure Terraform to use locally-built binaries for `google` and `google-beta`
290303
TF_LOG=DEBUG TF_LOG_PATH=output.log TF_CLI_CONFIG_FILE="$HOME/tf-dev-override.tfrc" terraform apply
291304
```
292305

306+
### Run Tests with VCR Locally
307+
308+
VCR tests record HTTP request/response interactions in cassettes and replay them in future runs without calling the real API.
309+
310+
Running tests in `REPLAYING` mode locally can sometimes be useful. In particular, it can allow you to test more quickly, cheaply, and without spinning up real infrastructure, once you've got an initial recording.
311+
312+
It can also be helpful for debugging tests that seem to work locally, but fail in CI in replaying mode.
313+
314+
VCR is controlled via two variables:
315+
- `VCR_MODE`: `REPLAYING` or `RECORDING` mode
316+
- `VCR_PATH`: Path where recorded cassettes are stored.
317+
318+
Ensure both variables are configured to properly trigger VCR tests locally.
319+
320+
If you don't already have an existing cassette that's up to date, first do a run in `RECORDING` mode:
321+
322+
```bash
323+
VCR_PATH=$HOME/.vcr/ VCR_MODE=RECORDING make testacc TEST=./google/services/alloydb TESTARGS='-run=TestAccContainerNodePool_basic$$'
324+
```
325+
326+
Now run the same test again in `REPLAYING` mode:
327+
328+
```bash
329+
VCR_PATH=$HOME/.vcr/ VCR_MODE=REPLAYING make testacc TEST=./google/services/alloydb TESTARGS='-run=TestAccContainerNodePool_basic$$'
330+
```
331+
293332
### Cleanup
294333
295334
To stop using developer overrides, stop setting `TF_CLI_CONFIG_FILE` in the commands you are executing.

mmv1/api/resource.go

+44-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ type Resource struct {
337337
// fine-grained resources and legacy resources.
338338
ApiResourceTypeKind string `yaml:"api_resource_type_kind,omitempty"`
339339

340-
ImportPath string `yaml:"-"`
340+
ImportPath string `yaml:"-"`
341+
SourceYamlFile string `yaml:"-"`
341342
}
342343

343344
func (r *Resource) UnmarshalYAML(unmarshal func(any) error) error {
@@ -1787,3 +1788,45 @@ func (r Resource) CaiIamAssetNameTemplate(productBackendName string) string {
17871788
}
17881789
return fmt.Sprintf("//%s.googleapis.com/%s/{{%s}}", productBackendName, caiBaseUrl, r.IamParentResourceName())
17891790
}
1791+
1792+
func urlContainsOnlyAllowedKeys(templateURL string, allowedKeys []string) bool {
1793+
// Create regex to match anything between {{ and }}
1794+
re := regexp.MustCompile(`{{\s*([^}]+)\s*}}`)
1795+
1796+
// Find all matches in the template URL
1797+
matches := re.FindAllStringSubmatch(templateURL, -1)
1798+
1799+
// Create a map of allowed keys for O(1) lookup
1800+
allowedKeysMap := make(map[string]bool)
1801+
for _, key := range allowedKeys {
1802+
allowedKeysMap[key] = true
1803+
}
1804+
1805+
// Check each found key against the allowed keys
1806+
for _, match := range matches {
1807+
if len(match) < 2 {
1808+
continue
1809+
}
1810+
1811+
// Trim spaces from the key
1812+
key := strings.TrimSpace(match[1])
1813+
1814+
// If the key isn't in our allowed list, return false
1815+
if !allowedKeysMap[key] {
1816+
return false
1817+
}
1818+
}
1819+
1820+
return true
1821+
}
1822+
1823+
func (r Resource) ShouldGenerateSweepers() bool {
1824+
allowedKeys := []string{"project", "region", "location", "zone", "billing_account"}
1825+
if !urlContainsOnlyAllowedKeys(r.ListUrlTemplate(), allowedKeys) {
1826+
return false
1827+
}
1828+
if r.ExcludeSweeper || r.CustomCode.CustomDelete != "" || r.CustomCode.PreDelete != "" || r.CustomCode.PostDelete != "" || r.ExcludeDelete {
1829+
return false
1830+
}
1831+
return true
1832+
}

mmv1/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ func GenerateProduct(productChannel chan string, providerToGenerate provider.Pro
256256

257257
resource := &api.Resource{}
258258
api.Compile(resourceYamlPath, resource, overrideDirectory)
259+
resource.SourceYamlFile = resourceYamlPath
259260

260261
resource.TargetVersionName = *version
261262
resource.Properties = resource.AddLabelsRelatedFields(resource.PropertiesWithExcluded(), nil)

mmv1/products/accesscontextmanager/ServicePerimeter.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,15 @@ properties:
384384
- name: 'accessLevel'
385385
type: String
386386
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
387+
- name: 'resource'
388+
type: String
389+
description: |
390+
A Google Cloud resource that is allowed to egress the perimeter.
391+
Requests from these resources are allowed to access data outside the perimeter.
392+
Currently only projects are allowed. Project format: `projects/{project_number}`.
393+
The resource may be in any Google Cloud organization, not just the
394+
organization that the perimeter is defined in. `*` is not allowed, the
395+
case of allowing all Google Cloud resources only is not supported.
387396
- name: 'sourceRestriction'
388397
type: Enum
389398
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
@@ -693,6 +702,15 @@ properties:
693702
- name: 'accessLevel'
694703
type: String
695704
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
705+
- name: 'resource'
706+
type: String
707+
description: |
708+
A Google Cloud resource that is allowed to egress the perimeter.
709+
Requests from these resources are allowed to access data outside the perimeter.
710+
Currently only projects are allowed. Project format: `projects/{project_number}`.
711+
The resource may be in any Google Cloud organization, not just the
712+
organization that the perimeter is defined in. `*` is not allowed, the
713+
case of allowing all Google Cloud resources only is not supported.
696714
- name: 'sourceRestriction'
697715
type: Enum
698716
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'

mmv1/products/accesscontextmanager/ServicePerimeterDryRunEgressPolicy.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ properties:
128128
- name: 'accessLevel'
129129
type: String
130130
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
131+
- name: 'resource'
132+
type: String
133+
description: |
134+
A Google Cloud resource that is allowed to egress the perimeter.
135+
Requests from these resources are allowed to access data outside the perimeter.
136+
Currently only projects are allowed. Project format: `projects/{project_number}`.
137+
The resource may be in any Google Cloud organization, not just the
138+
organization that the perimeter is defined in. `*` is not allowed, the
139+
case of allowing all Google Cloud resources only is not supported.
131140
- name: 'sourceRestriction'
132141
type: Enum
133142
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'

mmv1/products/accesscontextmanager/ServicePerimeterEgressPolicy.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ properties:
125125
- name: 'accessLevel'
126126
type: String
127127
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
128+
- name: 'resource'
129+
type: String
130+
description: |
131+
A Google Cloud resource that is allowed to egress the perimeter.
132+
Requests from these resources are allowed to access data outside the perimeter.
133+
Currently only projects are allowed. Project format: `projects/{project_number}`.
134+
The resource may be in any Google Cloud organization, not just the
135+
organization that the perimeter is defined in. `*` is not allowed, the
136+
case of allowing all Google Cloud resources only is not supported.
128137
- name: 'sourceRestriction'
129138
type: Enum
130139
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'

mmv1/products/accesscontextmanager/ServicePerimeters.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,15 @@ properties:
373373
- name: 'accessLevel'
374374
type: String
375375
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
376+
- name: 'resource'
377+
type: String
378+
description: |
379+
A Google Cloud resource that is allowed to egress the perimeter.
380+
Requests from these resources are allowed to access data outside the perimeter.
381+
Currently only projects are allowed. Project format: `projects/{project_number}`.
382+
The resource may be in any Google Cloud organization, not just the
383+
organization that the perimeter is defined in. `*` is not allowed, the
384+
case of allowing all Google Cloud resources only is not supported.
376385
- name: 'sourceRestriction'
377386
type: Enum
378387
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
@@ -674,6 +683,15 @@ properties:
674683
- name: 'accessLevel'
675684
type: String
676685
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
686+
- name: 'resource'
687+
type: String
688+
description: |
689+
A Google Cloud resource that is allowed to egress the perimeter.
690+
Requests from these resources are allowed to access data outside the perimeter.
691+
Currently only projects are allowed. Project format: `projects/{project_number}`.
692+
The resource may be in any Google Cloud organization, not just the
693+
organization that the perimeter is defined in. `*` is not allowed, the
694+
case of allowing all Google Cloud resources only is not supported.
677695
- name: 'sourceRestriction'
678696
type: Enum
679697
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'

mmv1/products/apphub/Application.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ custom_code:
4040
constants: 'templates/terraform/constants/apphub_application.go.tmpl'
4141
custom_diff:
4242
- 'apphubApplicationCustomizeDiff'
43+
sweeper:
44+
regions:
45+
- "us-central1"
46+
- "us-east1"
47+
- "global"
4348
examples:
4449
- name: 'apphub_application_basic'
4550
primary_resource_id: 'example'

mmv1/products/artifactregistry/Repository.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ custom_code:
5454
constants: 'templates/terraform/constants/artifact_registry_repository.go.tmpl'
5555
encoder: 'templates/terraform/encoders/location_from_region.go.tmpl'
5656
pre_create: 'templates/terraform/pre_create/artifact_registry_remote_repository.go.tmpl'
57+
sweeper:
58+
regions:
59+
- "us-central1"
60+
- "us"
5761
examples:
5862
- name: 'artifact_registry_repository_basic'
5963
primary_resource_id: 'my-repo'

0 commit comments

Comments
 (0)