FROM alpine:latest

RUN apk add --no-cache curl unzip bash git

ARG TERRAFORM_VERSION=1.14.3
RUN curl -fsSL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -o terraform.zip && \
    unzip terraform.zip -d /usr/local/bin/ && \
    chmod +x /usr/local/bin/terraform && \
    rm -f terraform.zip

ARG TERRAGRUNT_VERSION=0.98.0
RUN curl -fsSL https://github.com/gruntwork-io/terragrunt/releases/download/v${TERRAGRUNT_VERSION}/terragrunt_linux_amd64 -o /usr/local/bin/terragrunt && \
    chmod +x /usr/local/bin/terragrunt

RUN mkdir -p /root/.terraform.d/plugins/registry.terraform.io

RUN mkdir -p /root/.terraform.d/plugins/registry.terraform.io/yandex-cloud/yandex/0.100.0/linux_amd64 && \
    curl -fsSL https://releases.hashicorp.com/terraform-provider-yandex/0.100.0/terraform-provider-yandex_0.100.0_linux_amd64.zip -o /tmp/yandex.zip && \
    unzip -q /tmp/yandex.zip -d /root/.terraform.d/plugins/registry.terraform.io/yandex-cloud/yandex/0.100.0/linux_amd64 && \
    chmod +x /root/.terraform.d/plugins/registry.terraform.io/yandex-cloud/yandex/0.100.0/linux_amd64/terraform-provider-yandex_* && \
    rm -f /tmp/yandex.zip

RUN mkdir -p /root/.terraform.d/plugins/registry.terraform.io/hashicorp/kubernetes/2.23.0/linux_amd64 && \
    curl -fsSL https://releases.hashicorp.com/terraform-provider-kubernetes/2.23.0/terraform-provider-kubernetes_2.23.0_linux_amd64.zip -o /tmp/kubernetes.zip && \
    unzip -q /tmp/kubernetes.zip -d /root/.terraform.d/plugins/registry.terraform.io/hashicorp/kubernetes/2.23.0/linux_amd64 && \
    chmod +x /root/.terraform.d/plugins/registry.terraform.io/hashicorp/kubernetes/2.23.0/linux_amd64/terraform-provider-kubernetes_* && \
    rm -f /tmp/kubernetes.zip

RUN mkdir -p /root/.terraform.d/plugins/registry.terraform.io/hashicorp/random/3.1.0/linux_amd64 && \
    curl -fsSL https://releases.hashicorp.com/terraform-provider-random/3.1.0/terraform-provider-random_3.1.0_linux_amd64.zip -o /tmp/random.zip && \
    unzip -q /tmp/random.zip -d /root/.terraform.d/plugins/registry.terraform.io/hashicorp/random/3.1.0/linux_amd64 && \
    chmod +x /root/.terraform.d/plugins/registry.terraform.io/hashicorp/random/3.1.0/linux_amd64/terraform-provider-random_* && \
    rm -f /tmp/random.zip

ENV TF_PLUGIN_CACHE_DIR=/root/.terraform.d/plugins
ENV TERRAGRUNT_TFPATH=/usr/local/bin/terraform

WORKDIR /workspace
