Skip to content

Commit

Permalink
use k8s as a default backend (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: ibraheem Al Saady <ibraheemalsaady@ibraheems-MacBook-Pro-2.local>
  • Loading branch information
IbraheemAlSaady and ibraheem Al Saady authored May 30, 2022
1 parent 28da89f commit a6f610f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
13 changes: 13 additions & 0 deletions api/v1alpha1/terraform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,17 @@ func (t *Terraform) GetOwnerReference() metav1.OwnerReference {
}
}

// setBackendCfgIfNotExist sets the default backend to Kunernetes if not provided
func setBackendCfgIfNotExist(run *Terraform) {
if run.Spec.Backend == "" {
run.Spec.Backend = fmt.Sprintf(`backend "kubernetes" {
secret_suffix = "%s"
in_cluster_config = true
}
`, run.ObjectMeta.Name)
}
}

// runnerRBACName is the RBAC name that will be used in the role and service account creation
// if they're not found
const runnerRBACName string = "terraform-runner"
Expand All @@ -275,6 +286,8 @@ const runnerRBACName string = "terraform-runner"
// Secret to store the outputs if any, will be empty if no outputs are defined,
// Job to execute the workflow/run)
func (t *Terraform) CreateTerraformRun(namespacedName types.NamespacedName) (*batchv1.Job, error) {
setBackendCfgIfNotExist(t)

if err := createRbacConfigIfNotExist(runnerRBACName, namespacedName.Namespace); err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion config/samples/role-terraform-runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ metadata:
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "update"]
verbs: ["create", "get", "update", "list"]
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["create", "update", "watch", "get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
14 changes: 14 additions & 0 deletions config/samples/terraform-basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: run.terraform-operator.io/v1alpha1
kind: Terraform
metadata:
name: basic-module
spec:
terraformVersion: 1.1.7

module:
source: IbraheemAlSaady/test/module
version: 0.0.3

variables:
- key: length
value: "4"

0 comments on commit a6f610f

Please sign in to comment.