diff --git a/awsx/s3/bucket.ts b/awsx/s3/bucket.ts index 90c02c07c..1919031a6 100644 --- a/awsx/s3/bucket.ts +++ b/awsx/s3/bucket.ts @@ -16,7 +16,7 @@ import * as aws from "@pulumi/aws"; import * as pulumi from "@pulumi/pulumi"; import { ResourceOptions } from "@pulumi/pulumi"; import * as schema from "../schema-types"; -import { getRegion, getRegionFromOpts, parseArn } from "../utils"; +import { parseArn } from "../utils"; export interface BucketId { name: pulumi.Output; diff --git a/awsx/utils.ts b/awsx/utils.ts index 81a272a4f..d03d499b9 100644 --- a/awsx/utils.ts +++ b/awsx/utils.ts @@ -82,15 +82,14 @@ export function getRegionFromOpts(opts: pulumi.CustomResourceOptions): pulumi.Ou /** @internal */ export function getRegion(res: pulumi.Resource): pulumi.Output { - // A little strange, but all we're doing is passing a fake type-token simply to get - // the AWS provider from this resource. - const provider = res.getProvider ? res.getProvider("aws::") : undefined; - return getRegionFromProvider(provider); + // uses the provider from the parent resource to fetch the region + return aws.getRegionOutput({}, { parent: res }).apply((region) => region.name as aws.Region); } -function getRegionFromProvider(provider: pulumi.ProviderResource | undefined) { - const region = provider ? (provider).region : undefined; - return region || aws.config.region; +function getRegionFromProvider( + provider: pulumi.ProviderResource | undefined, +): pulumi.Output { + return aws.getRegionOutput({}, { provider }).apply((region) => region.name as aws.Region); } /** diff --git a/examples/examples_nodejs_test.go b/examples/examples_nodejs_test.go index bbe15d59d..0e799f454 100644 --- a/examples/examples_nodejs_test.go +++ b/examples/examples_nodejs_test.go @@ -18,6 +18,7 @@ package examples import ( "fmt" + "os" "path/filepath" "testing" "time" @@ -46,6 +47,23 @@ func TestAccEcsCapacityProviderService(t *testing.T) { integration.ProgramTest(t, &test) } +func TestRegress1112(t *testing.T) { + t.Setenv("AWS_REGION", "") + os.Unsetenv("AWS_REGION") + test := integration.ProgramTestOptions{ + Quick: true, + SkipRefresh: true, + }.With(integration.ProgramTestOptions{ + Dependencies: []string{ + "@pulumi/awsx", + }, + NoParallel: true, // cannot use call t.Parallel after t.Setenv + RunUpdateTest: false, + Dir: filepath.Join(getCwd(t), "ecs", "nodejs"), + }) + integration.ProgramTest(t, &test) +} + func TestLbSimple(t *testing.T) { test := getNodeJSBaseOptions(t). With(integration.ProgramTestOptions{