Skip to content

ENVBUILDER_GIT_SSH_PRIVATE_KEY_BASE64 not exist in .env output #83

@Ricky-Hao

Description

@Ricky-Hao
  1. Set ENVBUILDER_GIT_SSH_PRIVATE_KEY_BASE64 in locals.envbuilder_env.
  2. Pass locals.envbuilder_env to envbuilder_cached_image
  3. Pass envbuilder_cached_image.env to docker_container.env
  4. The ENVBUILDER_GIT_SSH_PRIVATE_KEY_BASE64 env does not exist in container's environment.
locals { container_name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}" devcontainer_builder_image = data.coder_parameter.devcontainer_builder.value git_author_name = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name) git_author_email = data.coder_workspace_owner.me.email repo_url = data.coder_parameter.repo.value == "custom" ? data.coder_parameter.custom_repo_url.value : data.coder_parameter.repo.value # The envbuilder provider requires a key-value map of environment variables. envbuilder_env = { # ENVBUILDER_GIT_URL and ENVBUILDER_CACHE_REPO will be overridden by the provider # if the cache repo is enabled. "ENVBUILDER_GIT_URL" : local.repo_url, "ENVBUILDER_CACHE_REPO" : var.cache_repo, "CODER_AGENT_TOKEN" : coder_agent.main.token, # Use the docker gateway if the access URL is 127.0.0.1 "CODER_AGENT_URL" : replace(data.coder_workspace.me.access_url, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal"), # Use the docker gateway if the access URL is 127.0.0.1 "ENVBUILDER_INIT_SCRIPT" : replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal"), "ENVBUILDER_FALLBACK_IMAGE" : data.coder_parameter.fallback_image.value, "ENVBUILDER_DOCKER_CONFIG_BASE64" : try(data.local_sensitive_file.cache_repo_dockerconfigjson[0].content_base64, ""), "ENVBUILDER_PUSH_IMAGE" : var.cache_repo == "" ? "" : "true", "ENVBUILDER_GIT_SSH_PRIVATE_KEY_BASE64": base64encode(data.coder_workspace_owner.me.ssh_private_key), "ENVBUILDER_INSECURE" : "${var.insecure_cache_repo}", } # Convert the above map to the format expected by the docker provider. docker_env = [ for k, v in local.envbuilder_env : "${k}=${v}" ] } resource "envbuilder_cached_image" "cached" { count = var.cache_repo == "" ? 0 : data.coder_workspace.me.start_count builder_image = local.devcontainer_builder_image git_url = local.repo_url cache_repo = var.cache_repo extra_env = local.envbuilder_env insecure = var.insecure_cache_repo cache_ttl_days = 90 } resource "docker_container" "workspace" { count = data.coder_workspace.me.start_count image = var.cache_repo == "" ? local.devcontainer_builder_image : envbuilder_cached_image.cached.0.image # Uses lower() to avoid Docker restriction on container names. name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}" # Hostname makes the shell more user friendly: coder@my-workspace:~$ hostname = data.coder_workspace.me.name # Use the environment specified by the envbuilder provider, if available. env = var.cache_repo == "" ? local.docker_env : envbuilder_cached_image.cached.0.env ... 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions