Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cw scrape job: fix modifyplan when creating a new resource #1804

Conversation

tristanburgess
Copy link

@tristanburgess tristanburgess commented Sep 13, 2024

We implemented ModifyPlan on the AWS CW scrape job resources in #1789. This was done in order to only make disabled_reason computed when the enabled state is being set to false. This function apparently runs even on resource creation, however, so an error was being thrown because the state was nil.

This PR handles the case that the state is nil, again depending on the planned enabled state.

enabled=true

  + resource "grafana_cloud_provider_aws_cloudwatch_scrape_job" "sandbox-ec2" {
      + aws_account_resource_id = (known after apply)
      + enabled                 = true
      + export_tags             = true
      + id                      = (known after apply)
      + name                    = "tf-managed-scrape-job"
      + regions                 = [
          + "us-east-1",
          + "us-east-2",
        ]
      + stack_id                = "1"
        # (1 unchanged attribute hidden)

      + service {
          + name                    = "AWS/EC2"
          + scrape_interval_seconds = 300
          + tags_to_add_to_metrics  = [
              + "eks:cluster-name",
            ]

          + metric {
              + name       = "CPUUtilization"
              + statistics = [
                  + "Average",
                ]
            }
          + metric {
              + name       = "StatusCheckFailed"
              + statistics = [
                  + "Maximum",
                ]
            }
        }
    }

enabled=false

  + resource "grafana_cloud_provider_aws_cloudwatch_scrape_job" "sandbox-ec2" {
      + aws_account_resource_id = (known after apply)
      + disabled_reason         = (known after apply)
      + enabled                 = false
      + export_tags             = true
      + id                      = (known after apply)
      + name                    = "tf-managed-scrape-job"
      + regions                 = [
          + "us-east-1",
          + "us-east-2",
        ]
      + stack_id                = "1"

      + service {
          + name                    = "AWS/EC2"
          + scrape_interval_seconds = 300
          + tags_to_add_to_metrics  = [
              + "eks:cluster-name",
            ]

          + metric {
              + name       = "CPUUtilization"
              + statistics = [
                  + "Average",
                ]
            }
          + metric {
              + name       = "StatusCheckFailed"
              + statistics = [
                  + "Maximum",
                ]
            }
        }
    }

@tristanburgess tristanburgess requested review from a team as code owners September 13, 2024 19:12
Copy link

In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically.
To do so, a Grafana Labs employee must trigger the cloud acceptance tests workflow manually.

Copy link

@thepalbi thepalbi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

@tristanburgess
Copy link
Author

tristanburgess commented Sep 13, 2024

also fixed an extra edge case when the provider isn't configured with the right params but you try to create a resource anyways:

│ Error: The Grafana Provider is missing a configuration for the Cloud Provider API.
│
│   with grafana_cloud_provider_aws_account.test,
│   on main.tf line 27, in resource "grafana_cloud_provider_aws_account" "test":
│   27: resource "grafana_cloud_provider_aws_account" "test" {
│
│ Please ensure that cloud_provider_url and cloud_provider_access_token are set in the provider configuration.

@tristanburgess tristanburgess merged commit c79d7eb into tf-cloud-provider-aws-app Sep 13, 2024
25 of 26 checks passed
@tristanburgess tristanburgess deleted the tristanburgess/fix-cw-scrape-modifyplan branch September 13, 2024 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants