- Related issues: #2443 [BUG] Image handling inconsistency between “Harvester Terraform harvester_image data source” vs. “UI created Image”
Category:
- Terraform
Verification Steps
-
Download latest terraform-provider terraform-provider-harvester_0.5.1_linux_amd64.zip
-
Extra the zip file
-
Create the install-terraform-provider-harvester.sh with the following content
#!/usr/bin/env bash [[ -n $DEBUG ]] && set -x set -eou pipefail usage() { cat <<HELP USAGE: install-terraform-provider-harvester.sh HELP } version=0.5.1 arch=linux_amd64 terraform_harvester_provider_bin=./terraform-provider-harvester terraform_harvester_provider_dir="${HOME}/.terraform.d/plugins/registry.terraform.io/harvester/harvester/${version}/${arch}/" mkdir -p "${terraform_harvester_provider_dir}" cp ${terraform_harvester_provider_bin} "${terraform_harvester_provider_dir}/terraform-provider-harvester_v${version}"
-
Rename the extraced
terraform-provider-harvester_v0.5.1
toterraform-provider-harvester
in the same folder with the install script -
Execute the installation script
-
Clone the terraform-provider project
-
Get the Harvester kubeconfig and place to the specific config file
-
Specify the kubeconfig path in
provider.tf
terraform { required_version = ">= 0.13" required_providers { harvester = { source = "harvester/harvester" version = "0.5.1" } } } provider "harvester" { kubeconfig = "/home/davidtclin/.kube/config" }
-
Create a image ubuntu-18.04-minimal-cloudimg-amd64.img in the namespace harvester-public form UI side
-
Create a data source harvester_image.ubuntu1804 in resource.tf
data "harvester_image" "ubuntu1804" { namespace = "harvester-public" display_name = "ubuntu-18.04-minimal-cloudimg-amd64.img" }
-
Execute
terraform init -upgrade
-
Execute
terraform apply
-
Execute
terraform show
... ... Plan: 1 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes harvester_ssh_key.davidtclin: Creating... harvester_ssh_key.davidtclin: Creation complete after 0s [id=default/davidtclin] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
-
Execute
terraform show
davidtclin@localhost:~/Documents/Harvester/workspace/terraform-provider-harvester/examples/test> terraform show # data.harvester_image.ubuntu1804: data "harvester_image" "ubuntu1804" { display_name = "ubuntu-18.04-minimal-cloudimg-amd64.img" id = "harvester-public/image-7w8tp" name = "image-7w8tp" namespace = "harvester-public" progress = 100 size = 202637312 source_type = "download" state = "Active" storage_class_name = "longhorn-image-7w8tp" tags = {} url = "https://cloud-images.ubuntu.com/minimal/releases/bionic/release/ubuntu-18.04-minimal-cloudimg-amd64.img" } ...
Expected Results
We can use the data source refer to the display name that had been used via creation of the image via UI.
-
Image resource created in image UI
-
Image state of running
terraform show
davidtclin@localhost:~/Documents/Harvester/workspace/terraform-provider-harvester/examples/test> terraform show # data.harvester_image.ubuntu1804: data "harvester_image" "ubuntu1804" { display_name = "ubuntu-18.04-minimal-cloudimg-amd64.img" id = "harvester-public/image-7w8tp" name = "image-7w8tp" namespace = "harvester-public" progress = 100 size = 202637312 source_type = "download" state = "Active" storage_class_name = "longhorn-image-7w8tp" tags = {} url = "https://cloud-images.ubuntu.com/minimal/releases/bionic/release/ubuntu-18.04-minimal-cloudimg-amd64.img" } ...