Skip to content

Commit

Permalink
Fix getRegion functions (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
flostadler authored Sep 25, 2024
1 parent 0d6f1b4 commit a12ec3b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion awsx/s3/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
Expand Down
13 changes: 6 additions & 7 deletions awsx/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,14 @@ export function getRegionFromOpts(opts: pulumi.CustomResourceOptions): pulumi.Ou

/** @internal */
export function getRegion(res: pulumi.Resource): pulumi.Output<aws.Region> {
// 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 ? (<any>provider).region : undefined;
return region || aws.config.region;
function getRegionFromProvider(
provider: pulumi.ProviderResource | undefined,
): pulumi.Output<aws.Region> {
return aws.getRegionOutput({}, { provider }).apply((region) => region.name as aws.Region);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package examples

import (
"fmt"
"os"
"path/filepath"
"testing"
"time"
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit a12ec3b

Please sign in to comment.