Skip to content

Commit 84f1434

Browse files
authored
Merge pull request #422 from mleone87/master
Bugfixes, timeouts, logging improvement, some logic rework
2 parents b7bcc94 + 5c49181 commit 84f1434

File tree

14 files changed

+493
-374
lines changed

14 files changed

+493
-374
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ examples/*_override.tf
44
*~*
55
*.bak
66
bin
7+
.vscode
8+
*.log

Makefile

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
1+
SHELL := /bin/bash
2+
3+
DESCRIBE := $(shell git describe --match "v*" --always --tags)
4+
DESCRIBE_PARTS := $(subst -, ,$(DESCRIBE))
5+
6+
VERSION_TAG := $(word 1,$(DESCRIBE_PARTS))
7+
COMMITS_SINCE_TAG := $(word 2,$(DESCRIBE_PARTS))
8+
9+
VERSION := $(subst v,,$(VERSION_TAG))
10+
VERSION_PARTS := $(subst ., ,$(VERSION))
11+
12+
MAJOR := $(word 1,$(VERSION_PARTS))
13+
MINOR := $(word 2,$(VERSION_PARTS))
14+
MICRO := $(word 3,$(VERSION_PARTS))
15+
16+
NEXT_MAJOR := $(shell echo $$(($(MAJOR)+1)))
17+
NEXT_MINOR := $(shell echo $$(($(MINOR)+1)))
18+
NEXT_MICRO = $(shell echo $$(($(MICRO)+1)))
19+
20+
ifeq ($(strip $(COMMITS_SINCE_TAG)),)
21+
CURRENT_VERSION_MICRO := $(MAJOR).$(MINOR).$(MICRO)
22+
CURRENT_VERSION_MINOR := $(CURRENT_VERSION_MICRO)
23+
CURRENT_VERSION_MAJOR := $(CURRENT_VERSION_MICRO)
24+
else
25+
CURRENT_VERSION_MICRO := $(MAJOR).$(MINOR).$(NEXT_MICRO)
26+
CURRENT_VERSION_MINOR := $(MAJOR).$(NEXT_MINOR).0
27+
CURRENT_VERSION_MAJOR := $(NEXT_MAJOR).0.0
28+
endif
29+
30+
DATE = $(shell date +'%d.%m.%Y')
31+
TIME = $(shell date +'%H:%M:%S')
32+
COMMIT := $(shell git rev-parse HEAD)
33+
AUTHOR := $(firstword $(subst @, ,$(shell git show --format="%aE" $(COMMIT))))
34+
BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD)
35+
36+
TAG_MESSAGE = "$(TIME) $(DATE) $(AUTHOR) $(BRANCH_NAME)"
37+
COMMIT_MESSAGE := $(shell git log --format=%B -n 1 $(COMMIT))
38+
39+
CURRENT_TAG_MICRO := "v$(CURRENT_VERSION_MICRO)"
40+
CURRENT_TAG_MINOR := "v$(CURRENT_VERSION_MINOR)"
41+
CURRENT_TAG_MAJOR := "v$(CURRENT_VERSION_MAJOR)"
42+
43+
KERNEL=$(shell if [ "$$(uname -s)" == "Linux" ]; then echo linux; fi)
44+
ARCH=$(shell if [ "$$(uname -m)" == "x86_64" ]; then echo amd64; fi)
45+
46+
# $(info $$KERNEL = $(KERNEL))
47+
48+
# $(error $$ARCH = $(ARCH))
49+
150
.PHONY: build fmt vet test clean install acctest local-dev-install
251

352
all: build
@@ -27,11 +76,12 @@ acctest: build
2776
install: build
2877
cp bin/terraform-provider-proxmox $$GOPATH/bin/terraform-provider-proxmox
2978

30-
KERNEL=$(shell $(uname -s | tr '[:upper:]' '[:lower:]'))
31-
ARCH=$(shell if [ "$$(uname -m)" == "x86_64" ]; then echo amd64; fi)
32-
local-dev-install:
33-
mkdir -p ~/.terraform.d/plugins/registry.example.com/telmate/proxmox/$(KERNEL)_$(ARCH)/
34-
cp bin/terraform-provider-proxmox ~/.terraform.d/plugins/registry.example.com/telmate/proxmox/$(KERNEL)_$(ARCH)/
79+
local-dev-install: build
80+
@echo "$(CURRENT_VERSION_MICRO)"
81+
@echo "$(KERNEL)"
82+
@echo "$(ARCH)"
83+
mkdir -p ~/.terraform.d/plugins/localhost/telmate/proxmox/$(CURRENT_VERSION_MICRO)/$(KERNEL)_$(ARCH)/
84+
cp bin/terraform-provider-proxmox ~/.terraform.d/plugins/localhost/telmate/proxmox/$(CURRENT_VERSION_MICRO)/$(KERNEL)_$(ARCH)/
3585

3686
clean:
37-
@git clean -f -d -X
87+
@git clean -f -d

docs/index.md

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
A Terraform provider is responsible for understanding API interactions and exposing resources. The Proxmox provider uses the Proxmox API. This provider exposes two resources: [proxmox_vm_qemu](docs/resources/vm_qemu.md) and [proxmox_lxc](docs/resources/lxc.md).
44

5-
## Creating the Proxmox user and role for terraform
5+
## Creating the Proxmox user and role for terraform
66

77
The particular privileges required may change but here is a suitable starting point rather than using cluster-wide Administrator rights
88

99
Log into the Proxmox cluster or host using ssh (or mimic these in the GUI) then:
10+
1011
- Create a new role for the future terraform user.
1112
- Create the user "terraform-prov@pve"
1213
- Add the TERRAFORM-PROV role to the terraform-prov user
@@ -17,9 +18,9 @@ pveum user add terraform-prov@pve --password <password>
1718
pveum aclmod / -user terraform-prov@pve -role TerraformProv
1819
```
1920

20-
The provider also supports using an API key rather than a password, see below for details.
21+
The provider also supports using an API key rather than a password, see below for details.
2122

22-
After the role is in use, if there is a need to modify the privileges, simply issue the command showed, adding or removing priviledges as needed.
23+
After the role is in use, if there is a need to modify the privileges, simply issue the command showed, adding or removing priviledges as needed.
2324

2425
```bash
2526
pveum role modify TerraformProv -privs "VM.Allocate VM.Clone VM.Config.CDROM VM.Config.CPU VM.Config.Cloudinit VM.Config.Disk VM.Config.HWType VM.Config.Memory VM.Config.Network VM.Config.Options VM.Monitor VM.Audit VM.PowerMgmt Datastore.AllocateSpace Datastore.Audit"
@@ -59,33 +60,46 @@ provider "proxmox" {
5960
}
6061
```
6162

63+
## Enable Debug Mode in proxmox-api-go
64+
65+
You can enable global debug mode for the provider underliing api client, using the new provider parameter. The default setting is _false_
66+
67+
```hcl
68+
provider "proxmox" {
69+
pm_debug = true
70+
}
71+
```
72+
6273
## Argument Reference
6374

6475
The following arguments are supported in the provider block:
6576

66-
* `pm_api_url` - (Required; or use environment variable `PM_API_URL`) This is the target Proxmox API endpoint.
67-
* `pm_user` - (Optional; or use environment variable `PM_USER`) The user, remember to include the authentication realm such as myuser@pam or myuser@pve.
68-
* `pm_password` - (Optional; sensitive; or use environment variable `PM_PASS`) The password.
69-
* `pm_api_token_id` - (Optional; or use environment variable `PM_API_TOKEN_ID`) This is an [API token](https://pve.proxmox.com/pve-docs/pveum-plain.html) you have previously created for a specific user.
70-
* `pm_api_token_secret` - (Optional; or use environment variable `PM_API_TOKEN_SECRET`) This is a uuid that is only available when initially creating the token.
71-
* `pm_otp` - (Optional; or use environment variable `PM_OTP`) The 2FA OTP code.
72-
* `pm_tls_insecure` - (Optional) Disable TLS verification while connecting to the proxmox server.
73-
* `pm_parallel` - (Optional; defaults to 4) Allowed simultaneous Proxmox processes (e.g. creating resources).
74-
* `pm_log_enable` - (Optional; defaults to false) Enable debug logging, see the section below for logging details.
75-
* `pm_log_levels` - (Optional) A map of log sources and levels.
76-
* `pm_log_file` - (Optional; defaults to "terraform-plugin-proxmox.log") If logging is enabled, the log file the provider will write logs to.
77-
* `pm_timeout` - (Optional; defaults to 300) Timeout value (seconds) for proxmox API calls.
77+
- `pm_api_url` - (Required; or use environment variable `PM_API_URL`) This is the target Proxmox API endpoint.
78+
- `pm_user` - (Optional; or use environment variable `PM_USER`) The user, remember to include the authentication realm such as myuser@pam or myuser@pve.
79+
- `pm_password` - (Optional; sensitive; or use environment variable `PM_PASS`) The password.
80+
- `pm_api_token_id` - (Optional; or use environment variable `PM_API_TOKEN_ID`) This is an [API token](https://pve.proxmox.com/pve-docs/pveum-plain.html) you have previously created for a specific user.
81+
- `pm_api_token_secret` - (Optional; or use environment variable `PM_API_TOKEN_SECRET`) This is a uuid that is only available when initially creating the token.
82+
- `pm_otp` - (Optional; or use environment variable `PM_OTP`) The 2FA OTP code.
83+
- `pm_tls_insecure` - (Optional) Disable TLS verification while connecting to the proxmox server.
84+
- `pm_parallel` - (Optional; defaults to 4) Allowed simultaneous Proxmox processes (e.g. creating resources).
85+
- `pm_log_enable` - (Optional; defaults to false) Enable debug logging, see the section below for logging details.
86+
- `pm_log_levels` - (Optional) A map of log sources and levels.
87+
- `pm_log_file` - (Optional; defaults to "terraform-plugin-proxmox.log") If logging is enabled, the log file the provider will write logs to.
88+
- `pm_timeout` - (Optional; defaults to 300) Timeout value (seconds) for proxmox API calls.
89+
- `pm_debug` - (Optional; defaults to false) Enable verbose output in proxmox-api-go
7890

7991
Additionally, one can set the `PM_OTP_PROMPT` environment variable to prompt for OTP 2FA code (if required).
8092

8193
## Logging
8294

83-
The provider is able to output detailed logs upon request. Note that this feature is intended for development purposes, but could also be used to help investigate bugs. For example: the following code when placed into the provider "proxmox" block will enable loging to the file "terraform-plugin-proxmox.log". All log sources will default to the "debug" level, and any stdout/stderr from sublibraries (proxmox-api-go) will be silenced (set to non-empty string to enable).
95+
The provider is able to output detailed logs upon request. Note that this feature is intended for development purposes, but could also be used to help investigate bugs. For example: the following code when placed into the provider "proxmox" block will enable loging to the file "terraform-plugin-proxmox.log". All log sources will default to the "debug" level.
96+
To silence and any stdout/stderr from sublibraries (proxmox-api-go), remove or comment out \_capturelog.
8497

8598
```hcl
8699
provider "proxmox" {
87100
pm_log_enable = true
88101
pm_log_file = "terraform-plugin-proxmox.log"
102+
pm_debug = true
89103
pm_log_levels = {
90104
_default = "debug"
91105
_capturelog = ""

0 commit comments

Comments
 (0)