Skip to content

Commit

Permalink
Merge pull request #143 from ytsarev/keep-cmd-env
Browse files Browse the repository at this point in the history
BUGFIX: keep environment when plugin cache enabled
  • Loading branch information
ytsarev authored Apr 4, 2023
2 parents 3929f0d + 42feed5 commit 0528f71
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
33 changes: 33 additions & 0 deletions examples/workspace-inline-aws.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: tf.upbound.io/v1beta1
kind: Workspace
metadata:
name: sample-inline
spec:
providerConfigRef:
name: aws-eu-west-1
forProvider:
source: Inline
module: |
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
tags = {
Name = var.vpcName
}
}
resource "aws_subnet" "main" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
}
output "vpc_id" {
value = aws_vpc.main.id
}
output "subnet_id" {
value = aws_subnet.main.id
}
variable "vpcName" {
description = "VPC name"
type = string
}
vars:
- key: vpcName
value: sample-tf-inline
8 changes: 4 additions & 4 deletions internal/terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ func (h Harness) Init(ctx context.Context, cache bool, o ...InitOption) error {
args := append([]string{"init", "-input=false", "-no-color"}, io.args...)
cmd := exec.CommandContext(ctx, h.Path, args...) //nolint:gosec
cmd.Dir = h.Dir
if !cache {
for _, e := range os.Environ() {
if strings.Contains(e, "TF_PLUGIN_CACHE_DIR") {
for _, e := range os.Environ() {
if strings.Contains(e, "TF_PLUGIN_CACHE_DIR") {
if !cache {
continue
}
cmd.Env = append(cmd.Env, e)
}
cmd.Env = append(cmd.Env, e)
}
cmd.Env = append(cmd.Env, "TF_CLI_CONFIG_FILE=./.terraformrc")
err := sem.Acquire(ctx, 1)
Expand Down

0 comments on commit 0528f71

Please sign in to comment.