hashicorp / terraform-cdk

Define infrastructure resources using programming constructs and provision them using HashiCorp Terraform
https://www.terraform.io/cdktf
Mozilla Public License 2.0
4.78k stars 441 forks source link

Provider `cdktf_cdktf_provider_newrelic` is unable to create `NrqlAlertCondition` using an `AlertPolicy` defined in the same cdktf run #3646

Open saleemjaffer opened 2 weeks ago

saleemjaffer commented 2 weeks ago

Expected Behavior

I am trying to create an NrqlAlertCondition. This requires a policy_id parameter.

Before creation of NrqlAlertCondition, I am creating an AlertPolicy. I should be able to typecast the id of the alertPolicy in to a number using Token.as_number and be able to pass this as the policy_id parameter of NrqlAlertCondition

Actual Behavior

policy_id of NrqlAlertCondition accepts an int or float. The policy.id that we get from AlertPolicy is a string like ${TfToken[TOKEN.244]}. When I typecast this to a number using Token.as_number and pass it as the policy_id parameter of NrqlAlertCondition, I get the following error:

⠙  Processing
[2024-06-13T15:56:13.186] [ERROR] default - ╷
│ Error: Attribute must be a whole number, got -1.8881545897087635e+289
│ 
│   with newrelic_nrql_alert_condition.oaac_test_dev_test-group_23730378,
│   on cdk.tf.json line 5908, in resource.newrelic_nrql_alert_condition.oaac_test_dev_test-group_23730378:
│ 5908:         "policy_id": -1.8881545897087635e+289
│ 
dev  ╷
     │ Error: Attribute must be a whole number, got -1.8881545897087635e+289
     │ 
     │   with newrelic_nrql_alert_condition.oaac_test_dev_test-group_23730378 (oaac_test_dev_test-group_23730378),
     │   on cdk.tf.json line 5908, in resource.newrelic_nrql_alert_condition.oaac_test_dev_test-group_23730378 (oaac_test_dev_test-group_23730378):
     │ 5908:         "policy_id": -1.8881545897087635e+289
     │ 
     ╵

The policy_id, is the Id of the alert policy, that I create in the same terraform run. I am able to successfully create the alert policies on NewRelic as well. The problem is, when I try to pass it the the alert_condittion, I get this error.

Steps to Reproduce

  1. Create a NewRelic alert policy.
  2. Cast the id of policy created earlier, using Token.as_number and try passing it the policy_id parameter while creating a NrqlAlertCondition

Versions

language: python
cdktf-cli: 0.20.7
node: v20.14.0
cdktf: 0.20.7
constructs: 10.3.0
jsii: 1.98.0
terraform: 1.7.5
arch: arm64
os: darwin 23.3.0
python: Python 3.9.7
pip: pip 21.2.3 from /Users/saleem.majeeth/.pyenv/versions/3.9.7/envs/playground-3.9.7/lib/python3.9/site-packages/pip (python 3.9)
pipenv: pipenv, version 2023.12.1
providers
cdktf-cdktf-provider-newrelic (PREBUILT)
        terraform provider version: 3.37.1 
        prebuilt provider version: 12.8.1
        cdktf version: ^0.20.0

Providers

newrelic/newrelic │ 3.37.1 │ ^0.20.0 │ │ cdktf-cdktf-provider-newrelic │ 12.8.1

Gist

No response

Possible Solutions

No response

Workarounds

No response

Anything Else?

Related to https://github.com/hashicorp/terraform-cdk/issues/3642

References

No response

Help Wanted

Community Note

saleemjaffer commented 2 weeks ago

@DanielMSchmidt do you have some idea about this?