latitudesh / terraform-provider-latitudesh

Latitude.sh Terraform Provider
https://registry.terraform.io/providers/latitudesh/latitudesh/latest/docs
Mozilla Public License 2.0
10 stars 4 forks source link

Cannot create server using project slug id #45

Closed zheli closed 11 months ago

zheli commented 1 year ago

Cannot create server using terraform.

Describe the bug

You will get the error below:

│ Error: json: cannot unmarshal string into Go struct field ServerProject.data.attributes.project.id of type int64

Affected Resource(s)

Expected Behavior

Server created successfully.

Actual Behavior

Server created but I can't finish applying the whole project. I can't import project either.

Steps to Reproduce

  1. Create a main.tf file
    resource "latitudesh_server" "server" {
    hostname         = "terraform.latitude.sh"
    operating_system = "ubuntu_22_04_x64_lts"
    plan             = "s2-small-x86"
    project          = "{project-id}"      # You can use the project id or slug
    site             = "DAL"
    ssh_keys         = [{ssh-key-id}]
    }
  2. terraform apply

Terraform Configuration Files

Terraform version

v1.4.6

Debug Output

https://gist.github.com/zheli/7b142cf8832164f0519b0e1df1138ae5

Panic Output

Additional context

References

esoubihe commented 1 year ago

Hi @zheli, thank you for opening an issue. Please try the following syntax and let me know if it works for you

  resource "latitudesh_server" "server" {
    hostname         = "terraform.latitude.sh"
    operating_system = "ubuntu_22_04_x64_lts"
    plan             = "s2-small-x86"
    project          = var.project_id # You can use the project id or slug
    site             = "DAL"
    ssh_keys         = [var.ssh_key_id]
  }

Make sure you have correctly defined the variables on variables.tf

Alternatively, if you're also managing projects and ssh keys with TF, reference resources like this

resource "latitudesh_server" "server" {
  hostname         = "terraform.latitude.sh"
  operating_system = "ubuntu_22_04_x64_lts"
  plan             = "s2-small-x86"
  project          = latitudesh_project.project.id # replace project with the resource name you used on the project.tf file
  site             = "DAL"
  ssh_keys         = [latitudesh_ssh_key.ssh_key.id] # replace ssh_key with the resource name you used on the ssh_key.tf file
}

You can find an example integration here: https://docs.latitude.sh/docs/terraform#example-integration

Let me know if that fixes your issue.

ynhummel commented 11 months ago

I'm closing this issue for the reasons stated in https://github.com/latitudesh/terraform-provider-latitudesh/issues/46. Now, with https://github.com/latitudesh/terraform-provider-latitudesh/releases/tag/v0.2.9, these issues should be solved.

Thank you yet again for your feedback!