opsgenie / terraform-provider-opsgenie

Terraform OpsGenie provider
https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs
Mozilla Public License 2.0
103 stars 137 forks source link

Terraform OpsGenie Provider: opsgenie_integration_action bug with the description field #328

Closed michael-elumeev closed 1 year ago

michael-elumeev commented 2 years ago

Hi there,

It seems that I've found a bug in the Terraform OpsGenie Provider, to be specific an "opsgenie_integration_action" resource. Here is the link to its documentation (https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs/resources/integration_action). In our environment, we use OpsGenie for all possible alerting mechanisms and quite often we supply quite wordy descriptions for our integration actions (such as create, delete, and so on). The problem comes with a multi-line description field, I simply cannot get it pass through the terraform plan command correctly. It always shows the differences between the state and the actual resource. In my coding, we use the Heredoc version of multi-line values for terraform, and even after an apply command, once some other parameters change, the difference related to the description field appears out of nowhere.

Terraform Version

1.2.8

Affected Resource(s)

opsgenie_integration_actions, description field

Terraform Configuration Files

The providers.tf has nothing special, in fact, I used the latest available version of the Opsgenie Provider. The configuration of the integration action: https://gist.github.com/michael-elumeev/d070556bcf8b98d5ffd7fd5ed96e8654

Debug Output

Please provide a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist. https://gist.github.com/michael-elumeev/9851e3b09e0dbb15c17dc16627902b62

Expected Behavior

What should have happened? The description field, in case it contains no changes, shall not be marked as the one, containing differences.

Actual Behavior

What actually happened? Even after applying the file and changing a different parameter (different from the description field), we encounter the same behavior during the terraform plan command. Output marks again the description field as the one containing the difference.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Import the resource (opsgenie integration action) from the OpsGenie using a TF file and import command
  2. Terraform plan (with -target option to specify only your file)
  3. terraform apply (with -target option to specify only your file)
  4. terraform plan (with -target option to specify only your file) - now will show that the configuration is up to date.
  5. Change something like the severity of alarm in the GUI, reflect the changes in your TF code
  6. terraform plan with -target option to specify only your file) - it will again show the differences in the description field.

Important Factoids

Everything is pretty standard, except for, as it was mentioned earlier, we have indeed, slightly longer descriptions than shown in the terraform examples.

aditya232 commented 1 year ago

Hi Michael

We were able to replicate the issue with this resource configuration and the root cause seems to be Terraform adding an extra trailing newline character to heredoc strings(a similar issue can be seen with the Azure provider as well). As suggested on the terraform discussion forum, you can use the chomp function when using heredoc strings. For instance, using the below snippet with the chomp function(Terraform version 1.3.6) should fix the issue.

create {
    name               = "Create Alert 4"
    alert_actions      = []
    append_attachments = true 
    description        = chomp(<<-EOT
        Line1
        Line2
        Line3
    EOT
    )
...
...
}    
arjunrajpal commented 1 year ago

We have updated the opsgenie terraform provider documentation to show how to manage an opsgenie_integration_action resource of create action type with multiline description using chomp function.