0

要为 IBM Cloud 运行 Terraform,我们需要下载一个模块: Module

有没有办法将此模块放置在任何想要运行 terraform 调用的中央服务器上。所以任何使用它的人都可以访问它,而不是每次在本地机器上下载它来运行 terraform?

4

1 回答 1

0
terraform init -verify-plugins=false -plugin-dir=${SCRIPT_DIR}/plugins

#!/usr/bin/env bash

os=$([[ $(uname) == "Darwin" ]] && echo "darwin" || echo "linux")

plugins=$(echo -e "
  terraform-provider-aws/1.51.0/terraform-provider-aws_1.51.0_${os}_amd64.zip
  terraform-provider-archive/1.1.0/terraform-provider-archive_1.1.0_${os}_amd64.zip
  terraform-provider-external/1.0.0/terraform-provider-external_1.0.0_${os}_amd64.zip
  terraform-provider-local/1.1.0/terraform-provider-local_1.1.0_${os}_amd64.zip
  terraform-provider-null/1.0.0/terraform-provider-null_1.0.0_${os}_amd64.zip
  terraform-provider-random/2.0.0/terraform-provider-random_2.0.0_${os}_amd64.zip
  terraform-provider-template/1.0.0/terraform-provider-template_1.0.0_${os}_amd64.zip
  terraform-provider-terraform/1.0.2/terraform-provider-terraform_1.0.2_${os}_amd64.zip
  terraform-provider-tls/1.2.0/terraform-provider-tls_1.2.0_${os}_amd64.zip
  " | xargs )

for plugin in `echo $plugins`; do
  name=$(echo $plugin | cut -d'/' -f3 | cut -d'_' -f1)
  version=$(echo "$plugin" | cut -d'/' -f3 | cut -d'_' -f2)
  plug="${name}_v${version}_x4"

  if [ ! -f "$SCRIPT_DIR/plugins/$plug" ]; then
    wget -q $SCRIPT_DIR/plugins https://releases.hashicorp.com/$plugin -O plugin.zip
    unzip -q ./plugin.zip -d $SCRIPT_DIR/plugins
    rm -rf ./plugin.zip
  fi
done
于 2019-02-06T05:49:58.300 回答