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

bumpy-agent-19616

06/21/2021, 10:01 AM
Does anyone have any idea on how to set config with objects involved using automation API? for example,
<project>:atlas:
cidr: 172.xx.xx.xx/24
cluster:
autoScalingDiskGbEnabled: true
mongoDbMajorVersion: 4.2
networkpeering:
resourceGroupName: rg-name
vnetName: vnet-name
numShards: 1
b

billowy-army-68599

06/21/2021, 10:19 AM
what have you tried? you can probably just write the YAML file directly using your language yaml parser if needed
b

bumpy-agent-19616

06/21/2021, 10:21 AM
Copy code
export interface AtlasCluserConfig {
  autoScalingDiskGbEnabled: boolean;
  mongoDbMajorVersion: string;
  networkpeering: AtlasCluserNetworkPeeringConfig;
  numShards: number;
  provider: AtlasCluserProviderConfig;
  replicationFactor: number;
}
Copy code
export interface AtlasConfig {
  cluster: AtlasCluserConfig;
  cidr: string;
}

const stack = await LocalWorkspace.createOrSelectStack({
      stackName: stackName,
      projectName: ATLAS_PROJECT,
      program: async () => { 
        console.log(JSON.stringify(pulumiConfig.requireObject<AtlasConfig>('atlas')));

      },
    },
      localworkspace.setLocalWorkspaceOptions(ATLAS_PROJECT, stackName),
    );
await stack.setAllConfig({
'atlas.cidr': { value: '1'},   'atlas.cluster.autoScalingDiskGbEnabled': { value: 'true'}
})
As you could see above, I tried using setAllconfig() from Stack class.
And I am trying to set the properties for different resources creation using stack config as we used to do before using YAML stack file instead of hardcoding it inside programFun in automation API as in https://github.com/pulumi/automation-api-examples/blob/main/nodejs/inlineProgram-ts/index.ts#L15
@billowy-army-68599 - do you have anything to suggest me 🙂 ?
b

billowy-army-68599

06/21/2021, 11:08 AM
I don't have any bright ideas there I'm afraid, other than using
setAllConfig
and setting a map into it I guess
b

bumpy-agent-19616

06/21/2021, 12:10 PM
One more thing, it is only value of type string that is allowed inside Map. And I couldn't find a place to put object value.
b

bored-oyster-3147

06/21/2021, 1:27 PM
I can't speak 100% for the other SDKs - but I will say that for the .NET SDK the decision was made that for complex config scenarios we would just leave the consumer to serialize / deserialize directly to the YAML without supporting it through the Automation API. With .NET particularly it was very difficult to support complex object serialization across both YAML & JSON config scenarios without causing weird collisions of type issues between the 2 or without splitting the API. Similar decisions may have been made in the other SDKs. You shouldn't have any issues reading your structured config from within your
programFunc
as that should still function the same as before the Automation API was released, but you might have to do the writing to the config file yourself.
b

bumpy-agent-19616

06/21/2021, 1:35 PM
Thanks for the update!