Hi all! I'm using the Pulumi Automation API and I ...
# general
p
Hi all! I'm using the Pulumi Automation API and I would like to let the users to have or not its configuration in his Pulumi.stackName.yaml_._ I would like to run his stack with AWS, but I found a little misleading accessing the aws config as there are multiple sources of truth (aws.Provider, stack Yaml Config and environment variables). Example1: If I want to access the region from within a custom ComponentResource, I can only get these variables if they are previously defined with
setConfig('aws:region', {value: 'myValue'})
Copy code
aws.config.region or aws.getRegion() // in this way I can somehow obtain the configuration
// also with const awsConfigRegion = new pulumi.Config('aws').get('region')
Example2: If I do not have them defined with setConfig/yaml file but in aws.Provider and pass this provider to my CustomResource, I haven't found a clear way to access these values_._
Copy code
// file1.ts
const awsProvider = new aws.Provider(
    'aws-provider',
    {region: 'eu-west-1', profile: 'some-profile'}
  )
  
const myCustomResource = new MyCustomComponentResource(
    {},
    { provider: awsProvider, parent: awsProvider }
)

// file2.ts
export class MyCustomComponentResource extends pulumi.ComponentResource{
    constructor(
        args: {},
        opts?: pulumi.ComponentResourceOptions | undefined
      ) {
        super('resource-type', 'resource-name', {}, opts)
        // how to correctly access here the parent provider config if setConfig has not been called?
        // I could pass here the aws provider config as an argument, but it doesn't seem like the intended way to access these values
      }
}
b
can you not just pass the provider through to your component resource?
p
this is what I was saying just above, but not sure if this was the "correct" way to do it
b
every resource in your Component will inherit the provider you pass, I think passing it as an opt is the right way to handle this
p
are you missing then the type for region?
Copy code
declare class Provider extends pulumi.ProviderResource {
    /**
     * Returns true if the given object is an instance of Provider.  This is designed to work even
     * when multiple copies of the Pulumi SDK have been loaded into the same process.
     */
    static isInstance(obj: any): obj is Provider;
    /**
     * The access key for API operations. You can retrieve this from the 'Security & Credentials' section of the AWS console.
     */
    readonly accessKey: pulumi.Output<string | undefined>;
    /**
     * The profile for API operations. If not set, the default profile created with `aws configure` will be used.
     */
    readonly profile: pulumi.Output<string | undefined>;
    /**
     * The secret key for API operations. You can retrieve this from the 'Security & Credentials' section of the AWS console.
     */
    readonly secretKey: pulumi.Output<string | undefined>;
    /**
     * The path to the shared credentials file. If not set this defaults to ~/.aws/credentials.
     */
    readonly sharedCredentialsFile: pulumi.Output<string | undefined>;
    /**
     * session token. A session token is only required if you are using temporary security credentials.
     */
    readonly token: pulumi.Output<string | undefined>;
    /**
     * Create a Provider resource with the given unique name, arguments, and options.
     *
     * @param name The _unique_ name of the resource.
     * @param args The arguments to use to populate this resource's properties.
     * @param opts A bag of options that control this resource's behavior.
     */
    constructor(name: string, args?: ProviderArgs, opts?: pulumi.ResourceOptions);
}
for
aws.Provider
, ts complains because it's not accessible