disk: Read attach field using volume's Virtualmachineid (#38)

The `.Attached` field is unreliable, there are situations where
cloudstack will return an empty `.Attached` value even if the disk is
attached to a VM. So far I've seem this happen when the disk is created
alongside with the virtualmachine (deployVirtualMachine called with the
`size` attribute) but there may be other situations where this also
happens.

Checking for the `.Virtualmachineid` field to set the `attach` attribute
seems a safer approach as it's always set when the volume is already
attached.

I came across this when importing an existing infrastructure to
terraform by manually creating a state file, the existing VMs have
attached volumes that were created with them and these volumes don't
have a `.Attached` field. This causes the cloudstack provider to try to
attach them to the same VMs they are already attached, raising an error.
1 file changed
tree: 8d80210a47108b12581644388b1e6401c6ad20eb
  1. .github/
  2. cloudstack/
  3. scripts/
  4. vendor/
  5. website/
  6. .gitignore
  7. .travis.yml
  8. CHANGELOG.md
  9. GNUmakefile
  10. LICENSE
  11. main.go
  12. README.md
README.md

Terraform Provider

Requirements

Building The Provider

Clone repository to: $GOPATH/src/github.com/terraform-providers/terraform-provider-cloudstack

$ mkdir -p $GOPATH/src/github.com/terraform-providers; cd $GOPATH/src/github.com/terraform-providers
$ git clone git@github.com:terraform-providers/terraform-provider-cloudstack

Enter the provider directory and build the provider

$ cd $GOPATH/src/github.com/terraform-providers/terraform-provider-cloudstack
$ make build

Using the provider

Fill in for each provider

Developing the Provider

If you wish to work on the provider, you‘ll first need Go installed on your machine (version 1.8+ is required). You’ll also need to correctly setup a GOPATH, as well as adding $GOPATH/bin to your $PATH.

To compile the provider, run make build. This will build the provider and put the provider binary in the $GOPATH/bin directory.

$ make bin
...
$ $GOPATH/bin/terraform-provider-cloudstack
...

In order to test the provider, you can simply run make test.

$ make test

In order to run the full suite of Acceptance tests, run make testacc.

Note: Acceptance tests create real resources, and often cost money to run.

$ make testacc