Thread
#general
    w

    white-rain-67342

    3 months ago
    Hello everyone! I am working with Pulumi do deploy a stack on Kubernetes. I would like to include the name of one my backend service in the nginx.conf of the frontend via a config-map. Is there a better way rather than put a string in the config and run a replace on the string? The issue is that
    api_url
    is an Output type and the replace function expects a string. The following is my snippet:
    with open('./nginx.conf', 'r') as file:
            config = file.read()
            config = config.replace("{{API_URL}}", api_url.apply(lambda foo: foo))
            print(config)
    
        config_map = ConfigMap(
            'nginx-config',
            metadata=ObjectMetaArgs(labels=labels),
            data={'default.conf': config}
            )
    l

    little-cartoon-10569

    3 months ago
    That won't work, since that code runs at the time Pulumi is generating the declarative state, but the API_URL value isn't available until after the infrastructure is deployed.
    Instead, you have to defer running that code until API_URL is available. It is available inside the call to
    apply()
    .
    I don't know Python, can you make something like this work?
    config_map = ConfigMap(
            'nginx-config',
            metadata=ObjectMetaArgs(labels=labels),
            data={
              'default.conf': api_url.apply(lambda url:
                with open('./nginx.conf', 'r') as file:
                  config = file.read()
                  config = config.replace("{{API_URL}}", url))
                  return config
            })
    w

    white-rain-67342

    3 months ago
    Thanks for the help!
    l

    little-cartoon-10569

    3 months ago
    Does the explanation / example make since? Is the difference in how apply() is being used understandable? Happy to answer more questions to clarify, this is a core concept that will make everything easier once you grok it.