Skip to content

Commit 53b557a

Browse files
authored
feat(plugin): use common UpCloud env variables (#32)
Use environment variables `UPCLOUD_USERNAME` and `UPCLOUD_PASSWORD` for authentication. Variables `UPCLOUD_API_USER` and `UPCLOUD_API_PASSWORD` still work but are considered to be deprecated.
1 parent 90cb03b commit 53b557a

File tree

15 files changed

+74
-44
lines changed

15 files changed

+74
-44
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)
55

66
## [Unreleased]
77

8+
### Added
9+
- enviroment variables `UPCLOUD_USERNAME` and `UPCLOUD_PASSWORD` for authentication
10+
11+
### Deprecated
12+
- environment variables `UPCLOUD_API_USER` and `UPCLOUD_API_PASSWORD`
13+
814
## [1.4.0] - 2022-05-30
915

1016
### Added

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,9 @@ fmt:
5252
packer fmt example/
5353
packer fmt -recursive docs-partials/
5454

55+
clean:
56+
find . -name "packer_log_*" -delete
57+
find . -name "TestBuilderAcc_*" -delete
58+
find . -name "packer-plugin-upcloud" -delete
59+
5560
.PHONY: default test test_integration lint build install

builder/upcloud/builder_acc_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ func TestBuilderAcc_network_interfaces(t *testing.T) {
146146
}
147147

