terraform-provider-newrelic icon indicating copy to clipboard operation
terraform-provider-newrelic copied to clipboard

policy_id should be string not int

Open jaecktec opened this issue 2 years ago • 1 comments

Please include the following with your bug report

  • [ ] Your New Relic provider configuration (sensitive details redacted)
  • [x] A list of affected resources and/or data sources
  • [x] The configuration of the resources and/or data sources related to the bug report (i.e. from the list mentioned above)
  • [x] Description of the current behavior (the bug)
  • [x] Description of the expected behavior
  • [ ] Any related log output

Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

Affected Resource(s)

Please list the resources as a list, for example:

  • newrelic_alert_policy
  • newrelic_alert_condition

Terraform Configuration

Hello. I am using terraform-cdk, and it is auto-generating the types. However for

const newrelicAlertPolicy = new newrelic.AlertPolicy(
  this,
  stage,
  {
    incidentPreference: "PER_CONDITION",
    name: `${stage}`,
  }
);
new newrelic.SyntheticsAlertCondition(
  this,
  `${stage}_${endpoint.name}_alert_condition`,
  {
    monitorId: newrelicSyntheticsMonitor.id,
    name: endpoint.name,
    // @ts-ignore
    policyId: newrelicAlertPolicy.id,
  }
);

the policyId is of type number, while the policy.id is of type string.

Actual Behavior

should not require // @ts-ignore policyId should match the alertPolicy.id type

Expected Behavior

types do not match -> // @ts-ignore is required

Steps to Reproduce

  1. generate cdktf project
  2. add newrelic provider
  3. add sample code
  4. remove // @ts-ignore

Reference

https://github.com/newrelic/terraform-provider-newrelic/blob/6fc1373ad30136bd84691c6a2bc7a25e9ced3bbc/newrelic/resource_newrelic_alert_condition.go#L90

jaecktec avatar Aug 23 '22 13:08 jaecktec

@jaecktec Thank you for reporting this issue. We'll look into making the policy ID types match to avoid this in the future.

mbazhlekova avatar Aug 25 '22 16:08 mbazhlekova

Hi @jaecktec, Is this issue still relevant?

NSSPKrishna avatar Nov 30 '22 11:11 NSSPKrishna

Yes. I just checked with cdktf and nr provider 3.7.1 and it still has that incompatibility.

jaecktec avatar Nov 30 '22 11:11 jaecktec

Sure we will look into it. For CDK please try using tonumber as a workaround for now.

NSSPKrishna avatar Nov 30 '22 11:11 NSSPKrishna

There isn't much to do on terraform side, hence closing this issue. Please open a new issue if you encounter any other issues or questions.

ChandraIragavarapu avatar Mar 10 '23 11:03 ChandraIragavarapu

There is something to do from terraform side... Adjusting the type.. Should I create a PR?

jaecktec avatar Mar 10 '23 14:03 jaecktec

Hi @jaecktec, the newrelic_synthetics_alert_condition resource is a legacy resource and will likely not be receiving any updates. It calls an old legacy API which has been deprecated. Our documentation recommends switching to use newrelic_nrql_alert_condition. Hope this helps 🙂

sanderblue avatar Mar 21 '23 15:03 sanderblue

Hi @jaecktec, the newrelic_synthetics_alert_condition resource is a legacy resource and will likely not be receiving any updates. It calls an old legacy API which has been deprecated. Our documentation recommends switching to use newrelic_nrql_alert_condition. Hope this helps 🙂

this does not help. the newrelic_nrql_alert_condition resource also defines policy_id as number type, which doesn't match with the policy.id (which is of string type)

https://github.com/newrelic/terraform-provider-newrelic/blob/6fc1373ad30136bd84691c6a2bc7a25e9ced3bbc/newrelic/resource_newrelic_nrql_alert_condition.go#L106

When used with CDKTF in TypeScript, we have to cast the value like this

const alertPolicy = new AlertPolicy(this, 'alert-policy', {
  name: 'some-policy',
  incidentPreference: 'PER_POLICY',
});

new NrqlAlertCondition(this, 'error-rate', {
  policyId: alertPolicy.id as unknown as number,
  ...
});

jackie-linz avatar May 01 '24 05:05 jackie-linz

@jackie-linz this would not work since alertPolicy.id is a tokenized string.

@jaecktec I am still facing this issue. Were you able to find a solution?

saleemjaffer avatar Jun 04 '24 13:06 saleemjaffer

@saleemjaffer I kept the //@ts-ignore

jaecktec avatar Jun 05 '24 11:06 jaecktec