Skip to content

Instantly share code, notes, and snippets.

@dirien
Last active April 6, 2023 16:10
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/6cd035c3538f8380fd6d8a7db3947972 to your computer and use it in GitHub Desktop.
Save dirien/6cd035c3538f8380fd6d8a7db3947972 to your computer and use it in GitHub Desktop.
OVH Terraform to Pulumi

Steps to success!

Step 1

Install tf2pulumi (e.g: brew install pulumi/tap/tf2pulumi or download the binary at https://github.com/pulumi/tf2pulumi)

Step 2

Install the Pulumi CLI if not present on your client.

Step 2.1

Install the OVH plugin with following command:

plugin install resource ovh v0.29.0 --server github://api.github.com/lbrlabs

Step 3

Create a Pulumi project in the same directory as the Terraform project you'd like to import and create a new Pulumi stack in your favourite language (here used go)

 pulumi new go -f

My demo ovh.tf is this:

variable "service_name" {
  type = string
  default = "test"
}

resource "ovh_cloud_project_kube" "example_cluster" {
  service_name = var.service_name
  name         = "example-cluster"
  region       = "GRA7"
}

resource "ovh_cloud_project_kube_nodepool" "example_nodepool" {
  service_name = var.service_name
  kube_id      = ovh_cloud_project_kube.example_cluster.id
  name         = "example-nodepool"
  flavor_name  = "b2-7"
  desired_nodes = 1
  max_nodes     = 2
  min_nodes     = 0
}

Step 4

Then run tf2pulumi which will write a file in the directory that contains the Pulumi project you just created:

tf2pulumi --target-language go

This will create the Pulumi program for you:

package main

import (
	"github.com/lbrlabs/pulumi-ovh/sdk/go/ovh/CloudProject"
	"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
	"github.com/pulumi/pulumi/sdk/v2/go/pulumi/config"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		cfg := config.New(ctx, "")
		serviceName := "test"
		if param := cfg.Get("serviceName"); param != "" {
			serviceName = param
		}
		exampleCluster, err := CloudProject.NewKube(ctx, "exampleCluster", &CloudProject.KubeArgs{
			ServiceName: pulumi.String(serviceName),
			Name:        pulumi.String("example-cluster"),
			Region:      pulumi.String("GRA7"),
		})
		if err != nil {
			return err
		}
		_, err = CloudProject.NewKubeNodePool(ctx, "exampleNodepool", &CloudProject.KubeNodePoolArgs{
			ServiceName:  pulumi.String(serviceName),
			KubeId:       exampleCluster.ID(),
			Name:         pulumi.String("example-nodepool"),
			FlavorName:   pulumi.String("b2-7"),
			DesiredNodes: pulumi.Int(1),
			MaxNodes:     pulumi.Int(2),
			MinNodes:     pulumi.Int(0),
		})
		if err != nil {
			return err
		}
		return nil
	})
}

Step 5

Party! 🎉

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