digitalocean / terraform-provider-digitalocean

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

500 Server Error when assigning resources to project #445

Open magsoftware opened 4 years ago

magsoftware commented 4 years ago

Terraform Version

Terraform v0.12.25

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

resource "digitalocean_droplet" "bastion" {
  name      = "bastion"
  image     = "ubuntu-18-04-x64"
  region    = var.project_region
  size      = "s-1vcpu-1gb"
  vpc_uuid  = digitalocean_vpc.flexvoucher.id
  ipv6      = false
  ssh_keys  = [var.ssh_fingerprint]
  user_data = file("config/user_data.yaml")
}

resource "digitalocean_domain" "main" {
  name = var.project_domain
}

resource "digitalocean_domain" "logs" {
  name       = "logs.${var.project_domain}"
  ip_address = digitalocean_droplet.bastion.ipv4_address
}

resource "digitalocean_droplet" "elasticsearch" {
  name      = "elasticsearch"
  image     = "ubuntu-18-04-x64"
  region    = var.project_region
  size      = "s-1vcpu-2gb"
  vpc_uuid  = digitalocean_vpc.flexvoucher.id
  ipv6      = false
  ssh_keys  = [var.ssh_fingerprint]
  user_data = file("config/user_data.yaml")
}

data "digitalocean_kubernetes_versions" "this" {
  version_prefix = "1.17."
}

resource "digitalocean_kubernetes_cluster" "flexvoucher" {
  name     = var.k8s_cluster_name
  region   = var.project_region
  version  = data.digitalocean_kubernetes_versions.this.latest_version
  tags     = [var.k8s_cluster_name]
  vpc_uuid = digitalocean_vpc.flexvoucher.id

  node_pool {
    name       = var.k8s_node_pool_name
    size       = var.k8s_node_pool_size
    node_count = var.k8s_node_pool_node_count
  }
}
locals {
  project_fullname = "${var.project_name}-${var.project_environment}"
}

resource "digitalocean_project" "flexvoucher" {
  name        = local.project_fullname
  description = var.project_description
  purpose     = var.project_purpose
  environment = var.project_environment
  resources = [
    digitalocean_database_cluster.flexvoucher.urn,
    digitalocean_droplet.bastion.urn,
    digitalocean_droplet.mongo.urn,
    digitalocean_droplet.elasticsearch.urn,
    digitalocean_spaces_bucket.flexvoucher.urn,
    digitalocean_volume.mongodata.urn,
    digitalocean_domain.main.urn,
    digitalocean_domain.logs.urn
  ]
}
resource "digitalocean_droplet" "mongo" {
  name      = "mongo"
  image     = "ubuntu-18-04-x64"
  region    = var.project_region
  size      = "s-1vcpu-1gb"
  vpc_uuid  = digitalocean_vpc.flexvoucher.id
  ipv6      = false
  ssh_keys  = [var.ssh_fingerprint]
  user_data = file("config/user_data.yaml")
}

resource "digitalocean_volume" "mongodata" {
  region                   = var.project_region
  name                     = "mongodata"
  size                     = 10
  initial_filesystem_type  = "xfs"
  initial_filesystem_label = "MONGODATA"
  description              = "data volume for mongodb"
}
resource "digitalocean_volume_attachment" "mongodata" {
  droplet_id = digitalocean_droplet.mongo.id
  volume_id  = digitalocean_volume.mongodata.id
}
output "k8s_version" {
  value = data.digitalocean_kubernetes_versions.this.latest_version
}

output "k8s_cluster" {
  value = digitalocean_kubernetes_cluster.flexvoucher
}

output "rdb_cluster" {
  value = digitalocean_database_cluster.flexvoucher
}
output "rdb_connection_pool" {
  value = digitalocean_database_connection_pool.flexvoucher
}
output "spaces_bucket" {
  value = digitalocean_spaces_bucket.flexvoucher
}
output "mongo" {
  value = digitalocean_droplet.mongo
}

output "bastion" {
  value = digitalocean_droplet.bastion
}

output "elasticsearch" {
  value = digitalocean_droplet.elasticsearch
}
provider "digitalocean" {
  version = "~> 1.18.0"

  token             = var.do_token
  spaces_access_id  = var.spaces_access_key
  spaces_secret_key = var.spaces_access_secret
}

