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

incalculable-engineer-92975

01/09/2020, 7:08 PM
Copy code
I'm trying to use structured config w/pulumi 1.8.1 and not getting anywhere, I keep getting invalid JSON errors: 
config:
The error I’m getting is: Error: Configuration ‘test:repos’ value ‘[object Object],[object Object]’ is not a valid JSON object
If I remove the list of items and just use a single entry that also doesn’t work
a

acoustic-florist-12628

01/09/2020, 7:35 PM
If you're using TypeScript, I believe you need to define an interface for the object in order for requireObject to know how to construct it. For example, if you define an interface myType, you then call requireObject<myType>, or if your config has a list of those objects, requireObject<myType[]>. This page gives a good example of how to get objects from the config file in various languages: https://www.pulumi.com/docs/intro/concepts/config/#structured-configuration
i

incalculable-engineer-92975

01/09/2020, 8:16 PM
Yep, tried that. No love from Pulumi.
Replacing YAML w/a JSON string DOES work though
obviously w/slightly different config syntax
a

acoustic-florist-12628

01/09/2020, 8:26 PM
hmmm, maybe it's a bug 🤔
I think the yaml format works if you have a setup like this: Pulumi.<stack>.yaml:
Copy code
config:
  aws:region: us-east-1
  configtest:app-names: |-
    foo-app
  configtest:repos:
    - name: "root"
      account: "xxxxx"
      untaggedExpireDays: 7
      mutableTags: true
      trustRelationships: [ "xxxxx", "xxxxx", "xxxxx", "xxxxx", "xxxxx" ]
    - name: "dev"
      account: "xxxxx"
      untaggedExpireDays: 14
      mutableTags: true
      trustRelationships: [ "xxxxx", "xxxxx", "xxxxx", "xxxxx", "xxxxx" ]
index.ts:
Copy code
import * as pulumi from "@pulumi/pulumi";

interface Repo {
    name: string,
    account: string,
    untaggedExpireDays: number,
    mutableTags: boolean,
    trustRelationships: string[]
}

const config = new pulumi.Config();
const objects = config.requireObject<Repo[]>("repos");

console.log(objects);
i

incalculable-engineer-92975

01/09/2020, 10:01 PM
ok, i’ll try again. thanks!
2 Views