我想运行不包含特定资源的terraform

suk*_*kho 10 terraform

运行terraform并等待需要很长时间.所以我想运行它来排除花费最长时间执行的rds,或者我想只运行ec2资源.有没有办法在terraform中做这样的事情?

Sau*_*abh 47

添加到 Julio 的答案中,您可以通过以下方式定位多个资源:

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
Run Code Online (Sandbox Code Playgroud)

如果输出计划,则只需要在计划阶段指定参数:

terraform init
terraform plan \
  -target=resource_type1.resource_name1 \
  -target=resource_type2.resource_name1 \
  -out plan
terraform apply plan
Run Code Online (Sandbox Code Playgroud)


Jul*_*yes 12

你可以-target=resource像这样使用:

terraform plan -target=module.mymodule.aws_instance.myinstance
terraform apply -target=module.mymodule.aws_instance.myinstance
Run Code Online (Sandbox Code Playgroud)

要么

terraform plan -target=aws_instance.myinstance
terraform apply -target=aws_instance.myinstance
Run Code Online (Sandbox Code Playgroud)

  • 在否决答案之前,请注意,他实际上要求“排除”或“仅运行 ec2 资源”。经过这么长时间,排除功能请求仍然在 terraform 存储库中打开 https://github.com/hashicorp/terraform/issues/2253。 (12认同)
  • 如前所述 - 这与提问者的要求相反。如果要排除特定资源,一种方法是使用“terraform rm state resource.key”将其从状态中删除 (7认同)
  • 但这不是排除。这个包含。如果您只需要排除一种资源,但要包括其他99种资源....那么这很乏味 (4认同)
  • 不知道为什么,但在我的配置中,开关是: --target=aws_instance.myinstance (注意:两个破折号,一个破折号失败) (2认同)

use*_*062 6

我想运行它以排除花费最长时间的 rds

Terraform 目前不支持资源排除(也称为反向定位)。

问题#2253:“功能请求:反向定位/排除”

(感谢胡里奥·丹尼尔·雷耶斯的链接。)