sparse-intern-71089
05/24/2023, 9:02 PMlittle-cartoon-10569
05/24/2023, 9:37 PMprovider
opt, not the dependsOn
opt.damp-lock-9822
05/24/2023, 9:40 PMdamp-lock-9822
05/24/2023, 9:44 PMconst commonProviderArgs = {
accessKey: this.awsConfig.AWS_ACCESS_KEY,
secretKey: pulumi.secret(this.awsConfig.AWS_SECRET_KEY),
assumeRole: {
externalId: this.awsConfig.EXTERNAL_ID,
roleArn: this.awsConfig.ROLE_ARN,
},
};
const awsClassicProvider = new awsClassic.Provider("aws-classic-test", {
...commonProviderArgs,
region: 'us-east-2',
});
const awsFix = new AwsFixtureComponent(fix.baseName, fix, configuration, awsConfig, awsClassicProvider, {providers: [awsClassicProvider]});
awsFix
.initialize()
.then((fix) => {
return fix;
})
.catch((err) => {
log.error(err);
});
return awsFix;
damp-lock-9822
05/24/2023, 9:45 PMconst fixtureAmi = await aws.ec2
.getAmi({
filters: [
{
name: "name",
values: ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"],
},
],
mostRecent: true,
},
{ provider: this.provider }
)
.then((invoke) => invoke.id);
damp-lock-9822
05/24/2023, 9:47 PMlittle-cartoon-10569
05/24/2023, 9:51 PMDefault provider for 'aws' disabled. 'awsec2/getAmigetAmi' must use an explicit providerIf you're getting this error, then the problem is the call to
getAmi()
. Since you have disabled default providers (which is good imo), you need to pass a provider to every call to AWS. This error is saying you haven't passed the provider to the call to getAmi()
.damp-lock-9822
05/24/2023, 9:52 PMlittle-cartoon-10569
05/24/2023, 9:53 PMdamp-lock-9822
05/24/2023, 9:53 PMlittle-cartoon-10569
05/24/2023, 9:54 PMthis.provider
? Could it be null or undefined?little-cartoon-10569
05/24/2023, 9:55 PMconst awsFix = new AwsFixtureComponent(fix.baseName, fix, configuration, awsConfig, awsClassicProvider, {providers: [awsClassicProvider]});
The question here is: ?!?little-cartoon-10569
05/24/2023, 9:56 PM.then((invoke) => invoke.id);
little-cartoon-10569
05/24/2023, 9:57 PMdamp-lock-9822
05/24/2023, 10:03 PM.then((invoke) => invoke.id)
I pulled from a pulumi template (https://github.com/pulumi/templates/blob/master/vm-aws-typescript/index.ts)damp-lock-9822
05/24/2023, 10:04 PMlittle-cartoon-10569
05/24/2023, 10:09 PMgetAmiOutput()
. You can now use getAmiOutput(...).id
, which is more idiomatic. Also, you might store the AMI object in the variable (since that's more flexible) and get the id only when you need it (passing it into the EC2 constructor).little-cartoon-10569
05/24/2023, 10:09 PMprovider
or providers
opts.damp-lock-9822
05/24/2023, 10:15 PMdamp-lock-9822
05/24/2023, 10:26 PMpulumi.all([awsClassicProvider]).apply(([awsProvider]) => {
const awsFix = new AwsFixtureComponent(fix.baseName, fix, {provider: awsProvider});
awsFix
.initialize()
.then((fix) => {
return fix;
})
.catch((err) => {
log.error(err);
});
return awsFix;
});
damp-lock-9822
05/24/2023, 10:27 PMexport class AwsFixtureComponent extends pulumi.ComponentResource {
public readonly fixture: AwsFixture;
public readonly provider: aws.Provider;
public readonly opts: pulumi.ComponentResourceOptions | undefined;
constructor(name: string, fixture: AwsFixture, opts?: pulumi.ComponentResourceOptions) {
super("fixtures:awsFixture", name, {}, opts);
this.fixture = fixture;
this.provider = this.opts?.provider as aws.Provider;
this.opts=opts;
}
little-cartoon-10569
05/24/2023, 10:27 PMdamp-lock-9822
05/24/2023, 10:27 PMdamp-lock-9822
05/24/2023, 10:27 PMdamp-lock-9822
05/24/2023, 10:28 PMlittle-cartoon-10569
05/24/2023, 10:28 PMthis.provider = this.opts?.provider as aws.Provider;
You're not detecting a missing provider.little-cartoon-10569
05/24/2023, 10:29 PM?
with !
, see where it's undefined.little-cartoon-10569
05/24/2023, 10:29 PMconst provider: aws.Provider;
. That'll barf sooner, too.damp-lock-9822
05/24/2023, 10:34 PMdamp-lock-9822
05/24/2023, 10:34 PM?
there, it was undefined twice before being defineddamp-lock-9822
05/24/2023, 10:35 PMprovider
and opts
right before making the getAmi call)damp-lock-9822
05/24/2023, 10:37 PMdamp-lock-9822
05/24/2023, 10:39 PM!
it fails in the constructor ('trying to read properties of undefined')little-cartoon-10569
05/24/2023, 10:41 PMdamp-lock-9822
05/24/2023, 11:25 PMlittle-cartoon-10569
05/24/2023, 11:33 PM