provider "kubernetes" {
  version = "~> 1.11.2"

  load_config_file = false
  host             = digitalocean_kubernetes_cluster.flexvoucher.endpoint
  token            = digitalocean_kubernetes_cluster.flexvoucher.kube_config[0].token
  cluster_ca_certificate = base64decode(
    digitalocean_kubernetes_cluster.flexvoucher.kube_config[0].cluster_ca_certificate
  )
}
resource "digitalocean_database_cluster" "flexvoucher" {
  name                 = var.rdb_cluster_name
  engine               = "pg"
  version              = var.rdb_version
  size                 = var.rdb_size
  node_count           = var.rdb_node_count
  region               = var.project_region
  private_network_uuid = digitalocean_vpc.flexvoucher.id
}

resource "digitalocean_database_firewall" "flexvoucher" {
  cluster_id = digitalocean_database_cluster.flexvoucher.id

  rule {
    type  = "ip_addr"
    value = "89.74.18.173"
  }

  rule {
    type  = "k8s"
    value = digitalocean_kubernetes_cluster.flexvoucher.id
  }
}

resource "digitalocean_database_user" "flexvoucher" {
  cluster_id = digitalocean_database_cluster.flexvoucher.id
  name       = var.rdb_database_user
}

resource "digitalocean_database_db" "flexvoucher" {
  cluster_id = digitalocean_database_cluster.flexvoucher.id
  name       = var.rdb_database_name
}

resource "digitalocean_database_connection_pool" "flexvoucher" {
  cluster_id = digitalocean_database_cluster.flexvoucher.id
  name       = var.rdb_database_connection_pool_name
  mode       = var.rdb_database_connection_pool_mode
  size       = var.rdb_database_connection_pool_size
  db_name    = var.rdb_database_name
  user       = var.rdb_database_user
}
resource "digitalocean_spaces_bucket" "flexvoucher" {
  # name   = local.project_fullname
  name   = "flexvoucher-dev"
  region = var.project_region

  cors_rule {
    allowed_headers = ["*"]
    allowed_methods = ["GET"]
    allowed_origins = ["*"]
    max_age_seconds = 3000
  }
}
variable "do_token" {}

variable "spaces_access_key" {}

variable "spaces_access_secret" {}

variable "ssh_fingerprint" {
  default = "03:e6:4f:47:d0:ba:c8:5d:d3:67:12:23:b8:4b:b1:a3"
}
variable "project_name" {
  default = "flexVOUCHER"
}

variable "project_description" {
  default = "flexVOUCHER"
}

variable "project_purpose" {
  default = "Mobile Application"
}

variable "project_environment" {
  default = "development"
}

variable "project_region" {
  default = "fra1"
}

variable "project_domain" {}

variable "vpc_name" {
  default = "flexvoucher"
}

variable "vpc_ip_range" {
  default = "10.0.0.0/24"
}

variable "k8s_cluster_name" {
  default = "flexvoucher"
}

variable "k8s_node_pool_name" {
  default = "flexvoucher-worker-pool"
}

variable "k8s_node_pool_size" {
  default = "s-1vcpu-2gb"
}

variable "k8s_node_pool_node_count" {
  default = 3
}

variable "rdb_cluster_name" {
  default = "flexvoucher"
}

variable "rdb_version" {
  default = 11
}

variable "rdb_size" {
  default = "db-s-1vcpu-1gb"
}

variable "rdb_node_count" {
  default = 1
}

variable "rdb_database_name" {
  default = "fvdb"
}

variable "rdb_database_user" {
  default = "fvuser"
}

variable "rdb_database_connection_pool_name" {
  default = "fvpool"
}

variable "rdb_database_connection_pool_mode" {
  default = "transaction"
}

variable "rdb_database_connection_pool_size" {
  default = 20
}
terraform {
  required_version = ">= 0.12"
}
resource "digitalocean_vpc" "flexvoucher" {
  name     = local.project_fullname
  ip_range = var.vpc_ip_range
  region   = var.project_region
}

Debug Output

