0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

terraformのdocker環境の立ち上げ

Last updated at Posted at 2025-01-03

motivation

localstack, motoを利用してlocalの開発環境をdockerで立ち上げを想定していたが、
hashicorp/terraformを利用した際に、ttyを使えず、docker runベースでの開発になり用途が合わなかった。

entry pointを変更すれば上記は解決します。
entry pointについて
terraform image

aws-cliは考えず、着手できる状況を目指す。

TL;DR

alpineを利用してcontainerを作成し、terraformを有効化する。

Directory構成

tree .
.
├── Makefile
├── README.md
├── local-dev
│   ├── compose.yaml
│   └── tmp.terraform.dockerfile
└── terraform
    └── main.tf

compose.yamlについては、terraformのversion controlできればよいので、雑めに作成する。

local-dev/compose.yaml
services:
  terraform:
    container_name: terraform_container
    build:
      context: .
      dockerfile: tmp.terraform.dockerfile
      target: development
      args:
        TERRAFORM_VERSION: "1.10.3"
    tty: true
    volumes:
      - ../terraform:/usr/terraform
    networks:
      - internal

networks:
  internal: {}
local-dev/tmp.terraform.dockerfile
FROM alpine:latest as development

ARG TERRAFORM_VERSION

WORKDIR /usr/terraform

RUN wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip &&\
    unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip && rm terraform_${TERRAFORM_VERSION}_linux_amd64.zip &&\
    mv terraform /usr/bin/terraform
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?