terraform-k8s
terraform-k8s copied to clipboard
Adding support for working-directory in CRD for workspace
Community Note
- Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request
Relates #138
Release note for CHANGELOG:
Adds support for setting working directory to the CRD.
Description
This PR adds to the CRD for the terraform workspace, allowing for the working directory property of the workspace to be set to something other than the repository root, making it possible to plan & apply terraform from subdirectories within a git repository using the terraform k8s operator.
apiVersion: app.terraform.io/v1alpha1
kind: Workspace
metadata:
name: demo
namespace: default
spec:
organization: example-org
secretsMountPath: "/tmp/secrets"
module:
source: "github.com/example-org/terraform-modules"
vcs:
token_id: "XX-XXXXXXXXXXX"
repo_identifier: "example-org/terraform-modules"
branch: main
ingress_submodules: false
workingDirectory: /modules/demo-module
variables:
- key: environment
value: "dev"
sensitive: false
environmentVariable: false
- key: region
value: "eu-west-1"
sensitive: false
environmentVariable: false
- key: TFC_WORKLOAD_IDENTITY_AUDIENCE
value: "example-org"
sensitive: false
environmentVariable: true
Output:
$ kubectl describe workspace
Name: demo
Namespace: default
Labels: <none>
Annotations: <none>
API Version: app.terraform.io/v1alpha1
Kind: Workspace
Metadata:
Creation Timestamp: 2023-01-24T13:34:43Z
Finalizers:
finalizer.workspace.app.terraform.io
Generation: 2
Managed Fields:
API Version: app.terraform.io/v1alpha1
Fields Type: FieldsV1
fieldsV1:
f:spec:
.:
f:module:
.:
f:source:
f:organization:
f:secretsMountPath:
f:vcs:
.:
f:branch:
f:repo_identifier:
f:token_id:
f:workingDirectory:
Manager: Go-http-client
Operation: Update
Time: 2023-01-24T13:34:43Z
API Version: app.terraform.io/v1alpha1
Fields Type: FieldsV1
fieldsV1:
f:metadata:
f:finalizers:
.:
v:"finalizer.workspace.app.terraform.io":
f:spec:
f:module:
f:version:
f:terraformVersion:
f:variables:
f:status:
.:
f:configVersionID:
f:workspaceID:
Manager: terraform-k8s
Operation: Update
Time: 2023-01-24T13:34:45Z
API Version: app.terraform.io/v1alpha1
Fields Type: FieldsV1
fieldsV1:
f:status:
f:runID:
f:runStatus:
Manager: terraform-k8s
Operation: Update
Subresource: status
Time: 2023-01-24T13:34:49Z
Resource Version: 32942851
UID: edb42054-3a99-45c3-b526-488c97e68592
Spec:
Module:
Source: github.com/example-org/terraform-modules
Version:
Organization: example-org
Secrets Mount Path: /tmp/secrets
Terraform Version:
Variables:
Environment Variable: false
Hcl: false
Key: environment
Sensitive: false
Value: dev
Environment Variable: false
Hcl: false
Key: region
Sensitive: false
Value: eu-west-1
Environment Variable: true
Hcl: false
Key: TFC_WORKLOAD_IDENTITY_AUDIENCE
Sensitive: false
Value: example-org
Vcs:
Branch: main
repo_identifier: example-org/terraform-modules
token_id: XX-XXXXXXXXXXX
Working Directory: /modules/demo-module
@arybolovlev @alexsomesan Any feedback on this PR would be appreciated please.
Looks like https://github.com/hashicorp/terraform-cloud-operator is a re-write of this repo and replacing the separate terraform-helm repo. @arybolovlev is there a roadmap for when this re-write is likely to come out of beta and replace terraform-k8s ?
It would be nice to see this get merged. We have multiple modules/sub-modules in the same repository, and the only way to get it working is by specifying the working directory.