hc-install cli throws an chmod error for terraform modules
sspans-sbp opened this issue · comments
The cli tries to chown extracted binaries, but fails to handle the naming conventions used for terraform modules.
root@cd8ecc68d197:~# hc-install install --version 3.48.0 terraform-provider-azurerm
hc-install: will install terraform-provider-azurerm@3.48.0
failed to install terraform-provider-azurerm@3.48.0: chmod /root/terraform-provider-azurerm: no such file or directory
root@cd8ecc68d197:~# ls
terraform-provider-azurerm_v3.48.0_x5
root@cd8ecc68d197:~# hc-install install --version 2.44.0 terraform-provider-awshc-install: will install terraform-provider-aws@2.44.0
failed to install terraform-provider-aws@2.44.0: chmod /root/terraform-provider-aws: no such file or directory
root@cd8ecc68d197:~# ls
terraform-provider-aws_v2.44.0_x4
I'm impressed that it gets this far - I hadn't anticipated hc-install being used for terraform modules (or providers, as in this case). These are usually installed by terraform
itself and don't quite count as "HashiCorp products" as intended in hc-install's README.
What's the use case here - why not use terraform init
to download the provider to a plugin cache dir?
The use case is pre-populating a terraform plugin-cache in a docker image.
So the terraform config that will run is not available, but we do know which providers will be used and can preload them.
ENV VAULT_CLI_VERSION="1.13.1"
ENV TF_PLUGIN_CACHE_DIR="/usr/local/.terraform.d/plugin-cache/"
ENV TF_PROVIDER_AWS_VERSION="2.44.0"
ENV TF_PROVIDER_AZURERM_VERSION="3.48.0"
# Use hc-install to fetch vault
RUN apt-get update && apt-get install -y --no-install-recommends hc-install && \
hc-install install --path /usr/local/bin --version ${VAULT_CLI_VERSION} vault && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Setup Terraform providers and plugin cache
RUN mkdir -p ${TF_PLUGIN_CACHE_DIR} && cd ${TF_PLUGIN_CACHE_DIR} && \
hc-install install --version ${TF_PROVIDER_AWS_VERSION} terraform-provider-aws && \
hc-install install --version ${TF_PROVIDER_AZURERM_VERSION} terraform-provider-azurerm
# Setup Terraform installation
ENV TERRAFORM_14="0.14.11"
ENV TERRAFORM_LATEST="1.4.2"
ENV TFENV_GIT_INSTALL_DIR "/opt/tfenv/"
ENV TFENV_CONFIG_DIR "/opt/.tfenv"
# Clone tfenv, configure and use gpg for package verification during installation.
RUN git clone ${TF_URL} "${TFENV_GIT_INSTALL_DIR}" && \
mkdir -p "${TFENV_CONFIG_DIR}" && \
touch "${TFENV_CONFIG_DIR}/use-gnupg" && \
tfenv install ${TERRAFORM_14} && \
tfenv install ${TERRAFORM_LATEST} && \
tfenv use ${TERRAFORM_LATEST}
You can use terraform providers mirror
with a stub config to download providers.
For example, create a providers.tf
file with provider configuration blocks for the AWS and Azure providers, and load this into the Docker image. The config can then be discarded.
In general Terraform plugins are intended to be downloaded using the Terraform CLI, and are outside the scope of hc-install. If the solution above doesn't work then let's improve Terraform CLI.
I'm going to close this as there's nothing actionable on hc-install
's side per @kmoe's last comment. Please do let us know however if the proposed solution doesn't work for you - ideally in the Terraform repository: https://github.com/hashicorp/terraform/issues/new/choose