Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 36 ยท Resources and Programs

Pulumi Programs in TypeScript, Python, Go, C#, Java and YAML

Compare the same Pulumi program in six languages: TypeScript, Python, Go, C#, Java and YAML. Learn naming conventions, how Outputs differ per language and how to choose one.

Pulumi supports several languages with the same engine and the same resources. The concepts (resources, inputs, outputs, stacks) are identical; what changes is syntax, naming style and a few type details. This lesson shows one small program, a bucket plus an object and an export, in each language, then compares the differences that matter when you choose.

All Pulumi code here is read-only: the real SDKs need the CLI and a cloud. The runnable stand-ins at the end use JavaScript only to demonstrate the naming-convention rules.

The program in six languages

TypeScript (Node.js):

TypeScript
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const bucket = new aws.s3.BucketV2("site", { tags: { team: "web" } });

new aws.s3.BucketObject("index", {
  bucket: bucket.id,
  content: "<h1>Hello</h1>",
  contentType: "text/html",
});

export const bucketName = bucket.id;

Python:

Python
import pulumi
import pulumi_aws as aws

bucket = aws.s3.BucketV2("site", tags={"team": "web"})

aws.s3.BucketObject(
    "index",
    bucket=bucket.id,
    content="<h1>Hello</h1>",
    content_type="text/html",
)

pulumi.export("bucket_name", bucket.id)

Go:

Go
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/s3"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		bucket, err := s3.NewBucketV2(ctx, "site", &s3.BucketV2Args{
			Tags: pulumi.StringMap{"team": pulumi.String("web")},
		})
		if err != nil {
			return err
		}
		_, err = s3.NewBucketObject(ctx, "index", &s3.BucketObjectArgs{
			Bucket:      bucket.ID(),
			Content:     pulumi.String("<h1>Hello</h1>"),
			ContentType: pulumi.String("text/html"),
		})
		if err != nil {
			return err
		}
		ctx.Export("bucketName", bucket.ID())
		return nil
	})
}

C#:

C#
using System.Collections.Generic;
using Pulumi;
using Pulumi.Aws.S3;

return await Deployment.RunAsync(() =>
{
    var bucket = new BucketV2("site", new BucketV2Args
    {
        Tags = { { "team", "web" } },
    });

    new BucketObject("index", new BucketObjectArgs
    {
        Bucket = bucket.Id,
        Content = "<h1>Hello</h1>",
        ContentType = "text/html",
    });

    return new Dictionary<string, object?> { ["bucketName"] = bucket.Id };
});

Java:

Java
public class App {
    public static void main(String[] args) {
        Pulumi.run(ctx -> {
            var bucket = new BucketV2("site", BucketV2Args.builder()
                .tags(Map.of("team", "web"))
                .build());

            new BucketObject("index", BucketObjectArgs.builder()
                .bucket(bucket.id())
                .content("<h1>Hello</h1>")
                .contentType("text/html")
                .build());

            ctx.export("bucketName", bucket.id());
        });
    }
}

YAML:

YAML
name: site
runtime: yaml
resources:
  site:
    type: aws:s3:BucketV2
    properties:
      tags:
        team: web
  index:
    type: aws:s3:BucketObject
    properties:
      bucket: ${site.id}
      content: "<h1>Hello</h1>"
      contentType: text/html
outputs:
  bucketName: ${site.id}

What differs between languages

Topic TypeScript Python Go C# / Java YAML
Property names camelCase snake_case PascalCase fields PascalCase / builder camelCase
Outputs Output<T> with apply Output[T] with apply pulumi.StringOutput etc. Output<T> ${res.prop} interpolation
Plain values as inputs direct direct wrap in pulumi.String(...) direct direct
Errors exceptions exceptions returned error exceptions validated by the engine
Loops and logic full language full language full language full language fn:: functions only
Tooling npm, tsc, ESLint pip, mypy go modules NuGet / Maven none

Go is the most verbose because every plain value must be wrapped to become an input type, and every constructor returns an error; Go 1.18+ generics help in newer helper APIs. YAML is the lightest for simple stacks but has no loops (it has fn:: built-in functions and, in newer versions, simple options such as dependsOn).

Reading configuration and exporting in each language

TypeScript
const config = new pulumi.Config();
const size = config.require("size");
Python
config = pulumi.Config()
size = config.require("size")
Go
cfg := config.New(ctx, "")
size := cfg.Require("size")

Naming follows the language, and the engine maps it to the provider's schema. That is why contentType (TypeScript) is content_type (Python) and ContentType (Go).

Choosing a language

  • Use the language your team already writes and reviews daily.
  • TypeScript has the widest example coverage and excellent editor completion.
  • Python suits data and ML teams and has strong scripting ergonomics.
  • Go fits teams that also write Kubernetes tooling or want a single static binary.
  • C#, Java and F# fit .NET and JVM shops with existing build pipelines.
  • YAML is good for small, static definitions, or for teaching.

You can mix languages across projects in one organization, and share components across languages through multi-language components (Components).

Stand-in: translating property names

The same property has a different spelling per language. This stand-in converts between them the way the generated SDKs do.

JS Stand-in: naming conventions

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Stand-in: one description, six renderers

JS Stand-in: render one resource as TypeScript or YAML

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What stays the same between the six languages?

    Only syntax, naming and type details differ.
  2. 2. Why does Go code wrap strings like pulumi.String("web")?

    Go's static types need explicit input types.
  3. 3. How is the same property typically spelled in Python?

    Python SDKs use snake_case.
  4. 4. Which language has no loops and conditionals of its own?

    YAML programs rely on built-in functions rather than a general-purpose language.

Summary

  • The same program works in TypeScript, Python, Go, C#, Java and YAML.
  • Property names follow each language's style; Go needs explicit input wrappers.
  • Outputs behave the same everywhere (apply or interpolation).
  • Choose the language your team already knows; YAML suits tiny static stacks.

Next: apply, interpolate and Output Helpers