Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the ability to run terraform plan only #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions deploy/crds/tf.isaaguilar.com_terraforms_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/tf/v1alpha1/terraform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
24 changes: 20 additions & 4 deletions pkg/controllers/terraform_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down