Hi there. How can I use the Config-values as an in...
# general
r
Hi there. How can I use the Config-values as an input to a templating call to an external process? I am using python and I need to create a butane config, write it to a file and run the butane transpiler on it and then read it in again. I am getting
Copy code
Calling __str__ on an Output[T] is not supported.
    To get the value of an Output[T] as an Output[str] consider:
    1. o.apply(lambda v: f"prefix{v}suffix")
    See <https://www.pulumi.com/docs/concepts/inputs-outputs> for more details.
    This function may throw in a future version of Pulumi.
I've tried
Copy code
registry_username = config.require_secret("registryUsername")
print(registry_username.apply(lambda v: f"{v}"))
Is it necessary to write a CustomResource for that?
Copy code
def read_config():
    with open("scraper.yaml", "r") as template:
        yml = template.read()
        yml = string.Template(yml)
        yml = yml.substitute({"pg_host": pg_host,
                              "pg_user": pg_user,
                              "pg_admin_password": pg_admin_password,
                              "pg_database": pg_database,
                              "ssh_keys": ssh_key,
                              "ssh_port": ssh_port,
                              "host": subdomain + "." + domain,
                              "username": username,
                              "image_name": image_name,
                              "image_tag": image_tag,
                              "metabase_tag": metabase_tag,
                              "traefik_tag": traefik_tag,
                              "registry_server": registry_server,
                              "registry_username": registry_username.apply(lambda v: v),
                              "registry_password": registry_password})
        with open("scraper.bu", "w") as butane:
            butane.write(yml)
            subprocess.run(["cat", "scraper.bu", "|", "butane", "-o", "scraper.ig", "--files-dir", "."],
                           shell=True,
                           capture_output=True)
    with open("scraper.ig", "r") as ignition:
        cfg = ignition.read()
        return base64.b64encode(cfg)
This is basically what I need to run to get my ignition data for a flatcar vm
most of the variables are coming from config
it does not even work when I parameterize the read_config function and call it from within the virtualmachine-resource. Any idea why? I mean I get that Pululmi lazily evaluates that. Still I don't get why config is lazily evaluated and I don't get why I can not call the function from within a virtualmachine-resource. The output must have been evaled by then.
s
Instead of
subprocess.run
, try using the Pulumi
command
provider. It might help with understanding dependencies and resolving Outputs before executing the command.
c
Also use
pulumi.log
+ pulumi.interpolate if you want debug logs or whatever in your output.
r
Thank you! trying that...
Can someone tell me why Config is Output and not available from start of process? I don't get it...
c
Can you please show your config code? Those are generally not pulumi.Output types.
r
Copy code
import pulumi
config = pulumi.Config()

base_name = "yobst-scraper"
location = config.get("location", "germanywestcentral")

username = "yobst"
ssh_key = config.get("sshKey")
ssh_port = 22
flatcar_version = "3602.2.3"

domain = config.get("domain", "germanywestcentral.cloudapp.azure.com")
subdomain = config.get("subdomain", "yobst-scraper")

pg_host = config.get("pgHost")
pg_user = "yobst"
pg_password = config.require_secret("pgPassword")
pg_admin_password = config.require_secret("pgAdminPassword")
pg_database = "scraper"
pg_sslmode = config.get_bool("pgSslMode", False)
pg_sslrootcert = config.require_secret("pgSslRootCert")

registry_server = "ghcr.io"
registry_username = config.require_secret("registryUsername")
registry_password = config.require_secret("registryPassword")

image_name = registry_server + "/yobst/" + base_name
image_tag = "0.1.09c1a77"
traefik_tag = "v3.0"
metabase_tag = "v0.48.1"
c
hard to say precisely as I don't use Python for this, but in TS land
config.get()
is a String
r
hmm, thank you for the answer
c
that looks like the correct usage of pulumi.Config generally though
r
pulumi.error(str(type(registry_username)))
returns
error: <class 'pulumi.output.Output'>
ok, secret is Output but config.get returns a string
tried with
ssh_key
from above
get_secret
again returns
Output
Is secret in TS returned as Output? @cuddly-computer-18851
c
Good question, we don't use pulumi secrets. Just checking the type def and yes they are.
Which kind of makes sense, as depending on the secrets provider it has to do ... things to get a value.
r
right, that makes sense. Thanks
may I ask why you're not using secrets and where you're getting your secrets from if not from pulumi secrets?
c
AWS SSM Parameters for secrets
They can be directly referenced by ECS and EKS, and dynamically created where needed for sharing between serices
r
will have a look