Skip to content

Instantly share code, notes, and snippets.

@donovanmuller
Created June 22, 2020 20:23
Show Gist options
  • Save donovanmuller/a7575815f8cd62222bb5c8b6e264abdb to your computer and use it in GitHub Desktop.
Save donovanmuller/a7575815f8cd62222bb5c8b6e264abdb to your computer and use it in GitHub Desktop.
module test
go 1.14
require (
github.com/jaxxstorm/pulumi-rke/sdk/v2 v2.0.0-20200622042604-c09f47d0d6f2
github.com/pulumi/pulumi-packet/sdk/v2 v2.2.2
github.com/pulumi/pulumi/sdk/v2 v2.4.0
)
package main
import (
"io/ioutil"
"github.com/jaxxstorm/pulumi-rke/sdk/v2/go/rke"
"github.com/pulumi/pulumi-packet/sdk/v2/go/packet"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
project, err := packet.NewProject(ctx, "test", &packet.ProjectArgs{
Name: pulumi.String("Test"),
})
if err != nil {
return err
}
content, err := ioutil.ReadFile("./id_rsa_test.pub")
if err != nil {
return err
}
publicKeyContents := string(content)
_, err = packet.NewProjectSshKey(ctx, "default", &packet.ProjectSshKeyArgs{
Name: pulumi.String("default"),
ProjectId: project.ID(),
PublicKey: pulumi.String(publicKeyContents),
})
if err != nil {
return err
}
distro := "ubuntu"
version := "18.04"
operatingSystem, err := packet.GetOperatingSystem(ctx, &packet.GetOperatingSystemArgs{
Distro: &distro,
Version: &version,
})
if err != nil {
return err
}
amsterdamFacility := "8e6470b3-b75e-47d1-bb93-45b225750975"
device, err := packet.NewDevice(ctx, "node1", &packet.DeviceArgs{
BillingCycle: pulumi.String("hourly"),
Description: pulumi.String("RKE node"),
Facilities: pulumi.StringArray{pulumi.String(amsterdamFacility)},
Hostname: pulumi.String("node1.test.com"),
OperatingSystem: pulumi.String(operatingSystem.Id),
Plan: pulumi.String("baremetal_1"),
ProjectId: project.ID(),
})
if err != nil {
return err
}
cluster, err := rke.NewCluster(ctx, "test", &rke.ClusterArgs{
ClusterName: pulumi.String("test"),
Nodes: rke.ClusterNodeArray{rke.ClusterNodeArgs{
Address: device.AccessPublicIpv4,
InternalAddress: device.AccessPrivateIpv4,
Roles: pulumi.StringArray{
pulumi.String("controlplane"),
pulumi.String("etcd"),
pulumi.String("worker"),
},
User: pulumi.String("root"),
}},
SshKeyPath: pulumi.String("./id_rsa_test.pub"),
})
if err != nil {
return err
}
ctx.Export("kubeconfig", cluster.KubeConfigYaml)
return nil
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment