terraform-controller
terraform-controller copied to clipboard
[Feature request] Skip destroy if no resource is actually created
Feature Request
Now we will dispatch destroy job if Configuration is deleted. However, sometimes no resources is created due to the wrong Configuration. In this case, we should detect the resource creation phase and skip the destroy phase depends on the situation.
1. What https://github.com/kubevela/kubevela/pull/3929 do
In deletion part, kubevela#3929 will set configuration.spec.forceDelete to true. Anything else is dealt with terraform-controller.
Origin Post
Hey, I know this is merged, but I realized when you have something wrong the deletion don't complete. For example, Imagine you go to the Cloud provider portal and delete the resource, terraform will fail to delete saying the resource doesn't exist, like this:
Error: Error: Subnet: (Name "subnet-1" / Virtual Network Name "vnet-1" / Resource Group "example1") was not found
The same happen if I accidentally make a mistake in a HCL and apply some components in an application, but try to delete after realize I did a mistake, the delete never happen.
I just did it on my test environment and can't delete the application even using force.

I receive a:
Deleting Application "vm-1"
force deleted the resources created by application
successfully cleanup the resources created by application, but fail to delete the application
Error: timed out waiting for the condition
Originally posted by @alisson276 in https://github.com/kubevela/kubevela/issues/3929#issuecomment-1143801240
Try two wrong applications below. vela delete -f works fine. No destroy Job will be created.
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: wrong-rds-db
spec:
components:
- name: wrong-rds-db
type: alibaba-rds-database
properties:
region: cn-hangzhou
existing_instance_id: FAKE_ID
database_name: first_database
password: U34rfwefwefffaked
account_name: first_db_account
Also see https://github.com/kubevela/terraform-controller/blob/master/controllers/configuration_controller.go#L365-L376
When forceDelete is set. No destroy Job is expected to be created.
After v0.7.10, Configuration can be deleted before it is fully created. PR https://github.com/kubevela/terraform-controller/pull/354 has supportted DeleteProvisioningResources feature gate.
This makes vela delete can works properly with wrong terraform Configuration.
DeleteProvisioningResources solves the second problem mentioned. The first case should be re-evaluate since the deleting resource in vendor portal is not a predictable action even with terraform itself. This kind of case should requires ops to get involved.