From c077ea406011627fcfd59ecbeb919876b695ed9c Mon Sep 17 00:00:00 2001 From: Dan Petersen Date: Tue, 15 Sep 2020 22:08:03 +0200 Subject: [PATCH] fix: changed ip detection logic based on review and added initial terraform 0.13 compatibility for the example module --- Makefile | 24 ++++++++++++++++++++++++ example/versions.tf | 14 ++++++++++++++ proxmox/virtual_environment_vm.go | 18 ++++++++---------- 3 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 example/versions.tf diff --git a/Makefile b/Makefile index ae6981e3..c043ed4b 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,27 @@ GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor) NAME=$$(grep TerraformProviderName proxmoxtf/version.go | grep -o -e 'terraform-provider-[a-z]*') TARGETS=darwin linux windows +TERRAFORM_PLUGIN_EXTENSION= VERSION=$$(grep TerraformProviderVersion proxmoxtf/version.go | grep -o -e '[0-9]\.[0-9]\.[0-9]') +ifeq ($(OS),Windows_NT) + TERRAFORM_CACHE_DIRECTORY=$$(cygpath -u "$(APPDATA)")/terraform.d/plugins + TERRAFORM_PLATFORM=windows_amd64 + TERRAFORM_PLUGIN_EXTENSION=.exe +else + TERRAFORM_CACHE_DIRECTORY=$(HOME)/terraform.d/plugins + UNAME_S=$$(shell uname -s) + + ifeq ($(UNAME_S),Darwin) + TERRAFORM_PLATFORM=darwin_amd64 + else + TERRAFORM_PLATFORM=linux_amd64 + endif +endif + +TERRAFORM_PLUGIN_DIRECTORY=$(TERRAFORM_CACHE_DIRECTORY)/terraform.danitso.com/provider/proxmox/$(VERSION)/$(TERRAFORM_PLATFORM) +TERRAFORM_PLUGIN_EXECUTABLE=$(TERRAFORM_PLUGIN_DIRECTORY)/$(NAME)_v$(VERSION)_x4$(TERRAFORM_PLUGIN_EXTENSION) + default: build build: @@ -19,6 +38,11 @@ example-destroy: example-init: rm -f "example/$(NAME)_v"* go build -o "example/$(NAME)_v$(VERSION)-custom_x4" + + mkdir -p "$(TERRAFORM_PLUGIN_DIRECTORY)" + rm -f "$(TERRAFORM_PLUGIN_EXECUTABLE)" + cp "example/$(NAME)_v$(VERSION)-custom_x4" "$(TERRAFORM_PLUGIN_EXECUTABLE)" + cd ./example && terraform init example-plan: diff --git a/example/versions.tf b/example/versions.tf new file mode 100644 index 00000000..45c50008 --- /dev/null +++ b/example/versions.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + local = { + source = "hashicorp/local" + } + proxmox = { + source = "terraform.danitso.com/provider/proxmox" + } + tls = { + source = "hashicorp/tls" + } + } + required_version = ">= 0.13" +} diff --git a/proxmox/virtual_environment_vm.go b/proxmox/virtual_environment_vm.go index f1016d4c..8993977b 100644 --- a/proxmox/virtual_environment_vm.go +++ b/proxmox/virtual_environment_vm.go @@ -180,16 +180,14 @@ func (c *VirtualEnvironmentClient) WaitForNetworkInterfacesFromVMAgent(nodeName missingIP := false if waitForIP { - if len(*data.Result) == 0 { - missingIP = true - } else if len(*data.Result) == 1 && (*data.Result)[0].Name == "lo" { - missingIP = true - } else { - for _, nic := range *data.Result { - if nic.IPAddresses != nil && len(*nic.IPAddresses) == 0 { - missingIP = true - break - } + for _, nic := range *data.Result { + if nic.Name == "lo" { + continue + } + + if nic.IPAddresses == nil || (nic.IPAddresses != nil && len(*nic.IPAddresses) == 0) { + missingIP = true + break } } }