diff --git a/api/v1alpha1/workspace_types.go b/api/v1alpha1/workspace_types.go index 6fbc6aad..cd68a112 100644 --- a/api/v1alpha1/workspace_types.go +++ b/api/v1alpha1/workspace_types.go @@ -144,6 +144,9 @@ type WorkspaceSpec struct { // Specifies the agent pool name we wish to use. // +optional AgentPoolName string `json:"agentPoolName,omitempty"` + // Specifies if the auto apply feature for the workspace is disabled or enabled + // +optional + DisableAutoApply bool `json:"disableAutoApply"` } // WorkspaceStatus defines the observed state of Workspace diff --git a/config/crd/bases/app.terraform.io_workspaces.yaml b/config/crd/bases/app.terraform.io_workspaces.yaml index 67e2c741..afbd2246 100644 --- a/config/crd/bases/app.terraform.io_workspaces.yaml +++ b/config/crd/bases/app.terraform.io_workspaces.yaml @@ -48,6 +48,9 @@ spec: agentPoolName: description: Specifies the agent pool name we wish to use. type: string + disableAutoApply: + description: Specifies if auto apply will be disabled or enabled + type: boolean module: description: Module source and version to use nullable: true diff --git a/workspacehelper/tfc_org.go b/workspacehelper/tfc_org.go index 4d3cb231..a44e9c6f 100644 --- a/workspacehelper/tfc_org.go +++ b/workspacehelper/tfc_org.go @@ -17,8 +17,6 @@ import ( ) var ( - // AutoApply run to workspace - AutoApply = true AgentPageSize = 100 ) @@ -217,8 +215,15 @@ func (t *TerraformCloudClient) CreateWorkspace(workspace string, instance *appv1 tfVersion = instance.Spec.TerraformVersion } + var autoApply bool + if instance.Spec.DisableAutoApply { + autoApply = false + } else { + autoApply = true + } + options := tfc.WorkspaceCreateOptions{ - AutoApply: &AutoApply, + AutoApply: &autoApply, Name: &workspace, TerraformVersion: &tfVersion, }