0
votes

I have a moderately complex terraform setup with a module directory containing a main.tf, variables.tf and input.tf and environments directory containing foo.tf, variables.tf and vars.tf

I can successfully run terraform apply and everything succeeds. But, if I immediately run terraform apply again it makes changes.

The changes it keeps making are to resources in the module...resources that get attributes from variables in the environments tf files. I'm creating an MQ broker and a dashboard to monitor it.

In the environments directory

top.tf

module "broker" {
  source = "modules/broker"
  dashboard = "...."
}

In the modules directory

input.tf

variable "dashboard" {
}

amazonmq.tf

resource "aws_cloudwatch_dashboard" "mydash" {
  dashboard_name = "foo"
  dashboard_body = "${dashboard}"
}

Every time I run terraform apply it says it needs to change the dashboard. Any hints on what I'm doing wrong? (I've tried running with TF_LOG=DEBUG but I can't see anything that says why a change is needed). Thanks in advance.

1
Any chance you can work on making your example code an minimal reproducible example so we can reproduce your issue? As is your example code doesn't work at all and I doubt even fixing it would show the same issue you are seeing which makes this impossible for anyone to help you with.ydaetskcoR
I'd venture to say that your JSON file for the dashboard is being reformatted or reorganized by AWS, and when you run apply - you're trying to do it with your version again. I've run into this with ECS Task Definitions before, where AWS would re-order my environment variables, so I would have to change my definition to match however they ordered them.TJ Biddle
Could you please provide more information like, terrafrom version, providers version and plan/apply output which is changing. It happens when you have something in code which keeps changing like logs/versions(in Elastic Beanstalk case etc). Your plan out may help people a lot here to help you.Khalid Waseem

1 Answers

1
votes

This seems to be an issue with the terraform provider code itself. The dashboard_body property should have the computed flag attached to it, to allow you to provide it but ignore any incoming changes from aws.

I've opened up an issue on the github page. You'll find it here: https://github.com/terraform-providers/terraform-provider-aws/issues/5729