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
  • w

    white-balloon-205

    08/28/2020, 5:51 PM
    Cross-posting for the #python folks here as well. https://pulumi-community.slack.com/archives/CB36DSVSA/p1598635165030400
  • s

    steep-alligator-79173

    08/28/2020, 7:43 PM
    Hi I’m trying to conver pulumi output object to string that can be assign to variable and used as a parameter in curl request. Im following documentation https://www.pulumi.com/docs/intro/concepts/programming-model/#outputs
    repo_id = gitlab_repo.id.apply(lambda repo_id: repo_id)
  • s

    steep-alligator-79173

    08/28/2020, 7:44 PM
    when I try to print this variable I all the time getting
    <pulumi.output.Output object at 0x10acc5a00>
  • s

    steep-alligator-79173

    08/28/2020, 7:44 PM
    how I can get raw string that can be used in curl request
  • s

    steep-alligator-79173

    08/28/2020, 7:44 PM
    I want to add gitlab environment
  • s

    steep-alligator-79173

    08/28/2020, 7:44 PM
    And I need repo id for a request
  • s

    steep-alligator-79173

    08/28/2020, 7:44 PM
    any hints
  • s

    steep-alligator-79173

    08/28/2020, 7:44 PM
    ?
  • g

    green-school-95910

    08/28/2020, 7:44 PM
    Lambda converts from Output to Output. If your need to do something with the actual value you need to do that inside the apply
  • s

    steep-alligator-79173

    08/28/2020, 7:45 PM
    hmm ?
  • s

    steep-alligator-79173

    08/28/2020, 7:45 PM
    how 🙂
  • g

    green-school-95910

    08/28/2020, 7:45 PM
    gilab_repo.id.apply(function_that_receives_the_id)
  • s

    steep-alligator-79173

    08/28/2020, 7:45 PM
    i create resource :
    gitlab_repo = pulumi_gitlab.Project(
            f"{repo}",
            name=repo,
            namespace_id=qtx_arc_group.id
        )
  • s

    steep-alligator-79173

    08/28/2020, 7:45 PM
    and now I need repo id in raw string
  • s

    steep-alligator-79173

    08/28/2020, 7:45 PM
    not as a output
  • g

    green-school-95910

    08/28/2020, 7:46 PM
    Isolated the logic that need the id and pass it to the apply, as I showed above
  • s

    steep-alligator-79173

    08/28/2020, 7:49 PM
    repo_id = gitlab_repo.id.apply(lambda repo_id: f"dupa+{repo_id}")
        pulumi.export("DUPA", repo_id)
  • s

    steep-alligator-79173

    08/28/2020, 7:49 PM
    Outputs:
      + DUPA: "dupa+20804159"
  • s

    steep-alligator-79173

    08/28/2020, 7:49 PM
    results are as expected
  • s

    steep-alligator-79173

    08/28/2020, 7:50 PM
    but I don’t understand part with
    Isolated the logic that need the id and pass it to the apply, as I showed above
  • s

    steep-alligator-79173

    08/28/2020, 7:50 PM
    can you explain this in more details. ?
  • s

    steep-alligator-79173

    08/28/2020, 7:51 PM
    as i understand in side apply i should execute function that need this raw id
  • s

    steep-alligator-79173

    08/28/2020, 7:51 PM
    ?
  • g

    green-school-95910

    08/28/2020, 8:05 PM
    Yes, the code inside the apply is executed during the deployment, when that information (the id) is guaranteed to be available The code outside is executed before the deployment, it is the code that define the graph of resources. When that code is running, the id is not known, only the reference to its future value (the Output object) is available.
  • g

    green-school-95910

    08/28/2020, 8:10 PM
    So any code that needs the actual value of a resource should go inside the apply. Normally you only need to transform it to something else
    repo_id = gitlab_repo.id.apply(lambda repo_id: f"dupa+{repo_id}")
    repo_id
    here is an
    Output
    object representing a value that, during the deployment, will be available and equal to the result of the lambda function The
    pulumi.export("DUPA", repo_id)
    don't export anything. It adds to the plan that after the deployment the values that was made available on that Output should be exported.
  • g

    green-school-95910

    08/28/2020, 8:11 PM
    You can just treat it as if it exported things for most cases, but if you need more control you also need to understand this difference
  • s

    steep-alligator-79173

    08/28/2020, 8:19 PM
    I get to the point:
    repo_id = gitlab_repo.id.apply(lambda repo_id:
          print(f"<https://gitlab.com/api/v4/projects/{repo_id}/environments>")
          
    )
  • s

    steep-alligator-79173

    08/28/2020, 8:20 PM
    output looks ok
  • s

    steep-alligator-79173

    08/28/2020, 8:20 PM
    now I will try to execute requests inside with paramteres
  • s

    steep-alligator-79173

    08/28/2020, 8:21 PM
    repo_id = gitlab_repo.id.apply(lambda repo_id:
          print(f"<https://gitlab.com/api/v4/projects/{repo_id}/environments>")
          requests.get("<https://gitlab.com>")  
        )
Powered by Linen
Title
s

steep-alligator-79173

08/28/2020, 8:21 PM
repo_id = gitlab_repo.id.apply(lambda repo_id:
      print(f"<https://gitlab.com/api/v4/projects/{repo_id}/environments>")
      requests.get("<https://gitlab.com>")  
    )
View count: 1