Experimental support for Kotlin language in Pulumi.
This is a proof of concept. We really need your feedback before adding more features, improving the code and integrating with the Pulumi ecosystem.
- Pulumi Kotlin. The missing piece in Kotlin multi-platform by @jplewa
- Infrastructure as code done right with JVM by @lbialy
ℹ️ You can find more examples here.
import com.pulumi.gcp.compute.kotlin.ComputeFunctions
import com.pulumi.gcp.compute.kotlin.instance
import com.pulumi.kotlin.Pulumi
fun main() {
Pulumi.run { ctx ->
val debianImage = ComputeFunctions.getImage {
family("debian-11")
project("debian-cloud")
}
val instance = instance("gcp-sample-instance") {
args {
machineType("e2-micro")
zone("europe-central2-a")
tags("foo", "bar")
bootDisk {
autoDelete(true)
initializeParams {
image(debianImage.name)
}
}
networkInterfaces {
network("default")
}
metadata("foo" to "bar")
metadataStartupScript("echo hi > /test.txt")
serviceAccount {
scopes("cloud-platform")
}
}
}
ctx.export("instanceName", instance.name)
}
}
import com.pulumi.azurenative.compute.kotlin.enums.CachingTypes.ReadWrite
import com.pulumi.azurenative.compute.kotlin.enums.DiskCreateOptionTypes.FromImage
import com.pulumi.azurenative.compute.kotlin.enums.DiskDeleteOptionTypes.Delete
import com.pulumi.azurenative.network.kotlin.enums.IPAllocationMethod.Dynamic
import com.pulumi.azurenative.compute.kotlin.enums.StorageAccountTypes.Standard_LRS
import com.pulumi.azurenative.compute.kotlin.enums.VirtualMachineSizeTypes.Standard_B1s
import com.pulumi.azurenative.compute.kotlin.virtualMachine
import com.pulumi.azurenative.network.kotlin.networkInterface
import com.pulumi.azurenative.network.kotlin.subnet
import com.pulumi.azurenative.network.kotlin.virtualNetwork
import com.pulumi.azurenative.resources.kotlin.resourceGroup
import com.pulumi.kotlin.Pulumi
fun main() {
Pulumi.run { ctx ->
val resourceGroup = resourceGroup("azure-native-sample-vm")
val mainVirtualNetwork = virtualNetwork("virtual-network") {
args {
resourceGroupName(resourceGroup.name)
addressSpace {
addressPrefixes("10.0.0.0/16")
}
}
}
val internalSubnet = subnet("internal-subnet") {
args {
resourceGroupName(resourceGroup.name)
virtualNetworkName(mainVirtualNetwork.name)
addressPrefix("10.0.2.0/24")
}
}
val mainNetworkInterface = networkInterface("network-interface") {
args {
resourceGroupName(resourceGroup.name)
ipConfigurations {
name("testconfiguration1")
subnet {
id(internalSubnet.id)
}
privateIPAllocationMethod(Dynamic)
}
}
}
val virtualMachine = virtualMachine("virtual-machine") {
args {
resourceGroupName(resourceGroup.name)
networkProfile {
networkInterfaces {
id(mainNetworkInterface.id)
}
}
hardwareProfile {
vmSize(Standard_B1s)
}
storageProfile {
imageReference {
publisher("Canonical")
offer("UbuntuServer")
sku("16.04-LTS")
version("latest")
}
osDisk {
name("myosdisk1")
caching(ReadWrite)
createOption(FromImage)
managedDisk {
storageAccountType(Standard_LRS)
}
deleteOption(Delete)
}
}
osProfile {
computerName("hostname")
adminUsername("testadmin")
adminPassword("testpassword")
}
}
}
ctx.export("virtualMachineId", virtualMachine.id)
}
}
import com.pulumi.kotlin.Pulumi
import com.pulumi.kubernetes.apps.v1.kotlin.deployment
fun main() {
Pulumi.run { ctx ->
val deployment = deployment("nginx") {
args {
spec {
selector {
matchLabels("app" to "nginx")
}
replicas(1)
template {
metadata {
labels("app" to "nginx")
}
spec {
containers {
name("nginx")
image("nginx")
ports {
containerPort(80)
}
}
}
}
}
}
}
val name = deployment.metadata?.applyValue { it.name.orEmpty() }
ctx.export("name", name)
}
}
To install the latest Pulumi release, run the following (see full installation instructions for additional installation options):
$ curl -fsSL https://get.pulumi.com/ | sh
⚠️ There are no Kotlin-specific templates forpulumi new
yet. You need to use Java templates (e.g.aws-java
).
To create a new Pulumi project, you need to use the pulumi new
command.
$ mkdir pulumi-kotlin-demo && cd pulumi-kotlin-demo
$ pulumi new aws-java
$ mkdir pulumi-kotlin-demo && cd pulumi-kotlin-demo
$ pulumi new https://github.com/myhau/pulumi-templates/tree/add-template-for-java-gradle-with-kotlin-dsl/java-gradle-kts
ℹ️ See the section below for the full list of supported providers along with docs.
Copy the dependency
block from the table below (Supported providers) and paste it to your
pom.xml
. For example:
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-google-native-kotlin</artifactId>
<version>0.31.0.0</version>
</dependency>
Any existing Java-specific dependency can be replaced with its Kotlin-specific equivalent. For example:
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>aws</artifactId>
<version>5.42.0</version>
</dependency>
can be replaced with:
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-aws-kotlin</artifactId>
<version>5.42.0.0</version>
</dependency>
Similarly, when it comes to the base Pulumi dependency, you can replace this:
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>pulumi</artifactId>
<version>0.11.0</version>
</dependency>
with this:
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-kotlin</artifactId>
<version>0.11.0.0</version>
</dependency>
Copy the dependency from the table below (Supported providers) and paste it to your
build.gradle.kts
. For example:
implementation("org.virtuslab:pulumi-google-native-kotlin:0.31.0.0")
Any existing Java-specific dependency can be replaced with its Kotlin-specific equivalent. For example:
implementation("com.pulumi.aws:5.42.0")
can be replaced with:
implementation("org.virtuslab.pulumi-aws-kotlin:5.42.0.0")
Similarly, when it comes to the base Pulumi dependency, you can replace this:
implementation("com.pulumi:pulumi:0.11.0")
with this:
implementation("org.virtuslab:pulumi-kotlin:0.11.0.0")
⚠️ For now, docs viewable in your text editor (and Kotlin API docs hosted here) only include Java SDK example snippets.
Using IntelliJ is heavily recommended as it can guide you through type-safe Kotlin DSLs.
Additionally, there are two sources of documentation:
- Pulumi official docs (example for
google-native
) - Kotlin API docs (example for
google-native
)
Write the code that describes your resources:
import com.pulumi.kotlin.Pulumi
fun main() {
Pulumi.run { ctx ->
// your resources
}
}
For inspiration, see the "Provisioning a virtual machine on Google Cloud Platform" example above (it's from Pulumi Java docs for Google Native provider, rewritten to Pulumi Kotlin).
Run pulumi up
. This provisions all cloud resources declared in your code.
The table below lists the providers that are currently supported by Pulumi Kotlin SDK. A full list of all Pulumi providers can be found here.
These Kotlin libraries serve as a wrapper on top of corresponding Java libraries.
For convenience, they follow the same versioning pattern with an additional KOTLIN-PATCH
version
number (MAJOR.MINOR.PATCH.KOTLIN-PATCH
). For example, version 5.16.2.0
of Pulumi Kotlin AWS provider is a wrapper on
top of version 5.16.2
of Pulumi Java AWS provider.
If the additional index is incremented (e.g. to 5.16.2.1
), it means that some updates were made to our generator and
that the Kotlin code has been improved, but the underlying Java library remained the same.
Name | Version | Maven artifact | Gradle artifact | Maven Central | Pulumi official docs | Kotlin API docs |
---|---|---|---|---|---|---|
cloudflare | 4.16.0.2 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-cloudflare-kotlin</artifactId>
<version>4.16.0.2</version>
</dependency> |
implementation("org.virtuslab:pulumi-cloudflare-kotlin:4.16.0.2") |
link | link | link |
cloudflare | 5.45.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-cloudflare-kotlin</artifactId>
<version>5.45.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-cloudflare-kotlin:5.45.0.0") |
link | link | link |
slack | 0.4.10.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-slack-kotlin</artifactId>
<version>0.4.10.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-slack-kotlin:0.4.10.0") |
link | link | link |
github | 5.26.0.1 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-github-kotlin</artifactId>
<version>5.26.0.1</version>
</dependency> |
implementation("org.virtuslab:pulumi-github-kotlin:5.26.0.1") |
link | link | link |
github | 6.4.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-github-kotlin</artifactId>
<version>6.4.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-github-kotlin:6.4.0.0") |
link | link | link |
random | 4.16.8.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-random-kotlin</artifactId>
<version>4.16.8.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-random-kotlin:4.16.8.0") |
link | link | link |
gcp | 6.67.1.1 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-gcp-kotlin</artifactId>
<version>6.67.1.1</version>
</dependency> |
implementation("org.virtuslab:pulumi-gcp-kotlin:6.67.1.1") |
link | link | link |
gcp | 7.38.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-gcp-kotlin</artifactId>
<version>7.38.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-gcp-kotlin:7.38.0.0") |
link | link | link |
gcp | 8.12.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-gcp-kotlin</artifactId>
<version>8.12.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-gcp-kotlin:8.12.0.0") |
link | link | link |
google-native | 0.31.1.2 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-google-native-kotlin</artifactId>
<version>0.31.1.2</version>
</dependency> |
implementation("org.virtuslab:pulumi-google-native-kotlin:0.31.1.2") |
link | link | link |
aws | 5.43.0.1 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-aws-kotlin</artifactId>
<version>5.43.0.1</version>
</dependency> |
implementation("org.virtuslab:pulumi-aws-kotlin:5.43.0.1") |
link | link | link |
aws | 6.65.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-aws-kotlin</artifactId>
<version>6.65.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-aws-kotlin:6.65.0.0") |
link | link | link |
aws-native | 0.126.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-aws-native-kotlin</artifactId>
<version>0.126.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-aws-native-kotlin:0.126.0.0") |
link | link | link |
aws-native | 1.17.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-aws-native-kotlin</artifactId>
<version>1.17.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-aws-native-kotlin:1.17.0.0") |
link | link | link |
azure | 5.87.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-azure-kotlin</artifactId>
<version>5.87.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-azure-kotlin:5.87.0.0") |
link | link | link |
azure | 6.14.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-azure-kotlin</artifactId>
<version>6.14.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-azure-kotlin:6.14.0.0") |
link | link | link |
azure-native | 1.104.0.2 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-azure-native-kotlin</artifactId>
<version>1.104.0.2</version>
</dependency> |
implementation("org.virtuslab:pulumi-azure-native-kotlin:1.104.0.2") |
link | link | link |
azure-native | 2.78.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-azure-native-kotlin</artifactId>
<version>2.78.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-azure-native-kotlin:2.78.0.0") |
link | link | link |
kubernetes | 3.30.2.2 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-kubernetes-kotlin</artifactId>
<version>3.30.2.2</version>
</dependency> |
implementation("org.virtuslab:pulumi-kubernetes-kotlin:3.30.2.2") |
link | link | link |
kubernetes | 4.19.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-kubernetes-kotlin</artifactId>
<version>4.19.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-kubernetes-kotlin:4.19.0.0") |
link | link | link |
nomad | 0.4.1.2 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-nomad-kotlin</artifactId>
<version>0.4.1.2</version>
</dependency> |
implementation("org.virtuslab:pulumi-nomad-kotlin:0.4.1.2") |
link | link | link |
nomad | 2.4.1.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-nomad-kotlin</artifactId>
<version>2.4.1.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-nomad-kotlin:2.4.1.0") |
link | link | link |
docker | 3.6.1.3 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-docker-kotlin</artifactId>
<version>3.6.1.3</version>
</dependency> |
implementation("org.virtuslab:pulumi-docker-kotlin:3.6.1.3") |
link | link | link |
docker | 4.5.8.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-docker-kotlin</artifactId>
<version>4.5.8.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-docker-kotlin:4.5.8.0") |
link | link | link |
gitlab | 4.10.0.2 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-gitlab-kotlin</artifactId>
<version>4.10.0.2</version>
</dependency> |
implementation("org.virtuslab:pulumi-gitlab-kotlin:4.10.0.2") |
link | link | link |
gitlab | 5.0.2.2 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-gitlab-kotlin</artifactId>
<version>5.0.2.2</version>
</dependency> |
implementation("org.virtuslab:pulumi-gitlab-kotlin:5.0.2.2") |
link | link | link |
gitlab | 6.11.0.1 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-gitlab-kotlin</artifactId>
<version>6.11.0.1</version>
</dependency> |
implementation("org.virtuslab:pulumi-gitlab-kotlin:6.11.0.1") |
link | link | link |
gitlab | 7.0.2.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-gitlab-kotlin</artifactId>
<version>7.0.2.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-gitlab-kotlin:7.0.2.0") |
link | link | link |
gitlab | 8.6.1.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-gitlab-kotlin</artifactId>
<version>8.6.1.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-gitlab-kotlin:8.6.1.0") |
link | link | link |
digitalocean | 4.37.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-digitalocean-kotlin</artifactId>
<version>4.37.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-digitalocean-kotlin:4.37.0.0") |
link | link | link |
alicloud | 3.70.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-alicloud-kotlin</artifactId>
<version>3.70.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-alicloud-kotlin:3.70.0.0") |
link | link | link |
keycloak | 5.4.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-keycloak-kotlin</artifactId>
<version>5.4.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-keycloak-kotlin:5.4.0.0") |
link | link | link |
vault | 6.4.0.0 |
<dependency>
<groupId>org.virtuslab</groupId>
<artifactId>pulumi-vault-kotlin</artifactId>
<version>6.4.0.0</version>
</dependency> |
implementation("org.virtuslab:pulumi-vault-kotlin:6.4.0.0") |
link | link | link |
Pulumi Kotlin SDK is a proof of concept, we really need feedback before moving on.
- Create an issue in this repo or express your opinion in the existing "Support for idiomatic Kotlin" issue.
- Start a thread on #java channel (Pulumi community Slack).
- Book a meeting through Calendly and let's talk!