繁体   English   中英

如何在气隙环境中获取 GitLab CI 跑步者上的 Terraform 提供者

[英]How to get Terraform providers on GitLab CI runners in an air-gapped environment

我在 Azure Red Hat Linux 7.9 VM 上运行 Gitlab CI 运行器,由于我们的网络限制,它是气隙的,无法与外界通信。 In the.gitlab-ci.yml file of my GitLab pipeline, I run some Terraform commands including Terraform init which subsequently attempts to pull down the Terraform provider plugins from the default Hashicorp location.

显然,在当前的网络限制下,上述 Terraform 命令失败,随后整个管道作业失败。 根据我现在建立的情况并考虑到我们特定的网络设置和情况,我可能有两个选择:

  1. 使用代理配置我的 GitLab 管道,以允许访问诸如 registry.terraform.io 之类的站点。 顺便说一句,我已经获得了一个代理地址,但我不完全确定如何在 GitLab 中配置它。 因此,将感谢一些帮助。

  2. 看来我将能够强制我的 Terraform 配置在本地或内部共享上引用所需的提供程序插件。 同样,任何有关如何设置的建议都将不胜感激,因为他们花了数小时研究这两个选项的无穷无尽的在线材料,但没有任何成功。

使用代理配置我的 GitLab 管道

如果您的环境中有可用的转发代理,并且希望 CI 作业使用该代理,则通常只需设置HTTP_PROXYHTTPS_PROXY变量即可。 您可以在运行器环境配置或 CI 配置中执行此操作。 例如在.gitlab-ci.yml你可以添加:

variables:
  HTTP_PROXY: "http://proxy.mydomain.corp"
  HTTPS_PROXY: "http://proxy.mydomain.corp"

有关更多信息,请参阅官方文档Running GitLab Runner Behind a Proxy


看来我将能够强制我的 Terraform 配置在本地或内部共享上引用所需的提供程序插件

您可以使用文件系统镜像选项来配置位于文件系统上的terraform 提供程序镜像(需要 terraform v0.13+)。

默认情况下,目录.terraform.d/plugins无需任何额外配置即可使用(参见隐含镜像)。 当您的文件系统镜像中有提供程序文件时,您无需从 Internet 下载它们。

例如,假设您正在使用这样的 graylog 提供程序:

provider "graylog" {
  version          = "1.0.4"
  web_endpoint_uri = "https://graylog.example.com/api"
  api_version      = "v3"
  auth_name        = "admin"
  auth_password    = "password"
}

All you need are the requisite files -- namely, the zip files of the providers you need (eg, terraform-provider-graylog_1.0.4_linux_amd64.zip ), then in your job copy them into your .terraform.d plugins directory (eg , .terraform.d/plugins/... )在预期的布局(打包或解包)。

您可以通过将这些文件放在运行器上并(对于 docker 运行器)使用volumes配置将文件安装到作业中来使这些文件可用。

例如,假设您的运行程序主机上有提供程序,您可以使用config.toml文件中的此配置将它们安装到您的作业中(仅基于 docker 的运行程序需要!)

[runners.docker]
  # ...
  volumes = ["/path/to/plugins/from/host:/plugins/path/in/container:rw"]

然后在您的作业中,您可以将提供程序文件复制到.terraform目录中。

my_job:
  image: 
    name: hashicorp/terraform
    entrypoint: [""]
  before_script:
    - cp /plugins/path/in/container/ .terraform.d/plugins/ 
    - terraform init  # will get plugins from your local mirror

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM