digitalocean / terraform-provider-digitalocean

Terraform DigitalOcean provider
https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs
Mozilla Public License 2.0
504 stars 276 forks source link

Load Balancer not added to Project #1092

Open MauriceArikoglu opened 10 months ago

MauriceArikoglu commented 10 months ago

Load balancers are not added to projects successfully.

When I apply my terraform configuration, which includes creating several resources and then creating a project and adding all resources to the project, the load balancer is not added.

I can confirm this by showing the state for the project, which does not include the load balancer. Subsequent applies cause the project to be updated all the time, without the load balancer ever making it into the resources list of the project.

If I look at the resource overview in my digitalocean dashboard I cannot see the load balancer. In contrast, if I look at the load balancer status page, I can see it is associated with the project. So it seems this could be an issue with digitalocean itself.

resource "digitalocean_project" "project" {
    name        = var.config.name
    purpose     = "Web Application"
    environment = title(lower(var.config.env_slug))
    resources   = [
            module.L1.this.postgres.urn,
            module.L1.this.redis.urn,
            module.L1.this.kubernetes.urn,
            module.L2.this.load_balancer.urn,
            module.domains.this.backend_urn,
            module.domains.this.frontend_urn
    ]
}

yields

resource "digitalocean_project" "project" {
    created_at  = "2023-12-12T16:16:29Z"
    environment = "Staging"
    id          = "some_id"
    is_default  = false
    name        = "example"
    owner_id    = 1337
    owner_uuid  = "1337_7331"
    purpose     = "Web Application"
    resources   = [
        "do:dbaas:one_db,
        "do:dbaas:another_db",
        "do:domain:example.com",
        "do:domain:example.net",
        "do:kubernetes:a_cluster",
    ]
    updated_at  = "2023-12-12T16:16:29Z"
}

where module.L2.this.load_balancer.urn is missing from the state.

Btw: Like I said, subsequent applies try to re-add the load balancer all the time and show the correct urn. The subsequent applies always succeed as in "no error from terraform", but the load balancer is not added actually.

MauriceArikoglu commented 10 months ago
# module.L3.module.project.digitalocean_project.project will be updated in-place
  ~ resource "digitalocean_project" "project" {
        id          = "id"
        name        = "example"
      ~ resources   = [
          + "do:loadbalancer:my_lb",
            # (5 unchanged elements hidden)
        ]
        # (7 unchanged attributes hidden)
    }
MauriceArikoglu commented 9 months ago

Pinging @andrewsomething here, since you also looked at the API-related #1093 - this is blocking us, since every apply causes dependent resources to be updated or re-created unneccessarily.

andrewsomething commented 9 months ago

Hi @MauriceArikoglu,

Apologies for the delayed response. I've not been able to reproduce the issue myself. I'm able to successfully place load balancers into projects using Terraform with no unexpected issues. With a little more information, hopefully we can better understand where your issue is occurring.

If run the apply with debug logging enabled (TF_LOG=debug terraform apply), you should see an API request like POST /v2/projects/<project_uuid>/resources. If so, do you see the load balancer referenced in the request body? How about the response?

If you list the resources in the project via the API (GET /v2/projects/<project_uuid>/resources), do you see the load balancer in the response?

If I look at the resource overview in my digitalocean dashboard I cannot see the load balancer. In contrast, if I look at the load balancer status page, I can see it is associated with the project. So it seems this could be an issue with digitalocean itself.

The fact that the load balancer seems to be associated with the project but is not displayed in the project overview on your dashboard suggests to me that there is an issue that can not be resolved via Terraform itself. If you see the load balancer included in the POST request but not either of the response bodies, that would collaborate this.

If this is the case, the engineering team responsible for projects would need to do further investigation specific to the resources in your account. The best way forward would be to open a support ticket.

Thanks!