Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit f7268f5

Browse files
authored
Merge pull request #48 from hashicorp/tf-0.12.25
Update to Terraform 0.12.25, add TF_VERSION environment variable
2 parents 8d2fa7c + fe04a11 commit f7268f5

7 files changed

Lines changed: 135 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
## 0.1.3 (April 28, 2020)
1+
## 0.1.4-alpha (May 14, 2020)
2+
3+
* Allow user to specify SSH Key by name or ID (#41)
4+
* Update to Terraform 0.12.25 and add TF_VERSION environment variable (#47)
5+
6+
## 0.1.3-alpha (April 28, 2020)
27

38
* Add `sshKeyID` to CR spec, so users can reference modules in private git repos (#25)
49
* Always update Sensitive variables when a Run is triggered and before the Run is executed (#22)
510
* Fix: update variables when HCL flag changes (#33)
611

7-
## 0.1.2 (April 16, 2020)
12+
## 0.1.2-alpha (April 16, 2020)
813

914
* Enable non-string Terraform variables by setting HCL type (#11)
1015
* Fix panics in handling non-string Terraform output (#19)
1116

12-
## 0.1.1 (March 24, 2020)
17+
## 0.1.1-alpha (March 24, 2020)
1318

1419
* Handle non-string Terraform outputs and return them as JSON-formatted string (#12)
1520

16-
## 0.1.0 (2020)
21+
## 0.1.0-alpha (2020)
1722

1823
* Initial release

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ require (
66
github.com/go-logr/logr v0.1.0
77
github.com/go-openapi/spec v0.19.4
88
github.com/hashicorp/go-tfe v0.3.31
9-
github.com/hashicorp/terraform v0.12.24
9+
github.com/hashicorp/terraform v0.12.25
1010
github.com/mitchellh/cli v1.1.0
1111
github.com/operator-framework/operator-sdk v0.15.1
1212
github.com/spf13/pflag v1.0.5
13-
github.com/stretchr/testify v1.4.0
13+
github.com/stretchr/testify v1.5.1
1414
github.com/zclconf/go-cty v1.3.1
1515
k8s.io/api v0.0.0
1616
k8s.io/apimachinery v0.0.0

go.sum

Lines changed: 83 additions & 3 deletions
Large diffs are not rendered by default.

operator/pkg/controller/workspace/tfc_org.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package workspace
33
import (
44
"context"
55
"fmt"
6+
"os"
67

78
tfc "github.com/hashicorp/go-tfe"
89
appv1alpha1 "github.com/hashicorp/terraform-k8s/operator/pkg/apis/app/v1alpha1"
10+
"github.com/hashicorp/terraform-k8s/operator/version"
911
"github.com/hashicorp/terraform/command/cliconfig"
1012
)
1113

@@ -68,11 +70,20 @@ func (t *TerraformCloudClient) CheckWorkspace(workspace string, instance *appv1a
6870
return ws.ID, err
6971
}
7072

73+
func getTerraformVersion() *string {
74+
tfVersion := os.Getenv("TF_VERSION")
75+
if tfVersion == "" {
76+
return &version.TerraformVersion
77+
}
78+
return &tfVersion
79+
}
80+
7181
// CreateWorkspace creates a Terraform Cloud Workspace that auto-applies
7282
func (t *TerraformCloudClient) CreateWorkspace(workspace string) (string, error) {
7383
options := tfc.WorkspaceCreateOptions{
74-
AutoApply: &AutoApply,
75-
Name: &workspace,
84+
AutoApply: &AutoApply,
85+
Name: &workspace,
86+
TerraformVersion: getTerraformVersion(),
7687
}
7788
ws, err := t.Client.Workspaces.Create(context.TODO(), t.Organization, options)
7889
if err != nil {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package workspace
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestShouldGetTerraformVersionFromEnvVariable(t *testing.T) {
11+
expected := "0.11.0"
12+
os.Setenv("TF_VERSION", expected)
13+
actual := getTerraformVersion()
14+
os.Unsetenv("TF_VERSION")
15+
assert.Equal(t, expected, *actual)
16+
}
17+
18+
func TestShouldGetTerraformVersionFromOperator(t *testing.T) {
19+
expected := "0.12.25"
20+
actual := getTerraformVersion()
21+
assert.Equal(t, expected, *actual)
22+
}

operator/version/version.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package version
22

33
var (
4-
Version = "0.0.1"
4+
// Version of operator
5+
Version = "0.1.4-alpha"
6+
7+
// TerraformVersion for workspace default
8+
TerraformVersion = "0.12.25"
59
)

version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var (
1414
//
1515
// Version must conform to the format expected by
1616
// github.com/hashicorp/go-version for tests to work.
17-
Version = "0.0.1"
17+
Version = "0.1.4-alpha"
1818

1919
// A pre-release marker for the version. If this is "" (empty string)
2020
// then it means that it is a final release. Otherwise, this is a pre-release

0 commit comments

Comments
 (0)