2020-06-01T10:21:36.065+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: -----------------------------------------------------
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: 2020/06/01 10:21:36 [DEBUG] DigitalOcean API Request Details:
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: ---[ REQUEST ]---------------------------------------
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: POST /v2/projects/140ce534-42b2-4417-a64a-e4b75d63a661/resources HTTP/1.1
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Host: api.digitalocean.com
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: User-Agent: Terraform/0.12.25 godo/1.34.0
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Content-Length: 284
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Accept: application/json
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Content-Type: application/json
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Accept-Encoding: gzip
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: {
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:  "resources": [
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:   "do:droplet:194391366",
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:   "do:space:flexVOUCHER-development",
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:   "do:droplet:194391367",
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:   "do:volume:9bb586e8-a3d5-11ea-aed1-0a58ac14d008",
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:   "do:domain:dev.asdagstage.com",
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:   "do:dbaas:ee01c967-4ae8-4d6c-9d96-20f73b06a3ff",
10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:   "do:droplet:194391368",
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:   "do:domain:logs.dev.asdagstage.com"
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:  ]
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: }
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:
2020-06-01T10:21:36.066+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: -----------------------------------------------------
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: 2020/06/01 10:21:43 [DEBUG] DigitalOcean API Response Details:
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: ---[ RESPONSE ]--------------------------------------
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: HTTP/2.0 500 Internal Server Error
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Content-Length: 59
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Cf-Cache-Status: DYNAMIC
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Cf-Ray: 59c785a47ba3f2ac-WAW
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Cf-Request-Id: 031091dacb0000f2ac9797c200000001
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Content-Type: application/json
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Date: Mon, 01 Jun 2020 08:21:43 GMT
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Expect-Ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Ratelimit-Limit: 5000
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Ratelimit-Remaining: 4649
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Ratelimit-Reset: 1590996162
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Server: cloudflare
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: Set-Cookie: __cfduid=d8b84b502ba6ae916df71a761aa9514a51590999696; expires=Wed, 01-Jul-20 08:21:36 GMT; path=/; domain=.digitalocean.com; HttpOnly; SameSite=Lax
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: X-Gateway: Edge-Gateway
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: X-Request-Id: dfd39a9d-d843-4881-9f0f-2fd3ed0289aa
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: X-Response-From: service
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: {
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:  "id": "Internal Server Error",
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4:  "message": "Server Error"
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: }
2020-06-01T10:21:43.312+0200 [DEBUG] plugin.terraform-provider-digitalocean_v1.18.0_x4: -----------------------------------------------------
2020/06/01 10:21:43 [DEBUG] digitalocean_project.flexvoucher: apply errored, but we're indicating that via the Error pointer rather than returning it: Error creating project: Error assigning resources: POST https://api.digitalocean.com/v2/projects/140ce534-42b2-4417-a64a-e4b75d63a661/resources: 500 Server Error
2020/06/01 10:21:43 [ERROR] <root>: eval: *terraform.EvalApplyPost, err: Error creating project: Error assigning resources: POST https://api.digitalocean.com/v2/projects/140ce534-42b2-4417-a64a-e4b75d63a661/resources: 500 Server Error
2020/06/01 10:21:43 [ERROR] <root>: eval: *terraform.EvalSequence, err: Error creating project: Error assigning resources: POST https://api.digitalocean.com/v2/projects/140ce534-42b2-4417-a64a-e4b75d63a661/resources: 500 Server Error

Error: Error creating project: Error assigning resources: POST https://api.digitalocean.com/v2/projects/140ce534-42b2-4417-a64a-e4b75d63a661/resources: 500 Server Error

  on main.tf line 9, in resource "digitalocean_project" "flexvoucher":
   9: resource "digitalocean_project" "flexvoucher" {

2020-06-01T10:21:43.344+0200 [DEBUG] plugin: plugin process exited: path=/Users/marek/devel/flexvoucher/terraform/.terraform/plugins/darwin_amd64/terraform-provider-digitalocean_v1.18.0_x4 pid=74005
2020-06-01T10:21:43.344+0200 [DEBUG] plugin: plugin exited

Expected Behavior

Resources should be attached to the project.

Actual Behavior

Server error: 500

Steps to Reproduce

  1. terraform apply
0x62 commented 2 years ago

I hit this recently, and worked it out was because I added a droplet to the project, but that droplet had a volume attachment which wasn't added. Adding digitalocean_volume.app.urn to the resources fixed it.