https://pulumi.com logo
Join the conversationJoin Slack
Channels
announcements
automation-api
aws
azure
blog-posts
built-with-pulumi
cloudengineering
cloudengineering-support
content-share
contribex
contribute
docs
dotnet
finops
general
getting-started
gitlab
golang
google-cloud
hackathon-03-19-2020
hacktoberfest
install
java
jobs
kubernetes
learn-pulumi-events
linen
localstack
multi-language-hackathon
office-hours
oracle-cloud-infrastructure
plugin-framework
pulumi-cdk
pulumi-crosscode
pulumi-deployments
pulumi-kubernetes-operator
pulumi-service
pulumiverse
python
registry
status
testingtesting123
testingtesting321
typescript
welcome
workshops
yaml
Powered by Linen
python
  • l

    lemon-night-89661

    05/24/2020, 9:37 PM
    I am struggling with the same
    Output
    object, and I have a feeling of moving in circles 🙂
    api_service = Service(
        opts=ResourceOptions(depends_on=[api_deployment]),
        resource_name="api",
        spec={
            "type": "ClusterIP",
            "selector": {"app": "api-deployment"},
            "ports": [port_map(api_port)],
        }
    )
    # Name is something like: "api-vvf3g61k"
    # Tried:
    srv_name1 = api_service.metadata.name
    srv_name2 = Output.all([api_service.metadata]).apply(lambda x: x.name)
    srv_name3 = Output.all([api_service.metadata.name]).apply(lambda x: x)
    srv_name4 = Output.all([api_service.status]).apply(lambda x: str(x))
    
    print("srv_name1:" + pformat(srv_name1))
    print("srv_name2:" + pformat(srv_name2))
    print("srv_name3:" + pformat(srv_name3))
    print("srv_name4:" + pformat(srv_name4))
    I want to use that name in an env var to configure another deployment …
  • s

    sparse-state-34229

    05/24/2020, 9:38 PM
    you can’t print
  • l

    lemon-night-89661

    05/24/2020, 9:38 PM
    Diagnostics:
      pulumi:pulumi:Stack (central-infra-central-danlaptop-docker-desktop):
        srv_name1:<pulumi.output.Output object at 0x10e3e5710>
        srv_name2:<pulumi.output.Output object at 0x10e3f1390>
        srv_name3:<pulumi.output.Output object at 0x10e3f1d10>
        srv_name4:<pulumi.output.Output object at 0x10e3fa990>
  • s

    sparse-state-34229

    05/24/2020, 9:38 PM
    also use f strings
  • l

    lemon-night-89661

    05/24/2020, 9:38 PM
    It will get caught by the “Diagnosstics”
  • l

    lemon-night-89661

    05/24/2020, 9:40 PM
    Thanks @sparse-state-34229. Is it only the printing that trips me?
  • l

    lemon-night-89661

    05/24/2020, 9:40 PM
    Or is there something else?
  • s

    sparse-state-34229

    05/24/2020, 9:40 PM
    maybe. how are you trying to use it? specifically with “I want to use that name in an env var”
  • l

    lemon-night-89661

    05/24/2020, 9:40 PM
    There’s another service that will connect to the internal name of this service.
  • l

    lemon-night-89661

    05/24/2020, 9:41 PM
    And I need to configure that other internal’s services environment with something like
    API_ENDPOINT=<http://api-vvf3g61k:8080>
  • s

    sparse-state-34229

    05/24/2020, 9:42 PM
    okay, cool…so that is the “what” you want to do, now “HOW” are you planning to do it?
  • l

    lemon-night-89661

    05/24/2020, 9:42 PM
    If I set
    metadata.name
    to
    api
    for example, I will be able to use ``API_ENDPOINT=http://api:8080` and this works.
  • l

    lemon-night-89661

    05/24/2020, 9:42 PM
    Now I’d rather not set it fixed
  • s

    sparse-state-34229

    05/24/2020, 9:42 PM
    code / pseudocode is always good 🙂
  • l

    lemon-night-89661

    05/24/2020, 9:43 PM
    But let pulumi autogenerate a name for the service
  • l

    lemon-night-89661

    05/24/2020, 9:43 PM
    Maybe my strategy is not pulumi-style 🙂
  • s

    sparse-state-34229

    05/24/2020, 9:44 PM
    srv_name1 = api_service.metadata.name
    what are you doing with
    srv_name1
    after this?
  • l

    lemon-night-89661

    05/24/2020, 9:46 PM
    serv2_deployment = Deployment(
    ...
         "spec": {
    ...
             "containers": [
                 {
    ...
                     "env": [
                         {"name": "API_HOST", "value": "<http://%s>" % srv_name1},
                     ],
    ...
  • l

    lemon-night-89661

    05/24/2020, 9:46 PM
    Use it in another deployment
  • l

    lemon-night-89661

    05/24/2020, 9:47 PM
    Does it make sense?
  • s

    sparse-state-34229

    05/24/2020, 9:47 PM
    and that isn’t working for you, correct?
  • l

    lemon-night-89661

    05/24/2020, 9:47 PM
    Correct
  • l

    lemon-night-89661

    05/24/2020, 9:48 PM
    I get something like
    http://<pulumi.output.Output object at 0x10e3fe850>
    🙂
  • s

    sparse-state-34229

    05/24/2020, 9:48 PM
    try something like
    serv2_deployment = Output.all([srv_name1]).apply(lambda s: Deployment("""json here""")) # replace srv_name1 with s[0][0]
  • l

    lemon-night-89661

    05/24/2020, 9:49 PM
    ok. let me try this.
  • s

    sparse-state-34229

    05/24/2020, 9:50 PM
    at that point you may be able to reference
    api_service.metadata.name
    unless you use
    srv_name1
    elsewhere
  • s

    sparse-state-34229

    05/24/2020, 9:51 PM
    https://gist.github.com/ohlol/330bc4fd062700dde7d8fd15cf3e18ab
  • s

    sparse-state-34229

    05/24/2020, 9:51 PM
    that is one way I do this
  • s

    sparse-state-34229

    05/24/2020, 9:52 PM
    self.vpc
    is a
    pulumi_aws.ec2.Vpc
    object
  • s

    sparse-state-34229

    05/24/2020, 9:53 PM
    if I passed
    self.vpc.id
    directly the jinja template output would look like your URL
Powered by Linen
Title
s

sparse-state-34229

05/24/2020, 9:53 PM
if I passed
self.vpc.id
directly the jinja template output would look like your URL
View count: 1