hashicorp / terraform-cloud-operator

Kubernetes Operator allows managing HCP Terraform resources via Kubernetes Custom Resources.
https://developer.hashicorp.com/terraform/cloud-docs
Mozilla Public License 2.0
114 stars 27 forks source link

🚀 Add annotations to the Workspace controller to trigger a new run #364

Closed arybolovlev closed 4 months ago

arybolovlev commented 4 months ago

Description

This PR adds three new annotations to the Workspace controller to trigger a new run.

Tests

Usage Example

$ kubectl annotate workspace this \
    workspace.app.terraform.io/run-new="true" \
    workspace.app.terraform.io/run-terraform-version=1.7.2 \
    workspace.app.terraform.io/run-type=plan --overwrite
apiVersion: app.terraform.io/v1alpha2
kind: Workspace
metadata:
  annotations:
    workspace.app.terraform.io/run-new: "true"
    workspace.app.terraform.io/run-type: plan
    workspace.app.terraform.io/run-terraform-version: 1.7.2
...
status:
  observedGeneration: 1
  plan:
    id: run-H1Ttm8HEP88xTW2w
    status: planned_and_finished
    terraformVersion: 1.7.2
  runStatus:
    configurationVersion: cv-ryQ2p4c1Ro4Jy23G
    id: run-iS61fqGde6WH49Np
    outputRunID: run-iS61fqGde6WH49Np
    status: applied
...

References

Community Note

patoarvizu commented 4 months ago

Is the intention of this feature to enable a behavior equivalent to setting queue_all_runs = true in the tfe_workspace resource of the TFE Terraform provider? Or am I misunderstanding?

I just gave this a try and I'm seeing the workspaces being created on TFC, but without any plans being automatically triggered. If I inspect the operator logs I see:

2024-03-22T21:25:19Z    ERROR   Reconcile Runs  {"workspace": {"name":"kubernetes-tfc-workspace","namespace":"tfc-operator-system"}, "msg": "failed to create a new plan run", "error": "resource not found"}
2024-03-22T21:25:19Z    ERROR   Reconcile Runs  {"workspace": {"name":"kubernetes-tfc-workspace","namespace":"tfc-operator-system"}, "msg": "failed to reconcile runs", "error": "resource not found"}
2024-03-22T21:25:19Z    ERROR   Workspace Controller    {"workspace": {"name":"kubernetes-tfc-workspace","namespace":"tfc-operator-system"}, "msg": "reconcile workspace", "error": "resource not found"}