terraform-provider-digitalocean icon indicating copy to clipboard operation
terraform-provider-digitalocean copied to clipboard

Unexpected changes for digitalocean_app

Open razum90 opened this issue 7 months ago • 0 comments

Bug Report

I am getting unexpected changes after creating digitalocean_app.

This is my tf config:

resource "digitalocean_app" "project" {
  for_each = var.environments

  spec {
    name   = "project-${each.key}"
    region = var.region

    domain {
      name = var.environments[each.key].domain
    }

    alert {
      rule = "DEPLOYMENT_FAILED"
    }

    service {
      name               = "api"
      instance_count     = 1
      instance_size_slug = "basic-xxs"

      image {
        registry_type = "DOCR"
        repository    = "api"
        tag           = "0.0.1"
        deploy_on_push {
          enabled = var.environments[each.key].web.deploy_on_push
        }
      }

      http_port = 8080

      alert {
        value    = 75
        operator = "GREATER_THAN"
        window   = "TEN_MINUTES"
        rule     = "CPU_UTILIZATION"
      }

      env {
        key   = "QUARKUS_DATASOURCE_JDBC_URL"
        value = "jdbc:postgresql://${digitalocean_database_cluster.db-cluster[each.key].host}:${digitalocean_database_cluster.db-cluster[each.key].port}/${digitalocean_database_db.db[each.key].name}"
      }

      env {
        key   = "QUARKUS_DATASOURCE_USERNAME"
        value = digitalocean_database_cluster.db-cluster[each.key].user
      }

      env {
        key   = "QUARKUS_DATASOURCE_PASSWORD"
        value = digitalocean_database_cluster.db-cluster[each.key].password
        type  = "SECRET"
      }

      env {
        key   = "API_KEY"
        value = var.api_key
        type  = "SECRET"
      }
    }

    static_site {
      name          = "web"
      build_command = "npm run build"

      source_dir = "web/"

      github {
        branch         = "main"
        deploy_on_push = true
        repo           = "username/project"
      }
    }

    database {
      name         = digitalocean_database_db.db[each.key].name
      db_name      = digitalocean_database_db.db[each.key].name
      cluster_name = digitalocean_database_cluster.db-cluster[each.key].name
      production   = var.environments[each.key].production_db
    }

    ingress {
      rule {
        component {
          name = "api"
        }
        match {
          path {
            prefix = "/api"
          }
        }
      }

      rule {
        component {
          name = "web"
        }

        match {
          path {
            prefix = "/"
          }
        }
      }
    }
  }
}

After applying it and doing unrelated updates to my terraform config, I get this:

  # digitalocean_app.project["prod"] will be updated in-place
  ~ resource "digitalocean_app" "project" {
        id                   = "xxx"
        # (6 unchanged attributes hidden)

      ~ spec {
          ~ features = [
              - "buildpack-stack=ubuntu-22",
            ]
            name     = "project-prod"
          ~ region   = "fra" -> "fra1"
            # (1 unchanged attribute hidden)

          ~ service {
                name               = "api"
                # (4 unchanged attributes hidden)

              - env {
                  # At least one attribute in this block is (or was) sensitive,
                  # so its contents will not be displayed.
                }
              - env {
                  # At least one attribute in this block is (or was) sensitive,
                  # so its contents will not be displayed.
                }
              - env {
                  # At least one attribute in this block is (or was) sensitive,
                  # so its contents will not be displayed.
                }
              - env {
                  # At least one attribute in this block is (or was) sensitive,
                  # so its contents will not be displayed.
                }
              + env {
                  # At least one attribute in this block is (or was) sensitive,
                  # so its contents will not be displayed.
                }
              + env {
                  # At least one attribute in this block is (or was) sensitive,
                  # so its contents will not be displayed.
                }
              + env {
                  # At least one attribute in this block is (or was) sensitive,
                  # so its contents will not be displayed.
                }
              + env {
                  # At least one attribute in this block is (or was) sensitive,
                  # so its contents will not be displayed.
                }

                # (2 unchanged blocks hidden)
            }

            # (5 unchanged blocks hidden)
        }
    }

  1. The region is all of a sudden fra which does not exist in your docs.
  2. It's trying to recreate my environment variables for some reason.

If I try to change to fra the db cluster creation complains:

╷
│ Error: Error creating database cluster: POST https://api.digitalocean.com/v2/databases: 412 (request "8bf6fc7c-aacc-4654-b29e-d3206e8651cd") At this time, we're unable to create a cluster of that size in that region
│ 
│   with digitalocean_database_cluster.db-cluster["dev"],
│   on digitalocean.tf line 52, in resource "digitalocean_database_cluster" "db-cluster":
│   52: resource "digitalocean_database_cluster" "db-cluster" {
│ 
╵

Affected Resource(s)

  • digitalocean_app

Might be more, have not investigated.

Terraform version 1.6.3

terraform {
  required_providers {
    digitalocean = {
      source  = "digitalocean/digitalocean"
      version = "~> 2.0"
    }
  }
}

razum90 avatar Nov 11 '23 14:11 razum90