【问题标题】:Pull private module within Terraform docker container在 Terraform docker 容器中拉取私有模块
【发布时间】:2021-03-17 22:13:17
【问题描述】:

为了运行我的 Terraform,我有一个 docker-compose 设置,它会提取 hashcorp/terraform:light 图像,然后构建我的基础架构。

我最近介绍了一个私有模块,它位于我的私有 Github 存储库中。当我在我的机器上运行 terraform get 时它工作正常,但在 Docker compose 设置中我收到以下错误:

Could not download module "privateModule" (privateModule.tf:1) source code from
"git@github.com:sum/private.go.deploy.git": error downloading
'ssh://git@github.com/sum/private.go.deploy.git': /usr/bin/git exited with
128: Cloning into '.terraform/modules/privateModule'...
Warning: Permanently added 'github.com,140.82.121.3' (RSA) to the list of
known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我正在尝试将我的 SSH 密钥传递给容器,以便它可以提取私有 Github 存储库,但它似乎没有做任何事情。

version: '3.4'

services:
  terraform:
    image: hashicorp/terraform:light
    volumes:
      - .:/terraform
      - ~/.ssh:/.ssh
    working_dir: /terraform
    environment:
      - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
      - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
      - AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}

我的 Makefile 中的命令是:

tf-init:
    docker-compose run --rm terraform init

是否有可能让我的容器从 Git 中提取私有依赖项以与 Terraform 一起使用?

【问题讨论】:

    标签: git docker ssh terraform


    【解决方案1】:

    ssh 文件夹没有安装到正确的位置。

    通过将其安装到 root/.ssh 中,它解决了我的问题,我可以成功下载私有 Terraform 模块!

    version: '3.4'
    
    services:
      terraform:
        image: hashicorp/terraform:light
        volumes:
          - .:/terraform
          - ~/.ssh:/root/.ssh
        working_dir: /terraform
        environment:
          - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
          - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
          - AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}
    

    【讨论】:

      猜你喜欢
      • 2018-12-31
      • 1970-01-01
      • 1970-01-01
      • 2019-03-23
      • 2020-02-26
      • 2020-01-26
      • 2020-08-02
      • 1970-01-01
      • 2022-11-14
      相关资源
      最近更新 更多