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

    sparse-state-34229

    06/11/2020, 7:08 PM
    there’s a lot more in https://github.com/pulumi/examples
  • c

    chilly-hairdresser-56259

    06/11/2020, 7:15 PM
    @sparse-state-34229 I have been looking at many examples and documentation and haven't figured out how to properly manipulate the strings. For one thing it works for another item such as this if I copy and paste with a few minor changes it fails.
  • s

    sparse-state-34229

    06/11/2020, 7:15 PM
    yeah, it’s kind of annoying like that 😞
  • c

    chilly-hairdresser-56259

    06/11/2020, 7:16 PM
    So if Output and Apply do not work does that mean its simply not possible to reference it?
  • s

    sparse-state-34229

    06/11/2020, 7:17 PM
    they do work
    👍 1
  • s

    sparse-state-34229

    06/11/2020, 7:17 PM
    it’s likely just a matter of using them the right way for this use case
  • c

    chilly-hairdresser-56259

    06/11/2020, 7:17 PM
    gotcha.
  • s

    sparse-state-34229

    06/11/2020, 7:19 PM
    how are you trying to use
    service[0].name
    ?
  • s

    sparse-state-34229

    06/11/2020, 7:19 PM
    eg as a function argument?
  • c

    chilly-hairdresser-56259

    06/11/2020, 7:21 PM
    service[0].name
    would be the output from the ecs service. I need to get string format of the output for
    resource_id
    in the appautoscaling. Format
    service/ecs cluster name/ecs service name
    . Yes Function argument
  • s

    sparse-state-34229

    06/11/2020, 7:27 PM
    so eg
    do_something(service_name=service[0].name)
    yeah?
  • s

    sparse-state-34229

    06/11/2020, 7:28 PM
    if so, try calling
    do_something()
    within the apply lambda
  • c

    chilly-hairdresser-56259

    06/11/2020, 7:29 PM
    appautoscalingTarget = aws.appautoscaling.Target(
            resource_name= "%s-%s-%s-asg-target" % (p_env, tasks[x]['application'], tasks[x]['service']),
            min_capacity= tasks[x]['minimumCapacity'],
            max_capacity= tasks[x]['maximumCapacity'],
            resource_id= f"service/{service[0].name}/{ecs_cluster.name}",
            scalable_dimension= "ecs:service:DesiredCount",
            service_namespace= "ecs"
        )
  • c

    chilly-hairdresser-56259

    06/11/2020, 7:30 PM
    x
    being the iterator of my list[dict{}] of ecs tasks configs
  • s

    sparse-state-34229

    06/11/2020, 7:32 PM
    what do you do with
    appautoscalingTarget
    ?
  • c

    chilly-hairdresser-56259

    06/11/2020, 7:35 PM
    appautoscalingTarget
    I use create the scaling policies. So I then reference like such in the scaling policies:
    appautoscalingTarget.scalable_dimension
    for the resource
    aws.appautoscaling.Policy
  • s

    sparse-state-34229

    06/11/2020, 7:36 PM
    okay
  • s

    sparse-state-34229

    06/11/2020, 7:37 PM
    you might need to move the output massaging up to
    aws.appautoscaling.Policy
    c
    • 2
    • 3
  • g

    gentle-diamond-70147

    06/11/2020, 7:40 PM
    What is
    service
    here?
    c
    • 2
    • 2
  • c

    chilly-hairdresser-56259

    06/11/2020, 7:40 PM
    service
    = ecs Service.
    service
    creates multiple resources and returns two objects. ECS Service and taskDefinition
  • g

    gentle-diamond-70147

    06/11/2020, 7:47 PM
    I believe this should work for you:
    appautoscalingTarget = aws.appautoscaling.Target(
            resource_name= "my-target",
            min_capacity= 1,
            max_capacity= 2,
            resource_id= Output.all(service[0].name, ecs_cluster.name).apply(lambda args: f"service/{args[0]}/{args[1]}"),
            scalable_dimension= "ecs:service:DesiredCount",
            service_namespace= "ecs"
        )
    c
    • 2
    • 1
  • g

    gentle-diamond-70147

    06/11/2020, 7:48 PM
    I changed the other inputs to test in my code, so only copy the
    resource_id
    input line :)
  • g

    gentle-diamond-70147

    06/11/2020, 7:52 PM
    As Scott said, you can't print the output of apply, but you can print within the apply. e.g.
    Output.all(service[0].name, ecs_cluster.name).apply(lambda args: print(f"service/{args[0]}/{args[1]}"))
  • g

    gentle-diamond-70147

    06/11/2020, 7:52 PM
    .apply()
    always returns an Output
  • c

    chilly-hairdresser-56259

    06/11/2020, 7:54 PM
    Ok, so somewhere I must have messed up when prevously trying to get this to work with
    Output.all().apply()
    I am going to try to figure out why.
  • c

    chilly-hairdresser-56259

    06/11/2020, 7:55 PM
    When referencing
    output.all().apply()
    does that implicitly "wait" for the previous resource output, making it like a
    depends_on
  • c

    chilly-hairdresser-56259

    06/11/2020, 7:55 PM
    ?
  • g

    gentle-diamond-70147

    06/11/2020, 7:57 PM
    Effectively, yes. Pulumi will wait for the outputs passed into
    .all()
    to be come "real" before proceeding with the lambda.
    👍 1
  • g

    gentle-diamond-70147

    06/11/2020, 8:02 PM
    Oh... I think you need to reverse the arguments to
    .all()
    . It looks like AWS expects
    service/<cluster-name>/<service-name>
    .
  • g

    gentle-diamond-70147

    06/11/2020, 8:02 PM
    Output.all(ecs_cluster.name, service[0].name).apply(lambda args: f"service/{args[0]}/{args[1]}")
Powered by Linen
Title
g

gentle-diamond-70147

06/11/2020, 8:02 PM
Output.all(ecs_cluster.name, service[0].name).apply(lambda args: f"service/{args[0]}/{args[1]}")
View count: 1