簡體   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