Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Volume attachment with droplet in digitalOcean using terraform

Tags:

terraform

I am trying to attach a volume with droplet using terraform in digitalocean provider. I am able to create droplet and volume. But when i am trying to attach volume with droplet i am getting the error.

Below is my code:

    provider "digitalocean" {
      token = "${var.do_token}"
     }
    resource "digitalocean_volume" "web" {
      region                  = "nyc1"
      name                    = "baz"
      size                    = 10
      initial_filesystem_type = "ext4"
      description             = "First volume for testing 10 GB"
    }

    resource "digitalocean_droplet" "web" {
      name = "web"
      size = "${var.size}"
      image = "${var.image}"
      region = "${var.region}"
      ssh_keys = [23625200]
      private_networking = "true"
    connection {
        user = "root"
        type = "ssh"
        private_key = "${file("/root/id_rsa")}"
        timeout = "2m"
        }
    provisioner "remote-exec" {
      inline = [
        "sudo apt update -y",
        "sudo apt install nginx -y",
      ]

     }
     }  
        resource "digitalocean_firewall" "dagar" {
          name = "only-22-and-80"
          droplet_ids = ["${digitalocean_droplet.web.id}"]
        inbound_rule {
         protocol           = "tcp"
         port_range         = "80"
         source_addresses   = ["0.0.0.0/0", "::/0"]
     }
    inbound_rule {
      protocol           = "tcp"
      port_range         = "22"
      source_addresses   = ["0.0.0.0/0", "::/0"]
       }
       }
   resource "digitalocean_volume_attachment" "web1" {
     droplet_id = "${digitalocean_droplet.web.id}"
     volume_id  = "${digitalocean_volume.web.id}"
     }

I have validate and run plan both are successful but when i am running apply its giving me blow error:

Error: Error applying plan:

1 error(s) occurred:

* digitalocean_volume_attachment.web: 1 error(s) occurred:

* digitalocean_volume_attachment.web: Error attaching volume to droplet after retry timeout: [WARN] Error attaching volume (92f6052e-6d5f-11e9-8d4c-0a58ac14455b) to Droplet (142436110): POST https://api.digitalocean.com/v2/volumes/92f6052e-6d5f-11e9-8d4c-0a58ac14455b/actions: 404 (request "90720f03-3d3c-4003-97d5-c25e031845f0") volume not found

Can you please help me to find out what is the cause?

Thanks in advance.

like image 767
Tekchand Dagar Avatar asked Oct 29 '25 07:10

Tekchand Dagar


1 Answers

The above issue is fixed. I have created the droplet and volume in different region thats why volume was not able to attache and API giving 404 not found error. Now i have made the changes and everything is working fine.

Thanks.

like image 114
Tekchand Dagar Avatar answered Oct 31 '25 11:10

Tekchand Dagar