sparse-intern-71089
01/18/2022, 8:16 AMprehistoric-activity-61023
01/18/2022, 9:09 AMprehistoric-activity-61023
01/18/2022, 9:12 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?acoustic-continent-29968
01/18/2022, 9:34 AMprehistoric-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)
prehistoric-activity-61023
01/18/2022, 9:55 AMprehistoric-activity-61023
01/18/2022, 9:55 AMprehistoric-activity-61023
01/18/2022, 9:59 AMI 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 AMacoustic-continent-29968
01/18/2022, 10:05 AMacoustic-continent-29968
01/18/2022, 10:06 AMacoustic-continent-29968
01/18/2022, 10:06 AM