Skip to content

Commit

Permalink
Merge pull request #130 from lbergnehr/main
Browse files Browse the repository at this point in the history
fix(build): add env var to point to provider config
  • Loading branch information
kichristensen authored Jan 24, 2025
2 parents f8eefb8 + 531ebae commit 7234a37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/terraform/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/
unzip terraform_{{.ClientVersion}}_linux_amd64.zip -d /usr/bin && \
rm terraform_{{.ClientVersion}}_linux_amd64.zip
COPY {{.WorkingDir}}/{{.InitFile}} $BUNDLE_DIR/{{.WorkingDir}}/
RUN cd $BUNDLE_DIR/{{.WorkingDir}} && \
RUN cd $BUNDLE_DIR/{{.WorkingDir}} && mkdir -p /usr/local/share/terraform/plugins/
{{if .ProviderHost }}
tee <<EOF > provider_mirror.tfrc && terraform init -backend=false && mkdir -p /usr/local/share/terraform/plugins/ && cp --recursive .terraform/providers /usr/local/share/terraform/plugins/
ENV TF_CLI_CONFIG_FILE=$BUNDLE_DIR/{{.WorkingDir}}/provider_mirror.tfrc
RUN tee <<EOF > provider_mirror.tfrc && terraform init -backend=false && cp --recursive .terraform/providers /usr/local/share/terraform/plugins/
provider_installation {
direct {
exclude = ["registry.terraform.io/*/*"]
Expand All @@ -31,7 +32,7 @@ RUN cd $BUNDLE_DIR/{{.WorkingDir}} && \
}
EOF
{{ else }}
terraform init -backend=false && \
RUN terraform init -backend=false && \
rm -fr .terraform/providers && \
terraform providers mirror /usr/local/share/terraform/plugins
{{ end }}
Expand Down
2 changes: 2 additions & 0 deletions pkg/terraform/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ func TestMixin_Build(t *testing.T) {

if tc.expectedProviderHost != "" {
assert.Contains(t, gotOutput, tc.expectedProviderHost)
assert.Contains(t, gotOutput, "ENV TF_CLI_CONFIG_FILE=")
} else {
assert.NotContains(t, gotOutput, "network_mirror")
assert.NotContains(t, gotOutput, "TF_CLI_CONFIG_FILE")
}

assert.NotContains(t, "{{.", gotOutput, "Not all of the template values were consumed")
Expand Down

0 comments on commit 7234a37

Please sign in to comment.