From f1630865beda7187cd33fe5bd6d2184547e5d30c Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 11 Apr 2025 22:54:57 +0200 Subject: [PATCH] fix: Use build_args everywhere and update documentation (#681) Co-authored-by: Martin Wentzel --- docs/resources/container.md | 4 ++-- docs/resources/image.md | 5 ++--- examples/resources/docker_image/resource-build.tf | 2 +- internal/provider/resource_docker_image.go | 11 +---------- .../resources/docker_image/testCreateDockerImage.tf | 2 +- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/docs/resources/container.md b/docs/resources/container.md index 60fd4af8..2bd76607 100644 --- a/docs/resources/container.md +++ b/docs/resources/container.md @@ -42,6 +42,7 @@ resource "docker_image" "ubuntu" { - `container_read_refresh_timeout_milliseconds` (Number) The total number of milliseconds to wait for the container to reach status 'running' - `cpu_set` (String) A comma-separated list or hyphen-separated range of CPUs a container can use, e.g. `0-1`. - `cpu_shares` (Number) CPU shares (relative weight) for the container. +- `cpus` (String) Specify how much of the available CPU resources a container can use. e.g a value of 1.5 means the container is guaranteed at most one and a half of the CPUs - `destroy_grace_seconds` (Number) If defined will attempt to stop the container before destroying. Container will be destroyed after `n` seconds or on successful stop. - `devices` (Block Set) Bind devices to the container. (see [below for nested schema](#nestedblock--devices)) - `dns` (Set of String) DNS servers to use. @@ -50,7 +51,6 @@ resource "docker_image" "ubuntu" { - `domainname` (String) Domain name of the container. - `entrypoint` (List of String) The command to use as the Entrypoint for the container. The Entrypoint allows you to configure a container to run as an executable. For example, to run `/usr/bin/myprogram` when starting a container, set the entrypoint to be `"/usr/bin/myprogra"]`. - `env` (Set of String) Environment variables to set in the form of `KEY=VALUE`, e.g. `DEBUG=0` -- `cpus` (String) Specify how much of the available CPU resources a container can use. e.g a value of 1.5 means the container is guaranteed at most one and a half of the CPUs - `gpus` (String) GPU devices to add to the container. Currently, only the value `all` is supported. Passing any other value will result in unexpected behavior. - `group_add` (Set of String) Additional groups for the container user - `healthcheck` (Block List, Max: 1) A test to perform to check that the container is healthy (see [below for nested schema](#nestedblock--healthcheck)) @@ -67,7 +67,7 @@ resource "docker_image" "ubuntu" { - `memory_swap` (Number) The total memory limit (memory + swap) for the container in MBs. This setting may compute to `-1` after `terraform apply` if the target host doesn't support memory swap, when that is the case docker will use a soft limitation. - `mounts` (Block Set) Specification for mounts to be added to containers created as part of the service. (see [below for nested schema](#nestedblock--mounts)) - `must_run` (Boolean) If `true`, then the Docker container will be kept running. If `false`, then as long as the container exists, Terraform assumes it is successful. Defaults to `true`. -- `network_mode` (String) Network mode of the container. +- `network_mode` (String) Network mode of the container. See https://docs.docker.com/engine/network/ for more information. - `networks_advanced` (Block Set) The networks the container is attached to (see [below for nested schema](#nestedblock--networks_advanced)) - `pid_mode` (String) he PID (Process) Namespace mode for the container. Either `container:` or `host`. - `ports` (Block List) Publish a container's port(s) to the host. (see [below for nested schema](#nestedblock--ports)) diff --git a/docs/resources/image.md b/docs/resources/image.md index 50d33909..65d99e76 100644 --- a/docs/resources/image.md +++ b/docs/resources/image.md @@ -52,7 +52,7 @@ resource "docker_image" "zoo" { build { context = "." tag = ["zoo:develop"] - build_arg = { + build_args = { foo : "zoo" } label = { @@ -108,8 +108,7 @@ Required: Optional: - `auth_config` (Block List) The configuration for the authentication (see [below for nested schema](#nestedblock--build--auth_config)) -- `build_arg` (Map of String) Set build-time variables -- `build_args` (Map of String) Pairs for build-time variables in the form TODO +- `build_args` (Map of String) Pairs for build-time variables in the form of `ENDPOINT : "https://example.com"` - `build_id` (String) BuildID is an optional identifier that can be passed together with the build request. The same identifier can be used to gracefully cancel the build with the cancel request. - `cache_from` (List of String) Images to consider as cache sources - `cgroup_parent` (String) Optional parent cgroup for the container diff --git a/examples/resources/docker_image/resource-build.tf b/examples/resources/docker_image/resource-build.tf index 3dbbb741..89088214 100644 --- a/examples/resources/docker_image/resource-build.tf +++ b/examples/resources/docker_image/resource-build.tf @@ -3,7 +3,7 @@ resource "docker_image" "zoo" { build { context = "." tag = ["zoo:develop"] - build_arg = { + build_args = { foo : "zoo" } label = { diff --git a/internal/provider/resource_docker_image.go b/internal/provider/resource_docker_image.go index 2652b103..2f3936a1 100644 --- a/internal/provider/resource_docker_image.go +++ b/internal/provider/resource_docker_image.go @@ -88,15 +88,6 @@ func resourceDockerImage() *schema.Resource { Default: true, Optional: true, }, - "build_arg": { - Type: schema.TypeMap, - Description: "Set build-time variables", - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - ForceNew: true, - }, "label": { Type: schema.TypeMap, Description: "Set metadata for an image", @@ -230,7 +221,7 @@ func resourceDockerImage() *schema.Resource { }, "build_args": { Type: schema.TypeMap, - Description: "Pairs for build-time variables in the form TODO", + Description: "Pairs for build-time variables in the form of `ENDPOINT : \"https://example.com\"`", Optional: true, ForceNew: true, Elem: &schema.Schema{ diff --git a/testdata/resources/docker_image/testCreateDockerImage.tf b/testdata/resources/docker_image/testCreateDockerImage.tf index 1670def6..4eb6518c 100644 --- a/testdata/resources/docker_image/testCreateDockerImage.tf +++ b/testdata/resources/docker_image/testCreateDockerImage.tf @@ -4,7 +4,7 @@ resource "docker_image" "test" { context = "." dockerfile = "Dockerfile" force_remove = true - build_arg = { + build_args = { test_arg = "kenobi" } label = {