项目作者: overneath

项目描述 :
hashicorp/terraform `FROM scratch`
高级语言: Dockerfile
项目地址: git://github.com/overneath/terraform.git
创建时间: 2019-07-26T16:54:06Z
项目社区:https://github.com/overneath/terraform

开源协议:

下载


Nothin’ but Terraform

Hashicorp Terraform

But Why Though

I needed a minimal installation of hashicorp/terraform, downloaded and verified from the official Terraform downloads page. This serves as a simple, containerized installation source.

Docker

Please notice that the examples below do not specify image tags which means the Docker client will assume latest.

Container

The Terraform executable is statically compiled and set as the image entry ENTRYPOINT with help as the default CMD:

  1. # this container is not shipped with ca-certificates, so let's set those up.
  2. # (supporting version check, plugin discovery+download, provider api interactions ...)
  3. docker container run --rm -it -v ca-certificates:/etc/ssl/certs alpine apk add --no-cache ca-certificates
  4. # now we can invoke terraform
  5. docker container run --rm -it -v ca-certificates:/etc/ssl/certs -v /tmp -v $PWD:$PWD -w $PWD overneath/terraform # [init|plan|apply|destroy|...]
  1. Usage: terraform [-version] [-help] <command> [args]
  2. The available commands for execution are listed below.
  3. The most common, useful commands are shown first, followed by
  4. less common or more advanced commands. If you're just getting
  5. started with Terraform, stick with the common commands. For the
  6. other commands, please read the help and docs before usage.
  7. Common commands:
  8. apply Builds or changes infrastructure
  9. console Interactive console for Terraform interpolations
  10. destroy Destroy Terraform-managed infrastructure
  11. env Workspace management
  12. fmt Rewrites config files to canonical format
  13. get Download and install modules for the configuration
  14. graph Create a visual graph of Terraform resources
  15. import Import existing infrastructure into Terraform
  16. init Initialize a Terraform working directory
  17. output Read an output from a state file
  18. plan Generate and show an execution plan
  19. providers Prints a tree of the providers used in the configuration
  20. refresh Update local state file against real resources
  21. show Inspect Terraform state or plan
  22. taint Manually mark a resource for recreation
  23. untaint Manually unmark a resource as tainted
  24. validate Validates the Terraform files
  25. version Prints the Terraform version
  26. workspace Workspace management
  27. All other commands:
  28. 0.12upgrade Rewrites pre-0.12 module source code for v0.12
  29. debug Debug output management (experimental)
  30. force-unlock Manually unlock the terraform state
  31. push Obsolete command for Terraform Enterprise legacy (v1)
  32. state Advanced state management
  1. docker container run --rm -it -v ca-certificates:/etc/ssl/certs -v /tmp overneath/terraform -version
  1. Terraform v0.12.5

Note the -v /tmp is important because the current default behavior of Terraform is to exec itself to capture logs.
Running vanilla Terraform in a container lacking a /tmp directory will error, e.g.:

  1. docker container run --rm -it -v ca-certificates:/etc/ssl/certs overneath/terraform -version
  1. Couldn't setup logging tempfile: open /tmp/terraform-log076603776: no such file or directory

Dockerfile

To install into an image via Dockerfile:

  1. COPY --from=overneath/terraform /opt/local/ /usr/local/

Volume

To install into a container via docker volume leveraging (the default) nocopy=false behavior:

  1. # this only works if the volume `terraform-files` does not already exist or it is empty
  2. docker container run --rm --mount source=terraform-files,destination=/opt/local,volume-nocopy=false overneath/terraform
  3. docker container run --rm -it --volume terraform-files:/usr/local alpine terraform help