Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
535 views
in Technique[技术] by (71.8m points)

kubernetes - 在Terraform配置中从销毁过程中排除资源(Exlude resources from the destroy process in terraform configuration)

I'm currently working on an fully managed by Terraform environment but I reached some limitations and I would like to know if there is a feature or a workaround to do what I want :

(我目前正在一个完全由Terraform环境管理的工作中,但是遇到了一些限制,我想知道是否有某个功能或解决方法可以实现我想要的功能:)

I have an environment described like that :

(我有一个这样描述的环境:)

  • A VPC with public and private subnets

    (具有公共和私有子网的VPC)

  • An EKS cluster with some workers

    (具有一些工人的EKS集群)

  • Some kubernetes configurations (using the kubernetes provider)

    (一些kubernetes配置(使用kubernetes提供程序))

  • Some helm configurations (using the helm provider)

    (一些头盔配置(使用头盔提供商))

Everything work, but when I want to do a full clean up by running terraform destroy I have to destroy some resources one by one with -target option and then delete manually some references in the state file.

(一切正常,但是当我想通过运行terraform destroy进行彻底清理时,必须使用-target选项逐个销毁一些资源,然后手动删除状态文件中的某些引用。)

Two reasons why I would like to do that:

(我想这样做的两个原因:)

  1. Just because it fails

    (只是因为失败)

    Don't know why, but I was unable to destroy with Terraform and manually some subnets (imposible to detach the internet gateway) but I was able to destroy them by simply destroying the VPC.

    (不知道为什么,但是我无法使用Terraform手动销毁某些子网(无法分离Internet网关),但是我能够通过销毁VPC销毁它们。)

    In this case, I would like to tell to Terraform to only delete the VPC, by doing that, AWS automatically destroy related components such as Subnets, Internet Gateway, Route table, Networks ACL, etc.

    (在这种情况下,我想告诉Terraform仅删除VPC,这样做,AWS会自动销毁相关组件,例如子网,Internet网关,路由表,网络ACL等。)

  2. Because it would be faster

    (因为这样会更快)

    I'm using Terraform with Kubernetes (and Helm) provider to define my Kubernetes configuration, but when I run terraform destroy it will delete all the Kubernetes resources, then the Cluster (and workers).

    (我正在使用带有Kubernetes(和Helm)提供程序的Terraform来定义我的Kubernetes配置,但是当我运行terraform destroy ,它将删除所有Kubernetes资源,然后是集群(和工作程序)。)

    Only deleting the Cluster would be really faster.

    (仅删除群集会更快。)


So here is my question : Is it possible to exclude resources to the destroy process in the Terraform configuration files ?

(所以这是我的问题: 是否可以在Terraform配置文件中排除破坏进程的资源?)

  ask by Martin Paucot translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have also seen terraform failures while destroying resources, needing manual intervention.

(我还看到破坏资源时需要手动干预的地形故障。)

The recommended way seems to be to modularise the required resources into separate configurations and then plan/destroy them as needed.

(推荐的方法似乎是将所需的资源模块化为单独的配置,然后根据需要计划/销毁它们。)

In your case, say a separate eks.tf for EKS configuration.

(对于您的情况,请为EKS配置说一个单独的eks.tf。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...