[英]Pull private module within Terraform docker container
To run my Terraform I have a docker-compose setup that pulls the hashcorp/terraform:light
image and then builds my infrastructure.要运行我的 Terraform,我有一个 docker-compose 设置,它可以提取
hashcorp/terraform:light
图像,然后构建我的基础架构。
I recently introduced a private module which sits in my private Github repo.我最近介绍了一个私有模块,它位于我的私有 Github 存储库中。 It works fine when I run
terraform get
on my machine but within the Docker compose set up I get the following error:当我在我的机器上运行
terraform get
时它工作正常,但在 Docker 组合设置中我收到以下错误:
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.
I am attempting to pass my SSH keys to the container so it can pull the private Github repo but it doesn't seem to do anything.我正在尝试将我的 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}
The command in my Makefile is:我的 Makefile 中的命令是:
tf-init:
docker-compose run --rm terraform init
Is there a possible way to allow my container to pull the private dependency from Git for use with Terraform?有没有办法让我的容器从 Git 中提取私有依赖项以与 Terraform 一起使用?
The ssh folder wasn't being mounted into the correct place. ssh 文件夹未安装到正确的位置。
By mounting it into root/.ssh
it fixed my issue and I can successfully download private Terraform modules!通过将其安装到
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}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.