安裝 Terraform

本頁面說明如何在Google Cloud Cloud Shell 和本機殼層中安裝 Terraform。Cloud Shell 是互動式殼層環境,可讓您透過網路瀏覽器學習及實驗 Google Cloud,並管理專案和資源 Google Cloud 。

如需搭配使用 Terraform 和 Google Cloud的入門指南,請參閱「Terraform for Google Cloud 快速入門」。

Cloud Shell

  1. 如要使用已設定 gcloud CLI 的線上終端機,請啟用 Cloud Shell:

    頁面底部會開啟 Cloud Shell 工作階段,並顯示指令列提示。工作階段可能要幾秒鐘的時間才能初始化。

  2. 如要安裝 Terraform CLI,請按照 HashiCorp 的操作說明操作。

    您可以自訂環境,在環境啟動時安裝 Terraform CLI,也可以將二進位檔安裝至主目錄,以便在工作階段間保留安裝項目。

  3. 執行下列指令,確認 Terraform 可供使用:

    terraform
    

    畫面會顯示如下的輸出內容:

    
    Usage: terraform [global options] <subcommand> [args]
    
    The available commands for execution are listed below.
    The primary workflow commands are given first, followed by
    less common or more advanced commands.
    
    Main commands:
      init          Prepare your working directory for other commands
      validate      Check whether the configuration is valid
      plan          Show changes required by the current configuration
      apply         Create or update infrastructure
      destroy       Destroy previously-created infrastructure
    
    
  4. 如要搭配使用 Terraform 和 Google Cloud,請確保在 Google Cloud中完成下列工作:

本機殼層

  1. 請按照 Terraform 提供的安裝說明操作。

  2. 執行下列指令,確認 Terraform 可供使用:

    terraform
    

    畫面會顯示如下的輸出內容:

    
     Usage: terraform [global options] <subcommand> [args]
    
    The available commands for execution are listed below.
    The primary workflow commands are given first, followed by
    less common or more advanced commands.
    
    Main commands:
      init          Prepare your working directory for other commands
      validate      Check whether the configuration is valid
      plan          Show changes required by the current configuration
      apply         Create or update infrastructure
      destroy       Destroy previously-created infrastructure
    
  3. 如要搭配使用 Terraform 和 Google Cloud,請確保在 Google Cloud中完成下列工作:

後續步驟