spotinst / terraform-provider-spotinst

Terraform Spotinst provider.
https://registry.terraform.io/providers/spotinst/spotinst/latest/docs
Mozilla Public License 2.0
63 stars 56 forks source link

rootVolumeSize must not exist simultaneously with [blockDeviceMappings] #512

Closed msvechla closed 8 months ago

msvechla commented 8 months ago

Terraform Version

v1.5.7

Affected Resource(s)

Terraform Configuration Files

abbreviated for readability:

resource "spotinst_ocean_aws" "ocean_eks" {
  name                        = module.eks_cluster.eks_cluster_name
  controller_id               = module.eks_cluster.eks_cluster_name
  region                      = var.region
  subnet_ids                  = local.active_eks_private_subnets
  image_id                    = var.eks_ami
  spot_percentage             = 100
  key_name                    = var.eks_worker_keypair_name
  min_size                    = 0
  max_size                    = local.spotinst_max_size
  desired_capacity            = 5

  # set to null, as we configure block_device_mappings below
  # simply omitting this value yields the same result
  root_volume_size            = null

  block_device_mappings {
    device_name = "/dev/xvda"
    ebs {
      delete_on_termination = "true"
      volume_size           = var.spotinst_root_volume_size
      volume_type           = "gp3"
    }
  }
}

Debug Output

---[ REQUEST ]---------------------------------------
PUT /ocean/aws/k8s/cluster/xyz?accountId=act-xyz HTTP/1.1
Host: api.spotinst.io
User-Agent: HashiCorp/1.0 Terraform/1.5.7 (+https://www.terraform.io/) Terraform Plugin SDK/2.5.0 Terraform Provider Spotinst/v2-1.165.0 spotinst-sdk-go/1.337.0 (go1.16.15; darwin; arm64)
Content-Length: 275
Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip

{"cluster":{"capacity":{},"compute":{"instanceTypes":{},"launchSpecification":{"blockDeviceMappings":[{"deviceName":"/dev/xvda","ebs":{"deleteOnTermination":true,"encrypted":false,"volumeSize":128,"volumeType":"gp3"}}],"rootVolumeSize":null}},"scheduling":{},"strategy":{}}}

-----------------------------------------------------: timestamp=2024-03-25T11:04:13.640+0100
2024-03-25T11:04:14.257+0100 [DEBUG] provider.terraform-provider-spotinst_v1.165.0: [spotinst-sdk-go] SPOTINST: Response "PUT https://api.spotinst.io/ocean/aws/k8s/cluster/o-xyz?accountId=act-xyz" details:
---[ RESPONSE ]----------------------------------------
HTTP/2.0 400 Bad Request
Content-Length: 510
Access-Control-Allow-Headers: Origin,Accept,Content-Type,Authorization,X-CSRF-Token
Access-Control-Allow-Methods: GET,POST,DELETE,PUT
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=utf-8
Date: Mon, 25 Mar 2024 10:04:14 GMT
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Ratelimit-Limit: 300
X-Ratelimit-Remaining: 299
X-Request-Id: 91ef11fd-13ae-4378-a5f5-5a4aaea26893
X-Response-Time: 39ms

{
  "request": {
    "id": "91ef11fd-13ae-4378-a5f5-5a4aaea26893",
    "url": "/ocean/aws/k8s/cluster/o-2c8a88a4",
    "method": "PUT",
    "timestamp": "2024-03-25T10:04:14.237Z"
  },
  "response": {
    "status": {
      "code": 400,
      "message": "Bad Request"
    },
    "errors": [
      {
        "code": "ValidationError",
        "message": "\"rootVolumeSize\" must not exist simultaneously with [blockDeviceMappings]",
        "field": "body:cluster,compute,launchSpecification"
      }
    ]
  }
}

Expected Behavior

We should not get an error about conflicting rootVolumeSize and blockDeviceMappings when rootVolumeSize is not specified or set to null

Actual Behavior

   "message": "\"rootVolumeSize\" must not exist simultaneously with [blockDeviceMappings]",

Steps to Reproduce

See config above. You can see in the trace log I added above, that rootVolumeSize is part of the body of the HTTP request with the value null , which probably causes the spot api to evaluate it and throw the error

{"cluster":{"capacity":{},"compute":{"instanceTypes":{},"launchSpecification":{"blockDeviceMappings":[{"deviceName":"/dev/xvda","ebs":{"deleteOnTermination":true,"encrypted":false,"volumeSize":128,"volumeType":"gp3"}}],"rootVolumeSize":null}},"scheduling":{},"strategy":{}}}

Potential root cause: https://github.com/spotinst/spotinst-sdk-go/issues/287

Community Note

chandra1-n commented 8 months ago

@msvechla Thanks for bringing up the issue here, as of now it is the behavior of the API where-in we cannot have root_volume_size and bdm updated together, but if you need to remove the root_volume_size and add bdm block then you can achieve through 2 separate updates - 1 removing root_volume_size and the second to add bdm block. Closing this ticket as it is not terraform provider issue.