Skip to content

Instantly share code, notes, and snippets.

@dirien
Last active February 22, 2024 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirien/20673c6d268befe9d6d531c685103c74 to your computer and use it in GitHub Desktop.
Save dirien/20673c6d268befe9d6d531c685103c74 to your computer and use it in GitHub Desktop.
Austin Workshop

Civo Navigate Workshop: IaC with Pulumi

Prerequisites

If you run Pulumi for the first time, you will be asked to log in. Follow the instructions on the screen to login. You may need to create an account first, don't worry it is free. Or you handle the state of the different stacks yourself, and use pulumi login --local

Instructions

Create a new Pulumi project

pulumi new civo-javascript --name pulumi-civo-workshop --dir pulumi-civo-workshop

Wizard will ask you for the description of the project, and the stack name. You can leave the default values.

At the end the wizard will ask you to configure the project. You can skip this step by pressing Enter key.

civo:token: The token that allows you access your CIVO account:  
Saved config

Now open the index.js file and replace/argument the content with the following code:

"use strict";
const pulumi = require("@pulumi/pulumi");
const civo = require("@pulumi/civo");

const firewall = new civo.Firewall("civo-firewall", {
    name: "my-civo-firewall",
    region: "PHX1",
    createDefaultRules: true
})

const cluster = new civo.KubernetesCluster("civo-k3s-cluster", {
    name: "my-civo-k3s-cluster",
    pools: {
        nodeCount: 3,
        size: "g4s.kube.medium"
    },
    region: "PHX1",
    firewallId: firewall.id,
    applications: "cert-manager,rancher,metrics-server,traefik2-nodeport"
})

exports.clusterName = cluster.name
exports.kubeconfig = pulumi.secret(cluster.kubeconfig)

Run Pulumi Up

pulumi up

This command will show you a preview of all the resources and asks you if you want to deploy them. You can run dedicated commands to see the preview or to deploy the resources.

pulumi preview
# or
pulumi up

Create a new Stack

Pulumi Stacks are a great way to manage different environments and configurations.

To create a new stack, execute the following command.

pulumi stack init prod

This will create a new stack called prod. You can see all the available stacks with the following command.

pulumi stack ls

Destroy the stack

To destroy the stack, run the following command.

pulumi destroy
pulumi stack rm <stack-name>

Now Celebrate, You're Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment