dmacvicar / terraform-provider-libvirt

Terraform provider to provision infrastructure with Linux's KVM using libvirt
Apache License 2.0
1.59k stars 458 forks source link

Fix/pool type #824

Closed RouxAntoine closed 3 years ago

RouxAntoine commented 3 years ago

Hello,

Little fix when import existing pool resource type: dir is not set which cause a pool resource recreation on following terraform apply/plan. I am not sure if it is a good practice to add type definition into schema resource read operation maybe it could be set into Importer operation. But due to actual use of schema.ImportStatePassthrough it seem more simple.

tfstate content after terraform import :

  "version": 4,
  "terraform_version": "0.13.5",
  "serial": 14,
  "lineage": "d1b8ac6d-ba5b-fbd6-8ced-f714bb8a21df",
  "outputs": {},
  "resources": [
    {
      "mode": "managed",
      "type": "libvirt_pool",
      "name": "test",
      "provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "allocation": 79629910016,
            "available": null,
            "capacity": 86946873344,
            "id": "e2e4ad32-7b14-4b4f-95e7-b5b7327acfe7",
            "name": "test",
            "path": "<path>",
            "type": null,                              // <=== here is wrongly null value
            "xml": []
          },
          "private": "eyJzY2hlbWFfdmVyc2lvbiI6IjAifQ=="
        }
      ]
    }
  ]
}

Step to reproduce :

terraform init
virsh pool-define-as --name test --type dir --target <path>
virsh pool-start test --build
virsh pool-uuid --pool test
terraform import libvirt_pool.test <previous-uuid>

// ask for recreate
terraform plan

My tf file configuration applied after terraform import

terraform {
  required_version = ">= 0.13"
  required_providers {
    libvirt = {
      source  = "dmacvicar/libvirt"
      version = ">= 0.6.3"
    }
  }
  backend "etcdv3" {
   ...
  }
}

provider "libvirt" {
  uri = "qemu+tcp://<endpoint>"
}

resource "libvirt_pool" "test" {
  name = "test"
  type = "dir"
  path = "<path>"
}

Thanks for your reviews.

MalloZup commented 3 years ago

thx for pr @RouxAntoine

dmacvicar commented 3 years ago

Thanks a lot for the contribution. Sorry that it took long, but we just merged a big port to make the provider available on the Terraform Registry among others.

RouxAntoine commented 3 years ago

Thanks a lot for the contribution. Sorry that it took long, but we just merged a big port to make the provider available on the Terraform Registry among others.

No problem thanks, glad to hear that this provider will be available on terraform registry