https://pulumi.com logo
#aws
Title
# aws
p

proud-pizza-80589

09/29/2020, 9:47 AM
I’m really struggling with some of the provider configurations. I have a stack that deploys three k8s clusters, one on aws, one on azure and one on gcp. And, and this is proving hard, i do not want any pulumi config variables and use only environment variables or variables coded in the TS code. Got gcp and azure this is fine, i have the credentials in env files and use in the cluster creation the location field to set the region to e.g. europe-west1-b. But for eks, there is no location field, and as far as i can tell from the docs, it has to be either in the config yaml file, OR use a custom provider. I would have expected the following to work, but since i use a new aws provider, it complains that i also have to do the providerCredentialsOpts `Error: providerCredentialOpts and an AWS provider instance must be set together`:
Copy code
const provider = new aws.Provider(`aws`, {
      region: location,
    });

    const cluster = new eks.Cluster(
      name,
      {
        skipDefaultNodeGroup: true,
        vpcId: vpc.id,
        publicSubnetIds: vpc.publicSubnetIds,
        privateSubnetIds: vpc.privateSubnetIds,
        instanceRoles: [role],
        name,
      },
      { provider: this.provider }
    );
But as far as I can tell, it does not listen to the env vars any more so i have to hardcode in the credentials or fetcht hem myself out or process.env.
s

steep-angle-29984

09/29/2020, 10:01 AM
I'm not sure if that works but just found the environment variable AWS_DEFAULT_REGION in terraform documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs#environment-variables
c

cool-fireman-90027

09/29/2020, 2:13 PM
Hi @proud-pizza-80589 Add this to the top of your code to replace the provider that you created:
Copy code
let aws = require("@pulumi/aws");
// Create an AWS provider for the us-east-2 region.
let useast2 = new aws.Provider("useast2", { region: "us-east-2" });
Then where you have this:
Copy code
{ provider: this.provider }
you can do this:
{ providers: {aws: useast2} }
replace useast2 with eu-west-1 https://www.pulumi.com/docs/intro/concepts/programming-model/#explicit-provider-configuration Can you try that and let us know?
p

proud-pizza-80589

09/29/2020, 2:18 PM
Copy code
const regionProvider = new aws.Provider(location, {
      region: location,
    });

    const vpc = new awsx.ec2.Vpc(
      name,
      {
        cidrBlock: '172.16.0.0/16',
        tags: { Name: name },
      },
      { provider: { aws: regionProvider } }
    );
error:
Copy code
Type '{ aws: aws.Provider; }' is not assignable to type 'ProviderResource'.
  Object literal may only specify known properties, and 'aws' does not exist in type 'ProviderResource'.
and location is
location: aws.Region,
which is a string
c

cool-fireman-90027

09/29/2020, 2:30 PM
Can you try this testing the following? Change
Copy code
region: location
in the const regionProvider section to:
region: "eu-west-1"
or update the variable for location to: const location = "eu-west-1"
p

proud-pizza-80589

09/29/2020, 2:55 PM
that is not the issue, the issue is that { provider: { aws: regionProvider } } is invalid. provider needs to be a ProviderResource and a ProviderResource does not have a ‘aws’ key
{ provider: regionProvider } is valid
however, this is the same as my first snippet
providerCredentialOpts is actually part of the EKS package
found a good solution, with naming the provider like the location, i just need to add the following to the cluster creation
Copy code
providerCredentialOpts: {
          profileName: location,
        },
so fully dynamic, no credentials needed
thx @cool-fireman-90027!
c

cool-fireman-90027

09/29/2020, 3:11 PM
@proud-pizza-80589 Awesome you got it working, i created this gist just in case you wanted to see what I had, since I have a StackReference for a vpc. This is rough code: https://gist.github.com/tusharshahrs/c9a6b58f1af47d2a5c7b9b4575cb4d1f
p

proud-pizza-80589

09/29/2020, 3:11 PM
yeah, that dod not compile for me, maybe i have different versions of the pulumi libs