Skip to content

Commit 5c76503

Browse files
Fix region injection for global resources (#5709)
Global resources that had a `region` argument in v6 have deprecated the `region` argument and added a new resource specific region argument (e.g. `StackSetInstance` has a `stackSetInstanceRegion` argument). This PR adds an additional check to exclude any `region` argument that has been deprecated. fixes #5707 --------- Co-authored-by: Guinevere Saenger <[email protected]>
1 parent 82759f9 commit 5c76503

File tree

7 files changed

+85
-1
lines changed

7 files changed

+85
-1
lines changed

examples/examples_nodejs_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,18 @@ func TestRegress3421Update(t *testing.T) {
672672
test.Up(t)
673673
}
674674

675+
func TestGlobalResourcesUseSeparateRegionArgument(t *testing.T) {
676+
skipIfShort(t)
677+
t.Parallel()
678+
test := pulumitest.NewPulumiTest(t, "test-programs/global-region-res",
679+
opttest.LocalProviderPath("aws", filepath.Join(getCwd(t), "..", "bin")),
680+
opttest.YarnLink("@pulumi/aws"),
681+
)
682+
683+
// only preview is needed to verify this
684+
test.Preview(t)
685+
}
686+
675687
func getJSBaseOptions(t *testing.T) integration.ProgramTestOptions {
676688
envRegion := getEnvRegion(t)
677689
baseJS := integration.ProgramTestOptions{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: global-region-res
2+
runtime: nodejs
3+
description: Testing global region resources
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# examples
2+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2016-2018, Pulumi Corporation.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import * as aws from '@pulumi/aws';
16+
17+
const stackset = new aws.cloudformation.StackSet('stackset', {
18+
autoDeployment: { enabled: true, retainStacksOnAccountRemoval: false },
19+
capabilities: ['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM'],
20+
description: 'my stack set',
21+
permissionModel: 'SERVICE_MANAGED',
22+
templateBody: `
23+
Resources:
24+
MyBucket:
25+
Type: AWS::S3::Bucket
26+
`,
27+
});
28+
29+
new aws.cloudformation.StackSetInstance('instance', {
30+
stackSetName: stackset.name,
31+
stackSetInstanceRegion: 'us-east-2',
32+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "global-region-res",
3+
"version": "0.0.1",
4+
"license": "Apache-2.0",
5+
"scripts": {
6+
"build": "tsc"
7+
},
8+
"dependencies": {
9+
"@pulumi/aws": "^7.0.0",
10+
"@pulumi/pulumi": "^3.0.0"
11+
},
12+
"devDependencies": {
13+
"@types/node": "^8.0.0"
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"strict": true,
4+
"outDir": "bin",
5+
"target": "es2016",
6+
"module": "commonjs",
7+
"moduleResolution": "node",
8+
"sourceMap": true,
9+
"experimentalDecorators": true,
10+
"pretty": true,
11+
"noFallthroughCasesInSwitch": true,
12+
"noImplicitReturns": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": [
16+
"index.ts"
17+
]
18+
}

provider/region.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ func applyRegionPreCheckCallback(
1919
key string,
2020
res shim.Resource,
2121
) {
22-
if _, ok := res.Schema().GetOk("region"); !ok {
22+
// global resources have a separate region argument (e.g. `stack_set_instance_region`)
23+
// and have deprecated the `region` argument if they had one
24+
if region, ok := res.Schema().GetOk("region"); !ok || region.Deprecated() != "" {
2325
return
2426
}
2527
if callback := prov.Resources[key].PreCheckCallback; callback != nil {

0 commit comments

Comments
 (0)