`bashicorp/terraform-exec` の `tf.Apply()` に `ApplyConfig` を渡すにはどうすればよいですか?

王林
リリース: 2024-02-09 10:50:29
転載
411 人が閲覧しました

如何将 `ApplyConfig` 传递给 `hashicorp / terraform-exec` 中的 `tf.Apply()`?

php エディターの Youzi が、「bashicorp/terraform-exec」の「tf.Apply()」に「ApplyConfig」を渡す方法を説明します。 Terraform デプロイメントに `bashicorp/terraform-exec` を使用する場合、`ApplyConfig` オブジェクトを作成することで `tf.Apply()` の動作を構成できます。このオブジェクトは、適切なデプロイメント操作のために `tf.Apply()` メソッドに渡されます。このようにして、展開プロセスを柔軟に制御し、カスタマイズされた構成ニーズを実装できます。実際のアプリケーションでは、特定のビジネス ニーズに応じて「ApplyConfig」オブジェクトのプロパティを設定して、最適な展開効果を実現できます。

質問内容

hach​​icorp/terraform-exec apply で golang sdk を使用して terraform に target を追加しようとしていますコマンド内の

理想的には、CLI の同等のコマンドは terraform apply --auto-approve --target 'module.example'

です。 ただし、applyoptions{}targetsapply() 関数に渡すと、次のエラーが発生します。

誰か私がここで何をしているのか指摘してもらえますか?

リーリー

エラー表示、無効な複合リテラル型 tfexec.applyoptioncompiler

package main

import (
    "context"

    "github.com/hashicorp/terraform-exec/tfexec"
)

func main() {
    // create a new tfexec.executor instance
    tf, err := tfexec.newterraform("/path/to/terraform/binary")
    if err != nil {
        panic(err)
    }
    err = tf.init(context.background(), tfexec.upgrade(true))
    if err != nil {
        panic(err)
    }
    // define the targets you want to apply
    targets := []string{"module.example", "module.another_example"}

    // create an applyoption with the targets
    applyoption := tfexec.applyoption{
        targets: targets,
    }

    // apply the terraform configuration with the defined targets
    err = tf.apply(context.background(), applyoption)
    if err != nil {
        panic(err)
    }
}
ログイン後にコピー

解決策

次のように機能すると思います:

リーリー

以上が`bashicorp/terraform-exec` の `tf.Apply()` に `ApplyConfig` を渡すにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ソース:stackoverflow.com
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!