diff --git a/deploy/crds/tf.isaaguilar.com_terraforms_crd.yaml b/deploy/crds/tf.isaaguilar.com_terraforms_crd.yaml index c4dcd36a..5c15b2c9 100644 --- a/deploy/crds/tf.isaaguilar.com_terraforms_crd.yaml +++ b/deploy/crds/tf.isaaguilar.com_terraforms_crd.yaml @@ -560,6 +560,10 @@ spec: required: - sshKeySecretRef type: object + terraformDryRun: + description: TerraformDryRun when true will run all stages except + apply. Default is false and all stages including apply are run. + type: boolean terraformModule: description: "TerraformModule is the terraform module scm address. Currently supports git protocol over SSH or HTTPS. \n Precedence diff --git a/pkg/apis/tf/v1alpha1/terraform_types.go b/pkg/apis/tf/v1alpha1/terraform_types.go index e2f56711..5da6c977 100644 --- a/pkg/apis/tf/v1alpha1/terraform_types.go +++ b/pkg/apis/tf/v1alpha1/terraform_types.go @@ -100,6 +100,10 @@ type TerraformSpec struct { // `inline-module.tf` TerraformModuleInline string `json:"terraformModuleInline,omitempty"` + // TerraformDryRun when true will run all stages except apply. Default is false + // and all stages including apply are run. + TerraformDryRun bool `json:"terraformDryRun,omitempty"` + // OutputsSecret will create a secret with the outputs from the module. All // outputs from the module will be written to the secret unless the user // defines "outputsToInclude" or "outputsToOmit". diff --git a/pkg/controllers/terraform_controller.go b/pkg/controllers/terraform_controller.go index 36b98556..3dd56bda 100644 --- a/pkg/controllers/terraform_controller.go +++ b/pkg/controllers/terraform_controller.go @@ -701,14 +701,24 @@ func checkSetNewStage(tf *tfv1alpha1.Terraform) bool { case tfv1alpha1.PodPlan: if tf.Spec.PostPlanScript != "" { podType = tfv1alpha1.PodPostPlan + } else if tf.Spec.TerraformDryRun { + reason = "COMPLETED_TERRAFORM_DRY_RUN" + podType = tfv1alpha1.PodNil + stageState = tfv1alpha1.StateComplete } else { podType = tfv1alpha1.PodApply interruptible = tfv1alpha1.CanNotBeInterrupt } case tfv1alpha1.PodPostPlan: - podType = tfv1alpha1.PodApply - interruptible = tfv1alpha1.CanNotBeInterrupt + if tf.Spec.TerraformDryRun { + reason = "COMPLETED_TERRAFORM_DRY_RUN" + podType = tfv1alpha1.PodNil + stageState = tfv1alpha1.StateComplete + } else { + podType = tfv1alpha1.PodApply + interruptible = tfv1alpha1.CanNotBeInterrupt + } // // apply types @@ -753,14 +763,20 @@ func checkSetNewStage(tf *tfv1alpha1.Terraform) bool { case tfv1alpha1.PodPlanDelete: if tf.Spec.PostPlanDeleteScript != "" { podType = tfv1alpha1.PodPostPlanDelete + } else if tf.Spec.TerraformDryRun { + podType = tfv1alpha1.PodNil } else { podType = tfv1alpha1.PodApplyDelete interruptible = tfv1alpha1.CanNotBeInterrupt } case tfv1alpha1.PodPostPlanDelete: - podType = tfv1alpha1.PodApplyDelete - interruptible = tfv1alpha1.CanNotBeInterrupt + if tf.Spec.TerraformDryRun { + podType = tfv1alpha1.PodNil + } else { + podType = tfv1alpha1.PodApplyDelete + interruptible = tfv1alpha1.CanNotBeInterrupt + } // // apply (delete) types