|
| 1 | +--- |
| 2 | +title: Plural Stacks |
| 3 | +description: API-Driven Infrastructure As Code CD |
| 4 | +--- |
| 5 | + |
| 6 | +The goal of Plural Stacks is to provide a scalable framework to manage infrastructure as code like Terraform, Ansible and Pulumi with a kubernetes-friendly, api-driven approach. The core workflow is as follows: |
| 7 | + |
| 8 | +* Declaratively define a stack with a type (terraform, ansible, etc), a location in a git repository to source code from, and a cluster on which it will execute |
| 9 | +* On each commit to the tracked git repository, a run is created which the Plural deployment operator will detect and execute on the targeted cluster |
| 10 | + - this allows users to fine grain permissions and network location of IaC runs where both are necessary to configure. |
| 11 | +* Plural will carefully execute the run for you, and besides basic information like communicating stdout to the UI, we will also gather and present useful information like inputs/outputs, terraform state diagrams and more |
| 12 | +* On PRs to the tracked repository, a "plan" run is also executed and comments posted on the relevant PR where possible. |
| 13 | + |
| 14 | +To get a better idea of the full power of the experience, feel free to take a look at this demo video (at 2x speed if you want to save some time): |
| 15 | + |
| 16 | +{% embed url="https://youtu.be/06WXbvw6p3w" aspectRatio="16 / 9" /%} |
| 17 | + |
| 18 | +# A Basic Stack |
| 19 | + |
| 20 | +The most common way to instantiate a stack is via Kubernetes CRD. This gives a flexible, modular way of recreating infrastructure with Terraform and pairs nicely with our PR Automation tooling for full self-service around IaC. |
| 21 | + |
| 22 | +Here's an example: |
| 23 | + |
| 24 | +```yaml |
| 25 | +apiVersion: deployments.plural.sh/v1alpha1 |
| 26 | +kind: InfrastructureStack |
| 27 | +metadata: |
| 28 | + name: gke-demo |
| 29 | + namespace: stacks |
| 30 | +spec: |
| 31 | + name: gke-demo |
| 32 | + type: TERRAFORM |
| 33 | + approval: true |
| 34 | + detach: false |
| 35 | + manageState: true |
| 36 | + |
| 37 | + configuration: |
| 38 | + version: 1.8.2 |
| 39 | + repositoryRef: |
| 40 | + name: fleet |
| 41 | + namespace: fleets |
| 42 | + clusterRef: |
| 43 | + name: mgmt |
| 44 | + namespace: infra |
| 45 | + workdir: gke-cluster |
| 46 | + git: |
| 47 | + ref: main |
| 48 | + folder: terraform |
| 49 | + files: |
| 50 | + - mountPath: /plural |
| 51 | + secretRef: |
| 52 | + name: gcp-creds |
| 53 | + environment: |
| 54 | + - name: GOOGLE_APPLICATION_CREDENTIALS |
| 55 | + value: /plural/creds.json |
| 56 | + - name: TF_VAR_cluster |
| 57 | + value: gke-demo |
| 58 | + - name: TF_VAR_tier |
| 59 | + value: dev |
| 60 | + - name: TF_VAR_fleet |
| 61 | + value: gke-dem |
| 62 | +``` |
| 63 | +
|
| 64 | +The meaning of this yaml is pretty self-documenting, we are: |
| 65 | +
|
| 66 | +* creating a `TERRAFORM` stack, so it will execute the standard terraform workflow |
| 67 | +* we're using Plural as the state store, removing the need to configure S3 or other backends manually |
| 68 | +* `approval` will be required before `terraform apply` will trigger, ensuring a human verifies the plan first to reduce misconfiguration risk |
| 69 | +* we're sourcing manifests from the `fleet` repository (referencing a `GitRepository` crd) |
| 70 | +* we're executing on the `mgmt` cluster (referencing a `Cluster` crd) |
| 71 | +* and we're executing in the `terraform/gke-cluster` folder |
| 72 | + |
| 73 | +You can also see you can bind files and environment variables into the environment, although it is still best practice to use IRSA, GKE workload identity or similar mechanisms for issuing cloud credentials. |
0 commit comments