Another question, this time regarding tagging of r...
# typescript
s
Another question, this time regarding tagging of resources. I load a set of default tags for all my resources from the config like this:
Copy code
const config = pulumi.Config();
const defaultTags = config.requireObject<{ [key: string]: string }>("defaultTags");
These defaultTags look like:
Copy code
config:
  aws:region: eu-central-1
  my-application:defaultTags:
    - team: application-team
    - environment: dev
    - cost-center: "123456"
Now, when I create a resource I would like to merge these defaultTags with the resource specifig tags like Name or others
Copy code
const route53Zone = new aws.route53.Zone("applicationZone", {
  name: fqdn,
  tags: {
    ...defaultTags,
    Name: fqdn,
  }
});
But this one fails with an error like:
Copy code
'' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[team:application-team]'.
Any ideas on how to fix this?
I gave the pulumi.com/ai a try and it came with a conclusion to create a custom aws provider where one can define a set of default tags and use this provider for all resources.
This would merge the resource tags with those from the aws provider
This looks a bit spooky
b
@sticky-bear-14421 this looks like you’re marshalling the array of tags into the wrong type?
it should end up being
Copy code
map[team]application-team
for example, if I do
export const defaultTags = config.requireObject<{ [key: string]: string }>("defaultTags");
I get
Copy code
Outputs:
  + defaultTags: [
  +     [0]: {
          + team: "application-team"
        }
  +     [1]: {
          + environment: "dev"
        }
  +     [2]: {
          + cost-center: "123456"
        }
    ]
s
Hi @billowy-army-68599 I get the same output, but the route53 block still fails
Copy code
...
tags: {
   ...defaulttags,
   Name: fqdn,
}
The complete error message is:
Copy code
Diagnostics:
  aws:route53:Zone (storeapplication):
    error: aws:route53/zone:Zone resource 'applicationZone' has a problem: '' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[team:application-team]'. Examine values at 'Zone.Tags["0"]'.
Exporting the defautlTags gives me the same result like you got:
Copy code
Outputs:
  + defaultTags: [
  +     [0]: {
          + team: "application-team"
        }
  +     [1]: {
          + environment: "dev"
        }
  +     [2]: {
          + cost-center: 123456
        }
    ]
s
i think this can be fixed by just changing your defaultTags to just be an object/map, not an array
Copy code
config:
  aws:region: eu-central-1
  my-application:defaultTags:
    team: application-team
    environment: dev
    cost-center: "123456"
s
Thanks for the suggestion, will give it a try and report.