https://pulumi.com logo
#general
Title
# general
w

worried-engineer-33884

08/23/2019, 6:56 PM
We are having problem requiring config variables from a dependency library. In the library we have:
Copy code
const awsConfig = new pulumi.Config("aws");
const awsRegion = awsConfig.require("region");
and later
Copy code
const sns = new awsSdk.SNS({ region: awsRegion });
this errors with:
Copy code
Diagnostics:
  pulumi-nodejs:dynamic:Resource (monitoring-topic-email-subscription):
    error: Plan apply failed: Missing required configuration variable 'aws:region'
        please set a value using the command `pulumi config set aws:region <value>`

  pulumi:pulumi:Stack (dev):
    error: update failed
Is this because dependency libraries cannot read a project config? cc @dazzling-memory-8548
f

future-barista-68134

08/23/2019, 8:24 PM
just to confirm that it's set, does your Pulumi.dev.yaml include:
Copy code
config:
  aws:region: us-east-1
w

worried-engineer-33884

08/23/2019, 8:25 PM
yes
and top-level resources work fine
f

future-barista-68134

08/23/2019, 8:29 PM
also to confirm.. you're using the aws sdk directly?
w

worried-engineer-33884

08/23/2019, 8:33 PM
yes
I think this has something to do with the library being `require`ed in the serialized delete callback of the dynamic provider
this excerpt from the serialized function in the stack:
Copy code
function __f3(__0) {\n  return (function() {\n    with({ __awaiter: __f2, awsSdk: require(\"aws-sdk/lib/aws.js\"), awsRegion: \"us-west-2\", exports: require(\"pulumi-lib-aws/dist/sns/index.js\") }) {\n\nreturn
is what triggers the error.
require(\"pulumi-lib-aws/dist/sns/index.js\")
f

future-barista-68134

08/23/2019, 8:51 PM
let me see if I can reproduce this
can confirm that the require statement is a problem when calling within a dynamic provider, this must be one of the limitations of dynamic providers as mentioned in https://www.pulumi.com/docs/reference/programming-model/#dynamicproviders:
you should be able to move those statements above the definition of the dynamic provider and achieve the same result
for example:
Copy code
import * as pulumi from "@pulumi/pulumi";
import * as AWS from 'aws-sdk';

const awsConfig = new pulumi.Config("aws");
console.log(awsConfig);
const awsRegion = awsConfig.require("region");

const testprovider: pulumi.dynamic.ResourceProvider = {
    async create(inputs) {
        console.log(awsRegion);
        const sns = new AWS.SNS({region: awsRegion});
        return { id: "testing", outs: {} };
    }
}

class testResource extends pulumi.dynamic.Resource {
    constructor(name: string, opts?: pulumi.CustomResourceOptions) {
        super(testprovider, name, {}, opts);
    }
}

const newTestResource = new testResource("name");