148148
func testAccPreCheck(t *testing.T) {
149-
if v := os.Getenv("UPCLOUD_API_USER"); v == "" {
150-
t.Skip("UPCLOUD_API_USER must be set for acceptance tests")
149+
if v := driver.UsernameFromEnv(); v == "" {
150+
t.Skipf("%s or %s must be set for acceptance tests", driver.EnvConfigUsernameLegacy, driver.EnvConfigUsername)
151151
}
152-
if v := os.Getenv("UPCLOUD_API_PASSWORD"); v == "" {
153-
t.Skip("UPCLOUD_API_PASSWORD must be set for acceptance tests")
152+
if v := driver.PasswordFromEnv(); v == "" {
153+
t.Skipf("%s or %s must be set for acceptance tests", driver.EnvConfigPasswordLegacy, driver.EnvConfigPassword)
154154
}
155155
}
156156

@@ -228,8 +228,8 @@ func teardown(testName string) func() error {
228228
}
229229

230230
drv := driver.NewDriver(&driver.DriverConfig{
231-
Username: os.Getenv("UPCLOUD_API_USER"),
232-
Password: os.Getenv("UPCLOUD_API_PASSWORD"),
231+
Username: driver.UsernameFromEnv(),
232+
Password: driver.PasswordFromEnv(),
233233
Timeout: DefaultTimeout,
234234
})
235235

builder/upcloud/config.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ package upcloud
44

55
import (
66
"errors"
7-
"os"
87
"time"
98

9+
"github.com/UpCloudLtd/packer-plugin-upcloud/internal/driver"
1010
"github.com/UpCloudLtd/upcloud-go-api/v4/upcloud"
1111
"github.com/UpCloudLtd/upcloud-go-api/v4/upcloud/request"
1212
"github.com/hashicorp/packer-plugin-sdk/common"
@@ -227,13 +227,11 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
227227

228228
// get params from environment
229229
func (c *Config) setEnv() {
230-
username := os.Getenv("UPCLOUD_API_USER")
231-
if username != "" && c.Username == "" {
232-
c.Username = username
230+
if c.Username == "" {
231+
c.Username = driver.UsernameFromEnv()
233232
}
234233

235-
password := os.Getenv("UPCLOUD_API_PASSWORD")
236-
if password != "" && c.Password == "" {
237-
c.Password = password
234+
if c.Password == "" {
235+
c.Password = driver.PasswordFromEnv()
238236
}
239237
}

docs-partials/config/builder/upcloud/interfaces.pkr.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ packer {
1010
variable "username" {
1111
type = string
1212
description = "UpCloud API username"
13-
default = "${env("UPCLOUD_API_USER")}"
13+
default = "${env("UPCLOUD_USERNAME")}"
1414
}
1515

1616
variable "password" {
1717
type = string
1818
description = "UpCloud API password"
19-
default = "${env("UPCLOUD_API_PASSWORD")}"
19+
default = "${env("UPCLOUD_PASSWORD")}"
2020
sensitive = true
2121
}
2222

docs-partials/config/builder/upcloud/interfaces_ipv6.pkr.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ packer {
1010
variable "username" {
1111
type = string
1212
description = "UpCloud API username"
13-
default = "${env("UPCLOUD_API_USER")}"
13+
default = "${env("UPCLOUD_USERNAME")}"
1414
}
1515

1616
variable "password" {
1717
type = string
1818
description = "UpCloud API password"
19-
default = "${env("UPCLOUD_API_PASSWORD")}"
19+
default = "${env("UPCLOUD_PASSWORD")}"
2020
sensitive = true
2121
}
2222

docs-partials/config/builder/upcloud/interfaces_private.pkr.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ packer {
1010
variable "username" {
1111
type = string
1212
description = "UpCloud API username"
13-
default = "${env("UPCLOUD_API_USER")}"
13+
default = "${env("UPCLOUD_USERNAME")}"
1414
}
1515

1616
variable "password" {
1717
type = string
1818
description = "UpCloud API password"
19-
default = "${env("UPCLOUD_API_PASSWORD")}"
19+
default = "${env("UPCLOUD_PASSWORD")}"
2020
sensitive = true
2121
}
2222

docs-src/post-processors/upcloud-import.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Artifact BuilderId: `packer.post-processor.upcloud-import`
1414
The UpCloud importer can be used to import raw disk images as private templates to UpCloud.
1515

1616
### Required
17-
Username and password configuration arguments can be omitted if environment variables `UPCLOUD_API_USER` and `UPCLOUD_API_PASSWORD` are set.
17+
Username and password configuration arguments can be omitted if environment variables `UPCLOUD_USERNAME` and `UPCLOUD_PASSWORD` are set.
1818

1919
@include 'post-processor/upcloud-import/Config-required.mdx'
2020

docs/builders/upcloud.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ packer {
125125
variable "username" {
126126
type = string
127127
description = "UpCloud API username"
128-
default = "${env("UPCLOUD_API_USER")}"
128+
default = "${env("UPCLOUD_USERNAME")}"
129129
}
130130

131131
variable "password" {
132132
type = string
133133
description = "UpCloud API password"
134-
default = "${env("UPCLOUD_API_PASSWORD")}"
134+
default = "${env("UPCLOUD_PASSWORD")}"
135135
sensitive = true
136136
}
137137

@@ -183,13 +183,13 @@ packer {
183183
variable "username" {
184184
type = string
185185
description = "UpCloud API username"
186-
default = "${env("UPCLOUD_API_USER")}"
186+
default = "${env("UPCLOUD_USERNAME")}"
187187
}
188188

189189
variable "password" {
190190
type = string
191191
description = "UpCloud API password"
192-
default = "${env("UPCLOUD_API_PASSWORD")}"
192+
default = "${env("UPCLOUD_PASSWORD")}"
193193
sensitive = true
194194
}
195195

@@ -249,13 +249,13 @@ packer {
249249
variable "username" {
250250
type = string
251251
description = "UpCloud API username"
252-
default = "${env("UPCLOUD_API_USER")}"
252+
default = "${env("UPCLOUD_USERNAME")}"
253253
}
254254

255255
variable "password" {
256256
type = string
257257
description = "UpCloud API password"
258-
default = "${env("UPCLOUD_API_PASSWORD")}"
258+
default = "${env("UPCLOUD_PASSWORD")}"
259259
sensitive = true
260260
}
261261

@@ -318,13 +318,13 @@ packer {
318318
variable "username" {
319319
type = string
320320
description = "UpCloud API username"
321-
default = "${env("UPCLOUD_API_USER")}"
321+
default = "${env("UPCLOUD_USERNAME")}"
322322
}
323323

324324
variable "password" {
325325
type = string
326326
description = "UpCloud API password"
327-
default = "${env("UPCLOUD_API_PASSWORD")}"
327+
default = "${env("UPCLOUD_PASSWORD")}"
328328
sensitive = true
329329
}
330330

docs/post-processors/upcloud-import.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Artifact BuilderId: `packer.post-processor.upcloud-import`
1414
The UpCloud importer can be used to import raw disk images as private templates to UpCloud.
1515

1616
### Required
17-
Username and password configuration arguments can be omitted if environment variables `UPCLOUD_API_USER` and `UPCLOUD_API_PASSWORD` are set.
17+
Username and password configuration arguments can be omitted if environment variables `UPCLOUD_USERNAME` and `UPCLOUD_PASSWORD` are set.
1818

1919
<!-- Code generated from the comments of the Config struct in post-processor/upcloud-import/config.go; DO NOT EDIT MANUALLY -->
2020

@@ -49,13 +49,13 @@ Import raw disk image from filesystem using `compress` post-processor to compres
4949
variable "username" {
5050
type = string
5151
description = "UpCloud API username"
52-
default = env("UPCLOUD_API_USER")
52+
default = env("UPCLOUD_USERNAME")
5353
}
5454

5555
variable "password" {
5656
type = string
5757
description = "UpCloud API password"
58-
default = env("UPCLOUD_API_PASSWORD")
58+
default = env("UPCLOUD_PASSWORD")
5959
sensitive = true
6060
}
6161

0 commit comments

Comments
 (0)