acoustic-continent-29968
01/18/2022, 8:16 AM[]
or with a dict {}
.
Or if there's a smart way to convert pulumi config to a dictionary, without iterating over the keys and decyphering the bag name, because we have infinite number of lines that look like:
name = config.require('name')
vpc_id = config.require('vpc_id')
tags = config.require('tags')
(obviously this can be done with dict comprehension but not what I'm looking for):
values = ['name', 'vpc_id', 'tags']
my_dict = { value: config.require(value) for value in values }
I'm looking for a more generic approach, what happens if a new parameter is introduced?
2. I'm looking to create layers of configuration in which I can explicitly say that a specific config should be appended or overriden.
e.g: tags should be appended,
configuration layer 1: physical site
configuration layer 2: environment
configuration layer 3: micro serviceprehistoric-activity-61023
01/18/2022, 9:09 AMpulumi up
?acoustic-continent-29968
01/18/2022, 9:33 AMnums
?
When you perform this line:
config = pulumi.Config()
data = config.require_object("data")
print("Nums:", data.get("nums"))
data.get("nums")
returns None
, obviously I can use data.get("nums", [])
to specify this manually, but that means I am aware that nums is a list, and therefore I know the falsy default value is []
. But what happens when the type is not known? Or we decide to change nums into a dict?prehistoric-activity-61023
01/18/2022, 9:53 AMwhat happens when the type is not knownI’d joke that you’re already f**ed 😄 . Even in python (that is a language without static typing) you should at least have some assumptions regarding data types in order to work on them. If
nums
was a list and you decided to change to into a dict, you’re most probably break your code. Check my suggestion regarding pydantic models usage:
from typing import Dict, List, Mapping, Optional
from pydantic import BaseModel
class MyConfig(BaseModel):
nums_with_default_empty: List[int] = []
optional_nums: Optional[List[int]]
required_nums: List[int]
...
pulumi_conf = pulumi.Config().get_object("config") or {}
config = MyConfig.parse_obj(pulumi_conf)
I want to be able to merge config filesAs far as I know, each stack can only have one, single config file (loaded with
pulumi.Config()
). You can overcome that limitation but implementing some logic outside of this config (pulumi does not prevent you from using your custom files or even getting your config from the internet - not that I’d advice doing that in IaC project).
If you want to make some modular projects and divide things into layers, I’d look into creating separate projects and bind them using Stack References (https://www.pulumi.com/docs/intro/concepts/stack/#stackreferences). One of my setup is divided into 3 different pulumi projects:
• gcp-project-bootstrap (creates a GCP project, VPC inside it and some high-level IAM rules)
• gcp-project (creates GKE, CloudSQL, MemoryStore, etc.)
• k8s-addons (manages helm charts within GKE and secrets/configmaps)acoustic-continent-29968
01/18/2022, 10:03 AM