aptible / terraform-provider-aptible

The official Terraform provider for Aptible Deploy
https://registry.terraform.io/providers/aptible/aptible/latest
10 stars 13 forks source link

Add Metric Drains #78

Closed joshraker closed 2 years ago

joshraker commented 2 years ago

Adding conditional validations for the various drain types increased the scope of the PR a little bit but it should be beneficial for future resources.

joshraker commented 2 years ago

https://app.shortcut.com/aptible/story/5182/add-metric-drains-to-terraform

shortcut-integration[bot] commented 2 years ago

This pull request has been linked to Shortcut Story #5182: Add Metric Drains to Terraform.

joshraker commented 2 years ago

Integration tests passed

❯ STACK=josh
❯ APTIBLE_API_ROOT_URL="https://api-${STACK}.aptible-sandbox.com" APTIBLE_AUTH_ROOT_URL="https://auth-${STACK}.aptible-sandbox.com" APTIBLE_ACCESS_TOKEN="$(cat "${HOME}/.aptible/tokens.json" | jq ".\"https://auth-${STACK}.aptible-sandbox.com\"" -r)" APTIBLE_ENVIRONMENT_ID=1 make testacc TESTARGS='-run TestAccResourceMetricDrain'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -count 1 -parallel 20 -run TestAccResourceMetricDrain -timeout 120m
?       github.com/aptible/terraform-provider-aptible   [no test files]
=== RUN   TestAccResourceMetricDrain_influxdb_database
...
--- PASS: TestAccResourceMetricDrain_influxdb_database (188.26s)
=== RUN   TestAccResourceMetricDrain_influxdb
...
--- PASS: TestAccResourceMetricDrain_influxdb (27.71s)
=== RUN   TestAccResourceMetricDrain_datadog
...
--- PASS: TestAccResourceMetricDrain_datadog (27.82s)
PASS
ok      github.com/aptible/terraform-provider-aptible/aptible   244.245s
joshraker commented 2 years ago

Still passing

❯ APTIBLE_API_ROOT_URL="https://api-${STACK}.aptible-sandbox.com" APTIBLE_AUTH_ROOT_URL="https://auth-${STACK}.aptible-sandbox.com" APTIBLE_ACCESS_TOKEN="$(cat "${HOME}/.aptible/tokens.json" | jq ".\"https://auth-${STACK}.aptible-sandbox.com\"" -r)" APTIBLE_ENVIRONMENT_ID=1 make testacc TESTARGS='-run TestAccResourceMetricDrain'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -count 1 -parallel 20 -run TestAccResourceMetricDrain -timeout 120m
?       github.com/aptible/terraform-provider-aptible   [no test files]
=== RUN   TestAccResourceMetricDrain_influxdb_database
...
--- PASS: TestAccResourceMetricDrain_influxdb_database (198.28s)
=== RUN   TestAccResourceMetricDrain_influxdb
...
--- PASS: TestAccResourceMetricDrain_influxdb (27.92s)
=== RUN   TestAccResourceMetricDrain_datadog
...
--- PASS: TestAccResourceMetricDrain_datadog (27.43s)
PASS
ok      github.com/aptible/terraform-provider-aptible/aptible   254.073s
joshraker commented 2 years ago

Integration tests still passing:

❯ STACK=josh; APTIBLE_API_ROOT_URL="https://api-${STACK}.aptible-sandbox.com" APTIBLE_AUTH_ROOT_URL="https://auth-${STACK}.aptible-sandbox.com" APTIBLE_ACCESS_TOKEN="$(cat "${HOME}/.aptible/tokens.json" | jq ".\"https://auth-${STACK}.aptible-sandbox.com\"" -r)" APTIBLE_ENVIRONMENT_ID=1 make testacc TESTARGS='-run TestAccResourceMetricDrain'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -count 1 -parallel 20 -run TestAccResourceMetricDrain -timeout 120m
?       github.com/aptible/terraform-provider-aptible   [no test files]
=== RUN   TestAccResourceMetricDrain_validation
--- PASS: TestAccResourceMetricDrain_validation (0.55s)
=== RUN   TestAccResourceMetricDrain_influxdb_database_validation
--- PASS: TestAccResourceMetricDrain_influxdb_database_validation (0.64s)
=== RUN   TestAccResourceMetricDrain_influxdb_database
...
--- PASS: TestAccResourceMetricDrain_influxdb_database (238.75s)
=== RUN   TestAccResourceMetricDrain_influxdb_validation
--- PASS: TestAccResourceMetricDrain_influxdb_validation (0.54s)
=== RUN   TestAccResourceMetricDrain_influxdb
...
--- PASS: TestAccResourceMetricDrain_influxdb (27.90s)
=== RUN   TestAccResourceMetricDrain_datadog_validation
--- PASS: TestAccResourceMetricDrain_datadog_validation (0.30s)
=== RUN   TestAccResourceMetricDrain_datadog
...
--- PASS: TestAccResourceMetricDrain_datadog (27.47s)
PASS
ok      github.com/aptible/terraform-provider-aptible/aptible   296.504s
joshraker commented 2 years ago

Here's what the custom errors look like:

main.tf

resource "aptible_metric_drain" "test" {
  env_id     = data.aptible_environment.test.env_id
  handle     = "tf-drain"
  drain_type = "influxdb_database"
  api_key    = "test_api_key"
  series_url = "https://series"
  url        = "https://localhost"
  username   = "influx"
  password   = "pass"
  database   = "metrics"
}

Output

❯ tf plan
data.aptible_environment.test: Reading...
data.aptible_environment.test: Read complete after 1s [id=handle]
╷
│ Error: 7 errors occurred:
│       * database_id is required when drain_type = "influxdb_database"
│       * url is not allowed when drain_type = "influxdb_database"
│       * username is not allowed when drain_type = "influxdb_database"
│       * password is not allowed when drain_type = "influxdb_database"
│       * database is not allowed when drain_type = "influxdb_database"
│       * api_key is not allowed when drain_type = "influxdb_database"
│       * series_url is not allowed when drain_type = "influxdb_database"
│ 
│ 
│ 
│   with aptible_metric_drain.test,
│   on main.tf line 45, in resource "aptible_metric_drain" "test":
│   45: resource "aptible_metric_drain" "test" {
│ 
╵
DArtagan commented 2 years ago

So much joy in my heart: following the announcement of log drains last month, I sat down today to add management of those into our Terraform stack. Following that I thought, "wow, I hope they do metric drains soon too." And that's when I found this ticket, "wow, I hope they cut a new release soon." And then this: image 😂 🎉 🚀