terraform apply failing to create machine

A terraform apply is failing with

 Error: Failed to create machine
│
│   with fly_machine.cookbook_staging_server,
│   on main.tf line 42, in resource "fly_machine" "cookbook_staging_server":
│   42: resource "fly_machine" "cookbook_staging_server" {
│
│ Create request failed: 400 Bad Request, &{ID: Name: State: Region: InstanceID: PrivateIP: Config:{Env:map[] Init:{Exec:[] Entrypoint:[] Cmd:[]} Image:
│ Metadata:<nil> Restart:{Policy:} Services:[] Mounts:[] Guest:{CPUKind: Cpus:0 MemoryMb:0}} ImageRef:{Registry: Repository: Tag: Digest: Labels:{}}
│ CreatedAt:0001-01-01 00:00:00 +0000 UTC}

As mentioned in Fly Machines Terraform feedback - #13 by DAlperin, I tried setting DEBUG=1 TF_LOG=debug, which produces output containing my fly auth token :stuck_out_tongue_closed_eyes:, but the tail end is:

fly_machine.cookbook_staging_server: Creating...
2023-01-27T20:10:45.145-0800 [INFO]  Starting apply for fly_machine.cookbook_staging_server
2023-01-27T20:10:45.146-0800 [DEBUG] skipping FixUpBlockAttrs
2023-01-27T20:10:45.146-0800 [DEBUG] fly_machine.cookbook_staging_server: applying the planned Create change
2023-01-27T20:10:45.148-0800 [DEBUG] provider.terraform-provider-fly_v0.0.20: Calling provider defined ResourceType NewResource: @caller=github.com/hashicorp/terraform-plugin-framework@v0.11.1/internal/fwserver/server_createresource.go:44 tf_provider_addr=registry.terraform.io/fly-apps/fly tf_rpc=ApplyResourceChange tf_resource_type=fly_machine @module=sdk.framework tf_req_id=38a021a0-7ec9-49fd-d137-f9370fdc9f2d timestamp=2023-01-27T20:10:45.148-0800
2023-01-27T20:10:45.148-0800 [DEBUG] provider.terraform-provider-fly_v0.0.20: Called provider defined ResourceType NewResource: tf_req_id=38a021a0-7ec9-49fd-d137-f9370fdc9f2d tf_rpc=ApplyResourceChange @module=sdk.framework tf_provider_addr=registry.terraform.io/fly-apps/fly tf_resource_type=fly_machine @caller=github.com/hashicorp/terraform-plugin-framework@v0.11.1/internal/fwserver/server_createresource.go:46 timestamp=2023-01-27T20:10:45.148-0800
2023-01-27T20:10:45.148-0800 [DEBUG] provider.terraform-provider-fly_v0.0.20: Calling provider defined Resource Create: @caller=github.com/hashicorp/terraform-plugin-framework@v0.11.1/internal/fwserver/server_createresource.go:89 @module=sdk.framework tf_req_id=38a021a0-7ec9-49fd-d137-f9370fdc9f2d tf_rpc=ApplyResourceChange tf_provider_addr=registry.terraform.io/fly-apps/fly tf_resource_type=fly_machine timestamp=2023-01-27T20:10:45.148-0800
2023-01-27T20:10:45.208-0800 [WARN]  unexpected data: registry.terraform.io/fly-apps/fly:stdout="2023/01/27 20:10:45.201981 DEBUG [req] HTTP/1.1 GET http://_api.internal:4280"
2023-01-27T20:10:45.208-0800 [WARN]  unexpected data: registry.terraform.io/fly-apps/fly:stdout="GET / HTTP/1.1
Host: _api.internal:4280
User-Agent: req/v3 (https://github.com/imroc/req)"
2023-01-27T20:10:45.208-0800 [WARN]  unexpected data: registry.terraform.io/fly-apps/fly:stdout="Authorization: Bearer REMOVED MANUALLY
Accept-Encoding: gzip"
2023-01-27T20:10:45.220-0800 [WARN]  unexpected data: registry.terraform.io/fly-apps/fly:stdout="HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Sat, 28 Jan 2023 04:10:45 GMT
Content-Length: 19"
2023-01-27T20:10:45.220-0800 [WARN]  unexpected data: registry.terraform.io/fly-apps/fly:stdout="404 page not found"
2023-01-27T20:10:45.220-0800 [WARN]  unexpected data: registry.terraform.io/fly-apps/fly:stdout="2023/01/27 20:10:45.220412 DEBUG [req] HTTP/1.1 POST http://_api.internal:4280/v1/apps/vlach-cookbook-staging/machines
POST /v1/apps/vlach-cookbook-staging/machines HTTP/1.1
Host: _api.internal:4280
User-Agent: req/v3 (https://github.com/imroc/req)
Content-Length: 362
Authorization: Bearer REMOVED MANUALLY
Content-Type: application/json; charset=utf-8
Accept-Encoding: gzip

{"name":"","region":"sea","config":{"image":"registry.fly.io/vlach-cookbook-staging:deployment-01GQTRWRE5EJSM9Y2C3MDBG30M","env":{"HOST":"0.0.0.0","MAX_IDLE_SECONDS":"600","PORT":"8080"},"init":{},"services":[{"ports":[{"port":443,"handlers":["tls","http"]}],"protocol":"tcp","internal_port":8080}],"guest":{"cpus":1,"memory_mb":256,"cpu_kind":"shared-cpu-1x"}}}"
2023-01-27T20:10:45.220-0800 [WARN]  unexpected data: registry.terraform.io/fly-apps/fly:stdout=
2023-01-27T20:10:45.239-0800 [WARN]  unexpected data: registry.terraform.io/fly-apps/fly:stdout="HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Fly-Trace-Id: 8799b19ac6d5194ca463ea5ec9104976
Date: Sat, 28 Jan 2023 04:10:45 GMT
Content-Length: 98"
2023-01-27T20:10:45.239-0800 [DEBUG] provider.terraform-provider-fly_v0.0.20: Called provider defined Resource Create: @caller=github.com/hashicorp/terraform-plugin-framework@v0.11.1/internal/fwserver/server_createresource.go:91 tf_provider_addr=registry.terraform.io/fly-apps/fly tf_rpc=ApplyResourceChange @module=sdk.framework tf_req_id=38a021a0-7ec9-49fd-d137-f9370fdc9f2d tf_resource_type=fly_machine timestamp=2023-01-27T20:10:45.238-0800
2023-01-27T20:10:45.239-0800 [WARN]  unexpected data: registry.terraform.io/fly-apps/fly:stdout="{"error":"invalid config.guest.cpu_kind, only \"shared\" or \"performance\" currently supported"}"
2023-01-27T20:10:45.239-0800 [ERROR] provider.terraform-provider-fly_v0.0.20: Response contains error diagnostic: diagnostic_severity=ERROR diagnostic_summary="Failed to create machine" tf_provider_addr=registry.terraform.io/fly-apps/fly @caller=github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov6/internal/diag/diagnostics.go:55 @module=sdk.proto diagnostic_detail="Create request failed: 400 Bad Request, &{ID: Name: State: Region: InstanceID: PrivateIP: Config:{Env:map[] Init:{Exec:[] Entrypoint:[] Cmd:[]} Image: Metadata:<nil> Restart:{Policy:} Services:[] Mounts:[] Guest:{CPUKind: Cpus:0 MemoryMb:0}} ImageRef:{Registry: Repository: Tag: Digest: Labels:{}} CreatedAt:0001-01-01 00:00:00 +0000 UTC}" tf_proto_version=6.3 tf_req_id=38a021a0-7ec9-49fd-d137-f9370fdc9f2d tf_resource_type=fly_machine tf_rpc=ApplyResourceChange timestamp=2023-01-27T20:10:45.239-0800
2023-01-27T20:10:45.240-0800 [ERROR] vertex "fly_machine.cookbook_staging_server" error: Failed to create machine

The machine block in the main.tf is:

resource "fly_machine" "cookbook_staging_server" {
  app      = fly_app.cookbook_staging.name
  region   = "sea"
  cputype  = "shared-cpu-1x"
  cpus     = 1
  memorymb = 256
  image    = "registry.fly.io/vlach-cookbook-staging:${var.staging_image_label}"
  env = {
    PORT             = 8080
    HOST             = "0.0.0.0"
    MAX_IDLE_SECONDS = 10 * 60
  }
  services = [
    {
      ports = [
        {
          port     = 443
          handlers = ["tls", "http"]
        }
      ]
      "protocol" : "tcp",
      "internal_port" : 8080
    }
  ]
}

Any ideas what’s going wrong?

The second before last debug line suggests the matter: cpu_kind can only be "shared" or "performance". So this determines only if te vcpu is shared or not

I would suggest to leave it empty, or set to "shared"

1 Like

Thanks! I’ve sent Explain the machine cputype parameter by jyasskin · Pull Request #144 · fly-apps/terraform-provider-fly · GitHub to put this in the documentation.

1 Like