https://pulumi.com logo
#general
Title
# general
b

breezy-piano-61073

09/02/2021, 9:50 PM
Copy code
alert_policy=newrelic.AlertPolicy("DAI-SHARED-DEV-OPERATIONS-WORKFLOW-CREATED", 
    incident_preference="PER_POLICY",
    name="DAI-SHARED-DEV-OPERATIONS-WORKFLOW-CREATED")

print("alert_policy.id=" + alert_policy.id)
anyone have any idea why this code snippit gives the following error?
Copy code
TypeError: can only concatenate str (not "Output") to str
    error: an unhandled error occurred: Program exited with non-zero exit code: 1
The AlertPolicy is created, but I cannot access the alert_policy.id in python.
b

bored-table-20691

09/02/2021, 9:51 PM
alert_policy.id()
is an output type, it’s value is not known at program execution time (unless you
apply
it). You would typically register it as an output.
b

breezy-piano-61073

09/03/2021, 1:03 AM
Itay, thanks so much for your response. If I can’t get this value at runtime, how do I create other resources that are dependent on it in the same stack? When you say apply, do you mean something like:
Copy code
print("alert_policy.id=" + alert_policy.id.apply(lambda id: id) )
And when you say resister output, do you mean something like this:
Copy code
pulumi.export('policyid',  alert_policy.id)
b

bored-table-20691

09/03/2021, 1:49 AM
So you have a couple of options. If something needs that ID explicitly it’ll typically take an input and you can use that. If you need to compute a value based on this, you can use apply to compute the value (and that’ll also be an output, so not resolved in normal execution), or I believe Python has a type of string formatting for values as well that’ll also create an output. I know Go has one.
Where are you trying to use this value? Is it in another Pulumi resource?
And yes, I meant as an exported value like you showed above.
b

breezy-piano-61073

09/03/2021, 2:22 AM
Basically, yes, I’m trying to use this ID in the creation of another resource later in the code, something like this:
Copy code
resource1 = x(...)

resource2 = y(resource1.id, ...)
It seems like a very basic thing to do, and I read in the doc that when you provide the output of one resource as an input to another, Pulumi should work the dependencies out and the value should be available when it is needed. But that doesn’t seem to be the case here. I did try the apply code I wrote above, but it returns the same error, the input to resource2 (which is an output of resource1) still does not have a value.
I really hate not being able to figure this out, I’m going to have to pass on adopting Pulumi at all if I can’t figure a way to make this work, and I really like Pulumi a lot more than Terraform. 😉
b

bored-table-20691

09/03/2021, 3:13 AM
Can you be more explicit about what’s the other resource you want to create? What’s the code you have that’s not working?
b

breezy-piano-61073

09/03/2021, 3:29 AM
sure, here is the actual code. I’m using the New Relic library to create a monitor that pings a website every 5 minutes or so.
Copy code
import pulumi
import pulumi_newrelic as newrelic
import pprint

alert_policy=newrelic.AlertPolicy("DAI-SHARED-DEV-OPERATIONS-WORKFLOW-CREATED", 
    incident_preference="PER_POLICY",
    name="DAI-SHARED-DEV-OPERATIONS-WORKFLOW-CREATED")

############################################################################
# simple ping/check for healthcheck and text check for correctness 
#
healthcheck_synthetics_monitor = newrelic.synthetics.Monitor(
    "api.us.digital.cloud healthchecks (script created)",
    frequency=5,
    locations=[
        "AWS_US_EAST_1",
        "AWS_US_WEST_1",
        "AWS_EU_WEST_1"
    ],
    status="ENABLED",
    type="SIMPLE",
    uri="<https://api.us.digitalai.cloud/core/monitoring/healthcheck>",
    validation_string='{"response": {"healthy": true,'
)

multiLocationAlertCondition1 = newrelic.synthetics.MultiLocationAlertCondition(
    "Alert Condition 1 (script created)",
    enabled=True,
    entities = [healthcheck_synthetics_monitor.id],
    policy_id = alert_policy.id, ##### PROBLEM IS HERE #######################################
    violation_time_limit_seconds = 3600,
    critical = newrelic.synthetics.MultiLocationAlertConditionCriticalArgs(threshold = 3),
    warning = newrelic.synthetics.MultiLocationAlertConditionWarningArgs(threshold=1)
)
When run, I get this:
Copy code
➜ pulumi up -y
Previewing update (dai-shared-dev-us-west-2):
     Type                                                Name                                                Plan       Info
     pulumi:pulumi:Stack                                 dai-palumi-dai-shared-dev-us-west-2                            
 +   ├─ newrelic:synthetics:Monitor                      api.us.digital.cloud healthchecks (script created)  create     
     └─ newrelic:synthetics:MultiLocationAlertCondition  Alert Condition 1 (script created)                             1 error
 
Diagnostics:
  newrelic:synthetics:MultiLocationAlertCondition (Alert Condition 1 (script created)):
    error: newrelic:synthetics/multiLocationAlertCondition:MultiLocationAlertCondition resource 'Alert Condition 1 (script created)' has a problem: Attribute must be a whole number, got 1510434. Examine values at 'MultiLocationAlertCondition.PolicyId'.
Funny thing is, Pulumi is complaining “Attribute must be a whole number, got 1510434”, and 1510434 is clearly a whole number if I remember my math correctly. And I did check NewRelic, the created AlertPolicy does have the value of 1510434.
b

bored-table-20691

09/03/2021, 3:55 AM
Can you try something like this (on my phone so this is pseudo code):
Copy code
policyid = alertpolicy.id.apply(lambda myid: int(myid))
And then try and pass policyid to the alert you’re creating
b

breezy-piano-61073

09/07/2021, 1:01 PM
Holy cow, that worked! Thanks so much for the help!
b

bored-table-20691

09/07/2021, 2:41 PM
This kind of seems like a bug. You should open a ticket with the info.