https://pulumi.com logo
#automation-api
Title
# automation-api
m

most-lighter-95902

11/22/2021, 10:45 PM
I’m using the tutorial as a base for the code and setting the configs with
await stack.setAllConfig(configMap)
to set multiple configs at the same time
r

red-match-15116

11/22/2021, 10:46 PM
Can you show a code snippet?
m

most-lighter-95902

11/22/2021, 10:47 PM
Copy code
export const run = async ({
  projectName,
  stackName,
  program,
  plugins,
  configMap = {},
}) => {
  const args: InlineProgramArgs = {
    projectName,
    stackName,
    program,
  }
  const stack = await LocalWorkspace.createOrSelectStack(args)

  if (Array.isArray(plugins) && plugins.length > 0) {
    const pluginPromises = plugins.map(({ name, version, kind }) => {
      return stack.workspace.installPlugin(name, version, kind)
    })
    await Promise.all(pluginPromises)
  }

      console.log('configs inside Pulumi Run...', configMap)
    <http://console.info|console.info>(infoColor('Setting up config...\n'))
    await stack.setAllConfig(configMap)
    <http://console.info|console.info>(successColor('Config set\n'))

  await stack.refresh({ onOutput: <http://console.info|console.info> })

  const upRes = await stack.up({ onOutput: <http://console.info|console.info> })
  return upRes.outputs
}
Copy code
const program = async () => {
  const customDomain = config.require('custom_domain')
  const currentAwsAccount = await aws.getCallerIdentity({})
  const awsAccountId = currentAwsAccount.accountId
  const currentAwsRegion = await aws.getRegion()
  const awsRegion = currentAwsRegion.name
}
Copy code
const configMap = {
  'aws:region': { value: 'us-west-1' },
  'custom_domain': { value: '<http://sidetrek.com|sidetrek.com>' },
}
The thing is, it looks like other configs are setting fine - it’s just that aws:region is not available
r

red-match-15116

11/22/2021, 10:51 PM
Huh... weird.
What's the output of
getAllConfig
?
(after setting)
And I guess just making sure you're using the aws classic provider and not aws-native
m

most-lighter-95902

11/22/2021, 10:55 PM
Copy code
{
  'aws:region': { value: 'us-west-1', secret: false },
  'create-knative-cluster:custom_domain': { value: '<http://sidetrek.com|sidetrek.com>', secret: false },
}
Yes I think so -
import * as aws from '@pulumi/aws'
r

red-match-15116

11/22/2021, 10:57 PM
When do you see this error?
m

most-lighter-95902

11/22/2021, 10:58 PM
So I create a function called
const main = async () => {}
and then
export = main
In another file,
const mainPulumiProgram = require('./main')
Then I run the run function:
Copy code
await run({
    projectName,
    stackName: 'cluster',
    program: mainPulumiProgram,
    configMap: {
  'aws:region': { value: 'us-west-1' },
  'custom_domain': { value: '<http://sidetrek.com|sidetrek.com>' },
},
    options: { destroy: false },
  })
The run function I mentioned at the beginning of this thread
I think it’s the same setup as the tutorial except for having the main function in another file and importing it
r

red-match-15116

11/22/2021, 11:04 PM
That shouldn't be a problem... yeah I'm not really sure what's going on. From the example you've provided I would expect that to work. FWIW unless something has broken recently this definitely used to work... all the examples use it and are tested.
m

most-lighter-95902

11/22/2021, 11:04 PM
Hmm
Yeah it’s definitely erroring out on my end
Other configs seem to work - just not getting the aws:region for some reason
Could it have something to do with the namespace?
r

red-match-15116

11/22/2021, 11:05 PM
What do you mean "not getting"? I thought you said it was throwing an error.
Do you mean you're not being able to access the region inside the pulumi program or it's throwing an error when you try to run
stack.up()
?
m

most-lighter-95902

11/22/2021, 11:08 PM
So in the main program,
const customDomain = config.require('custom_domain')
seems to work - so configs seem to be setting OK
But there’s an error:
* missing required configuration key "aws:region": The region where AWS operations will take place. Examples are us-east-1, us-west-2, etc.
Oh wait…
Do I need to create aws provider explicitly in Automation API?
r

red-match-15116

11/22/2021, 11:15 PM
no...
In your main program can you try
Copy code
const awsConfig = new pulumi.Config("aws")
const region = awsConfig.require("region")
It's unclear to me from your description where the error is happening because if the config values are being set then I'm not sure how it's also throwing an error at the same time.
Perhaps you're trying to access the region somewhere before it is set.
m

most-lighter-95902

11/22/2021, 11:26 PM
Hmm interesting
So it looks like refresh is what’s throwing the error
If I comment that out and do an
up
, it runs without error
@red-match-15116 I’ll just leave refresh step out for now - can’t really figure out what’s happening there. Thanks for all your help - it’s much appreciated!
r

red-match-15116

11/23/2021, 12:20 AM
np! I agree it's super odd that refresh would be throwing this. It seems to me that it's stemming from the use of functions in your main program. As a test you could replace
Copy code
const currentAwsRegion = await aws.getRegion()
const awsRegion = currentAwsRegion.name
with
Copy code
const awsConfig = new pulumi.Config("aws")
const region = awsConfig.require("region")
And maybe omit the lines:
Copy code
const currentAwsAccount = await aws.getCallerIdentity({})
const awsAccountId = currentAwsAccount.accountId
If it no longer throws that error then it's related to the functions and refresh...
m

most-lighter-95902

11/23/2021, 2:54 AM
Sorry what do you mean by functions and refresh? Can you elaborate a little?
r

red-match-15116

11/23/2021, 3:00 AM
aws.GetRegion()
and
aws.getCallerIdentity()
are pulumi Functions. They are different than Resources because they fetch data about existing cloud state instead of create a resource in the cloud. This is just a hunch on my part but I'm wondering if there's a link between the issue of
refresh
throwing that error and the fact that your program contains pulumi functions.