본문 바로가기

개발하자

특정 리소스에 대해서만 테라폼을 실행하려고 합니다

반응형

특정 리소스에 대해서만 테라폼을 실행하려고 합니다

테라폼을 실행하고 기다리는 시간이 오래 걸린다. 그래서 가장 오랜 시간이 걸리는 rds를 제외하고 실행하거나 ec2 resource만 실행하고 싶습니다. 그런 것들을 테라폼으로 할 수 있는 방법이 있을까요?




다음과 같이 사용할 수 있습니다:

terraform plan -target=module.mymodule.aws_instance.myinstance
terraform apply -target=module.mymodule.aws_instance.myinstance

아니면

terraform plan -target=aws_instance.myinstance
terraform apply -target=aws_instance.myinstance

: 답변을 부결시키기 전에, 그들은 실제로 "제외" 또는 "EC2 리소스만 실행"할 것을 요청했다는 점에 유의하시기 바랍니다. 그리고 시간이 많이 흘렀지만 테라폼 레포에는 여전히 열려있다.




가장 오래 걸리는 rds를 제외하기 위해 실행하고 싶습니다

테라폼은 현재 리소스 배제(일명 역타겟팅)를 지원하지 않는다.

이슈 #2253: "기능 요청: 역타겟팅/제외"

(Julio Daniel Reyes 링크 감사합니다.)




Julio's를 추가하면 다음과 같은 방식으로 리소스를 여러 개 사용할 수 있습니다:

terraform init
terraform plan -target=resource_type1.resource_name1 -target=resource_type2.resource_name1
terraform apply -target=resource_type1.resource_name1 -target=resource_type2.resource_name1

계획을 출력하는 경우 계획 단계 중에 파라미터만 지정하면 됩니다:

terraform init
terraform plan \
  -target=resource_type1.resource_name1 \
  -target=resource_type2.resource_name1 \
  -out plan
terraform apply plan



사용하시는 분들께

terraform plan -var-file dev.tfvars -target=module.mymodule.aws_instance.myinstance
terraform apply -var-file dev.tfvars -target=module.mymodule.aws_instance.myinstance



이것이 확실한 해결책은 아니지만, 이 도구는 유용할 수 있다.

도구 " tftarget"은 " terraform xxx -target={..."을 선택적으로 실행하도록 설계되었습니다...}".

선택 화면에는 '모두 선택' 등의 옵션이 포함되어 있어 먼저 모든 리소스를 선택한 후 불필요한 리소스의 선택을 취소함으로써 '역표적' 효과를 얻을 수 있어야 한다.

https://github.com/future-architect/tftarget

이미지 설명을 여기에 입력합니다




대부분의 답이 내 테라폼 버전에 맞지 않는다. 이 구문은 내게 도움이 된다:

terraform plan -target aws_resource.resource_name
terraform apply -target aws_resource.resource_name

반응형