From 5660627fab7afe1f5973433f3c1136f3afd34d40 Mon Sep 17 00:00:00 2001 From: Jochen Schreiber Date: Thu, 30 Jun 2022 12:07:53 +0200 Subject: [PATCH 1/2] AutoApply feature for workspace spec --- api/v1alpha1/workspace_types.go | 3 +++ config/crd/bases/app.terraform.io_workspaces.yaml | 3 +++ workspacehelper/tfc_org.go | 4 +--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/api/v1alpha1/workspace_types.go b/api/v1alpha1/workspace_types.go index 6fbc6aad..048f063d 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 worksace is disabled or enabled + // +optional + AutoApply bool `json:"autoApply"` } // 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..3bd1f858 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 + autoApply: + description: Specifies if auto apply will be disabled or enabled + type: bool module: description: Module source and version to use nullable: true diff --git a/workspacehelper/tfc_org.go b/workspacehelper/tfc_org.go index 4d3cb231..04a5e2bb 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 ) @@ -218,7 +216,7 @@ func (t *TerraformCloudClient) CreateWorkspace(workspace string, instance *appv1 } options := tfc.WorkspaceCreateOptions{ - AutoApply: &AutoApply, + AutoApply: &instance.Spec.AutoApply, Name: &workspace, TerraformVersion: &tfVersion, } From 04f759c403c08b67377291f78f978c6b60db5962 Mon Sep 17 00:00:00 2001 From: Jochen Schreiber Date: Thu, 30 Jun 2022 17:33:04 +0200 Subject: [PATCH 2/2] Reworked the autoApply feature --- api/v1alpha1/workspace_types.go | 4 ++-- config/crd/bases/app.terraform.io_workspaces.yaml | 4 ++-- workspacehelper/tfc_org.go | 9 ++++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/api/v1alpha1/workspace_types.go b/api/v1alpha1/workspace_types.go index 048f063d..cd68a112 100644 --- a/api/v1alpha1/workspace_types.go +++ b/api/v1alpha1/workspace_types.go @@ -144,9 +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 worksace is disabled or enabled + // Specifies if the auto apply feature for the workspace is disabled or enabled // +optional - AutoApply bool `json:"autoApply"` + 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 3bd1f858..afbd2246 100644 --- a/config/crd/bases/app.terraform.io_workspaces.yaml +++ b/config/crd/bases/app.terraform.io_workspaces.yaml @@ -48,9 +48,9 @@ spec: agentPoolName: description: Specifies the agent pool name we wish to use. type: string - autoApply: + disableAutoApply: description: Specifies if auto apply will be disabled or enabled - type: bool + 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 04a5e2bb..a44e9c6f 100644 --- a/workspacehelper/tfc_org.go +++ b/workspacehelper/tfc_org.go @@ -215,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: &instance.Spec.AutoApply, + AutoApply: &autoApply, Name: &workspace, TerraformVersion: &tfVersion, }