ホームページ  >  記事  >  バックエンド開発  >  `bashicorp/terraform-exec` の `tf.Apply()` に `ApplyConfig` を渡すにはどうすればよいですか?

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

王林
王林転載
2024-02-09 10:50:29412ブラウズ

如何将 `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 までご連絡ください。