>  기사  >  백엔드 개발  >  `hashicorp/terraform-exec`에서 `ApplyConfig`를 `tf.Apply()`에 전달하는 방법은 무엇입니까?

`hashicorp/terraform-exec`에서 `ApplyConfig`를 `tf.Apply()`에 전달하는 방법은 무엇입니까?

王林
王林앞으로
2024-02-09 10:50:29408검색

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

php 편집기 Yuzi가 `hashicorp/terraform-exec`에서 `ApplyConfig`를 `tf.Apply()`에 전달하는 방법을 설명할 것입니다. Terraform 배포에 `hashicorp/terraform-exec`를 사용하는 경우 `ApplyConfig` 객체를 생성하여 `tf.Apply()`의 동작을 구성할 수 있습니다. 그런 다음 이 객체는 적절한 배포 작업을 위해 `tf.Apply()` 메서드에 전달됩니다. 이러한 방식으로 배포 프로세스를 유연하게 제어하고 사용자 정의된 구성 요구 사항을 구현할 수 있습니다. 실제 애플리케이션에서는 특정 비즈니스 요구 사항에 따라 'ApplyConfig' 개체의 속성을 설정하여 최상의 배포 효과를 얻을 수 있습니다.

질문 내용

hashicorp/terraform-exec에서 golang SDK를 사용하여 terraform apply ​​​​commandtarget

을 추가하려고 합니다. 이상적으로 cli에 해당하는 명령은

terraform apply --auto-approve --target 'module.example'

입니다. 그런데 함수에

를 추가하면 다음과 같은 오류가 발생합니다. applyoptions{} 中的 targets 传递给 apply()

누군가 내가 여기서 뭘 하고 있는지 지적해 줄 수 있나요?

으아악

오류 표시,

invalid 复合文字类型 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)
    }
}

Solution

다음이 효과가 있을 것 같아요:

으아악

위 내용은 `hashicorp/terraform-exec`에서 `ApplyConfig`를 `tf.Apply()`에 전달하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 stackoverflow.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제