简体   繁体   English

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

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

I am running a Gitlab CI runner on an Azure Red Hat Linux 7.9 VM which is air-gapped and cannot communicate with the outside world due to our network restrictions.我在 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. 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.

Obviously, with the prevailing network restrictions, the aforementioned Terraform command fails and subsequently the entire pipeline job fails.显然,在当前的网络限制下,上述 Terraform 命令失败,随后整个管道作业失败。 From what I've now established and bearing in mind our particular network setup and circumstances, I probably have two options:根据我现在建立的情况并考虑到我们特定的网络设置和情况,我可能有两个选择:

  1. Configure my GitLab pipeline with a Proxy to allow access to sites like registry.terraform.io.使用代理配置我的 GitLab 管道,以允许访问诸如 registry.terraform.io 之类的站点。 I have been provided a proxy address by the way, but I'm not entirely sure how to get this configured in GitLab.顺便说一句,我已经获得了一个代理地址,但我不完全确定如何在 GitLab 中配置它。 Will therefore appreciate some assistance with this.因此,将感谢一些帮助。

  2. It also appears I will be able to force my Terraform configuration to reference the required provider plugins locally or on an internal share.看来我将能够强制我的 Terraform 配置在本地或内部共享上引用所需的提供程序插件。 Again, any advice on how to set this up would be greatly appreciated, having spent hours poring over endless online material on both options without any success.同样,任何有关如何设置的建议都将不胜感激,因为他们花了数小时研究这两个选项的无穷无尽的在线材料,但没有任何成功。

Configure my GitLab pipeline with a Proxy使用代理配置我的 GitLab 管道

If you have a forward proxy available in your environment and want to have your CI jobs use that proxy, it's usually simply a matter of setting your HTTP_PROXY and HTTPS_PROXY variables.如果您的环境中有可用的转发代理,并且希望 CI 作业使用该代理,则通常只需设置HTTP_PROXYHTTPS_PROXY变量即可。 You can do this in your runner environment configuration or CI configuration.您可以在运行器环境配置或 CI 配置中执行此操作。 For example in a .gitlab-ci.yml you could add:例如在.gitlab-ci.yml你可以添加:

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

Refer to the official docs Running GitLab Runner Behind a Proxy for more information.有关更多信息,请参阅官方文档Running GitLab Runner Behind a Proxy


It also appears I will be able to force my Terraform configuration to reference the required provider plugins locally or on an internal share看来我将能够强制我的 Terraform 配置在本地或内部共享上引用所需的提供程序插件

You can use the filesystem mirror option to configure a terraform providers mirror that lives on your filesystem (requires terraform v0.13+).您可以使用文件系统镜像选项来配置位于文件系统上的terraform 提供程序镜像(需要 terraform v0.13+)。

By default, the directory .terraform.d/plugins can be used without any additional configuration (see implied mirrors ).默认情况下,目录.terraform.d/plugins无需任何额外配置即可使用(参见隐含镜像)。 When you have the provider files in your filesystem mirror, you won't need to download them from the internet.当您的文件系统镜像中有提供程序文件时,您无需从 Internet 下载它们。

Let's say for example you're using the graylog provider like this:例如,假设您正在使用这样的 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/... ) in an expected layout (packed or unpacked). 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/... )在预期的布局(打包或解包)。

You can make these files available by placing them on your runner and (for docker runners) mounting the files into the job using the volumes configuration .您可以通过将这些文件放在运行器上并(对于 docker 运行器)使用volumes配置将文件安装到作业中来使这些文件可用。

For example, say you have the providers on your runner host, you can mount them into your jobs with this configuration in the config.toml file (only needed for docker-based runners!)例如,假设您的运行程序主机上有提供程序,您可以使用config.toml文件中的此配置将它们安装到您的作业中(仅基于 docker 的运行程序需要!)

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

Then in your jobs, you can copy the provider files into the .terraform directory.然后在您的作业中,您可以将提供程序文件复制到.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