hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.86k stars 9.2k forks source link

[Bug]: Endless plan updates when using a non-breaking space character in heredoc in `aws_quicksight_analysis` #33080

Open udidn opened 1 year ago

udidn commented 1 year ago

Terraform Core Version

1.5.3

AWS Provider Version

5.13.0

Affected Resource(s)

definition.sheets.text_boxes block in aws_quicksight_analysis resource

Expected Behavior

When running multiple applies in the following configuration: Using a non-breaking space character in heredoc in content field in definition.sheets.text_boxes block in aws_quicksight_analysis resource.

Terraform should detect no changes

Actual Behavior

When running multiple applies in the following configuration: Using a non-breaking space character in heredoc in content field in definition.sheets.text_boxes block in aws_quicksight_analysis resource.

Terraform always detects changes although there are no changes, and there are endless plan updates. When using exactly the same text in a double-quoted string, and running multiple applies, Terraform detects no changes.

Configuration examples can be found in the "Terraform Configuration Files" section

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

The below configuration has heredoc text in the definition.sheets.text_boxes.content field. This heredoc has a non-breaking space character in it, after the "here is a link:" part.

resource "aws_quicksight_analysis" "test" {
  analysis_id = "test"
  name        = "test"
  theme_arn   = "arn:aws:quicksight::aws:theme/CLASSIC"

  definition {
    data_set_identifiers_declarations {
      identifier   = aws_quicksight_data_set.test.name
      data_set_arn = aws_quicksight_data_set.test.arn
    }

    sheets {
      sheet_id     = random_uuid.test.id
      description  = "Some description"
      name         = "Some name"
      content_type = "INTERACTIVE"
      text_boxes {
        sheet_text_box_id = random_uuid.tets.id
        content           = <<-EOT
            <text-box>
              <inline font-size="20px">
                <b>Title</b>
              </inline>
              <br/>
              <br/>
              Some text.
              <br/>
              Some text, and here is a link: 
              <a href="https://github.com/hashicorp/terraform-provider-aws" target="_blank">link</a>
            </text-box>
        EOT
      }
      layouts {
        configuration {
          grid_layout {
            elements {
              element_id   = random_uuid.test.id
              element_type = "TEXT_BOX"
              column_index = 0
              column_span  = 36
              row_index    = 0
              row_span     = 3
            }
          }
        }
      }
    }

    analysis_defaults {
      default_new_sheet_configuration {
        interactive_layout_configuration {
          grid {
            canvas_size_options {
              screen_canvas_size_options {
                resize_option             = "FIXED"
                optimized_view_port_width = "1600px"
              }
            }
          }
        }
        sheet_content_type = "INTERACTIVE"
      }
    }
  }
}

If you apply the above configuration multiple times, Terraform will detected changes endlessly, and you'll have endless plan updates. Here's how the plan looks like after a second apply:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # module.dashboard.aws_quicksight_analysis.eks_insights will be updated in-place
  ~ resource "aws_quicksight_analysis" "test" {
        id                      = "id"
        name                    = "test"
        tags                    = {}
        # (9 unchanged attributes hidden)

      ~ definition {
          ~ sheets {
                name         = "Executive Summary"
                # (3 unchanged attributes hidden)

              ~ text_boxes {
                  ~ content           = <<-EOT
                        <text-box>
                          <inline font-size="20px">
                            <b>Title</b>
                          </inline>
                          <br/>
                          <br/>
                          Some text.
                          <br/>
                          Some text, and here is a link:
                          <a href="https://github.com/hashicorp/terraform-provider-aws" target="_blank">link</a>
                        </text-box>
                    EOT
                    # (1 unchanged attribute hidden)
                }

                # (1 unchanged block hidden)
            }

            # (97 unchanged blocks hidden)
        }

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value:

If you replace the above configuration file, with a double-quoted text in the definition.sheets.text_boxes.content field (and keep the non-breaking space), Terraform will detect no changes after a second apply. Here's the same configuration as above, only with a double-quoted string in the definition.sheets.text_boxes.content field:

resource "aws_quicksight_analysis" "test" {
  analysis_id = "test"
  name        = "test"
  theme_arn   = "arn:aws:quicksight::aws:theme/CLASSIC"

  definition {
    data_set_identifiers_declarations {
      identifier   = aws_quicksight_data_set.test.name
      data_set_arn = aws_quicksight_data_set.test.arn
    }

    sheets {
      sheet_id     = random_uuid.test.id
      description  = "Some description"
      name         = "Some name"
      content_type = "INTERACTIVE"
      text_boxes {
        sheet_text_box_id = random_uuid.tets.id
        content           = "<text-box>\n  <inline font-size=\"20px\">\n    <b>Title</b>\n  </inline>\n  <br/>\n  <br/>\n  Some text.\n  <br/>\n  Some text, and here is a link: \n  <a href=\"https://github.com/hashicorp/terraform-provider-aws\" target=\"_blank\">link</a>\n</text-box>"
      }
      layouts {
        configuration {
          grid_layout {
            elements {
              element_id   = random_uuid.test.id
              element_type = "TEXT_BOX"
              column_index = 0
              column_span  = 36
              row_index    = 0
              row_span     = 3
            }
          }
        }
      }
    }

    analysis_defaults {
      default_new_sheet_configuration {
        interactive_layout_configuration {
          grid {
            canvas_size_options {
              screen_canvas_size_options {
                resize_option             = "FIXED"
                optimized_view_port_width = "1600px"
              }
            }
          }
        }
        sheet_content_type = "INTERACTIVE"
      }
    }
  }
}

If you apply the above configuration multiple times, Terraform won't detect any changes, as expected. Here's how the plan looks like after a second apply:

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Steps to Reproduce

Run terraform apply multiple times without making any changes, using the first configuration example provided in the "Terraform Configuration Files" section. You'll see Terraform detects changes although no changes were made.

Then, run terraform apply multiple times with the second configuration example provided in the "Terraform Configuration Files" section. You'll see that Terraform detects no changes, as expected

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

udidn commented 1 year ago

It looks like the issue recreates regardless of non-breaking space character (it was just the first time I used heredoc in aws_quicksight_analysis, for some reason I thought the issue is specific to this character). I removed the non-breaking space character and the issue recreates the same way: With heredoc, there are endless plans, and with double-quoted string, Terraform detects no changes, as expected.

This is recreated also in definition.sheets.visuals.kpi_visual.title.format_text.rich_text in aws_quicksight_analysis