Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Adding support for working-directory in CRD for workspace #156

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

robcoward
Copy link

@robcoward robcoward commented Jan 24, 2023

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

@hashicorp-cla
Copy link

hashicorp-cla commented Jan 24, 2023

CLA assistant check
All committers have signed the CLA.

@robcoward robcoward marked this pull request as ready for review January 24, 2023 14:03
robcoward added a commit to uptime-labs/terraform-helm that referenced this pull request Jan 24, 2023
@robcoward
Copy link
Author

@arybolovlev @alexsomesan Any feedback on this PR would be appreciated please.

@robcoward
Copy link
Author

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 ?

@gamunu gamunu requested a review from a team as a code owner March 29, 2023 11:35
@gamunu
Copy link

gamunu commented Mar 29, 2023

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants