【问题标题】:How to add entries to Pulumi output for environment variables?如何为环境变量添加条目到 Pulumi 输出?
【发布时间】:2021-01-30 16:25:01
【问题描述】:

我已经为 Pulumi 中的环境变量创建了一个 Output,就像 https://github.com/pulumi/examples/blob/master/aws-ts-airflow/index.ts#L61 一样,但我需要为我正在启动的容器之一在这些环境变量中添加一个条目。

我想在声明类似于https://github.com/pulumi/examples/blob/master/aws-ts-airflow/index.ts#L79-L85的容器时做一些事情

            "webserver": {
                image: awsx.ecs.Image.fromPath("webserver", "./airflow-container"),
                portMappings: [airflowControllerListener],
                environment: environment + {name: "ANOTHER_ENV", value: "value"},
                command: [ "webserver" ],
                memory: 128,
            },

我尝试过使用pulumi.all (pulumi.all([environment, {name: "FLASK_APP", value: "server/__init.py"}])) 和environment.apply,但不知道如何联系Output

这可能吗?如果有,怎么做?

【问题讨论】:

    标签: pulumi


    【解决方案1】:

    你应该可以

    const newEnvironment = environment.apply(env =>
        env.concat({ name: "ANOTHER_ENV", value: "value"}));
    
    // ...
    
    "webserver": {
        image: awsx.ecs.Image.fromPath("webserver", "./airflow-container"),
        portMappings: [airflowControllerListener],
        environment: newEnvironment,
        command: [ "webserver" ],
        memory: 128,
    },
    

    【讨论】:

    • 啊!我认为实际上我们需要使用env.concat 而不是env.push,但这是有道理的。谢谢!
    • 确实!修正了答案。
    猜你喜欢
    • 2016-09-25
    • 2020-10-07
    • 1970-01-01
    • 2023-01-30
    • 1970-01-01
    • 2018-06-16
    • 2019-06-06
    • 1970-01-01
    • 2019-03-13
    相关资源
    最近更新 更多