> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ubiquex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Go Runtime

> Compile your .iac source to Go — for teams that prefer static typing and fast compilation.

Go's appeal for infrastructure code is the same as its appeal for systems code: static typing that catches errors at compile time rather than runtime, fast compilation, a single static binary with no runtime dependencies, and explicit error handling that makes failure modes clear and auditable. Teams building platform tooling in Go — controllers, operators, CLIs — often find it natural to run their infrastructure in Go too. Set `runtime = "go"` in `ubx.iac` and ubx generates a `main.go` and `go.mod` — idiomatic Go code using the Pulumi Go SDK. The `.iac` source is still identical to tutorials 42 and 43. The generated Go is more verbose than the TypeScript or Python equivalents, but it's also the most explicit: every type is declared, every error is handled, and the dependency graph is visible in the code structure.

## What you'll learn

* What Go output ubx generates from a `.iac` stack
* How Go's explicit error handling appears in generated Pulumi programs
* The three-runtime comparison: TypeScript, Python, Go

***

## Why this matters

<Info>
  Go runtime produces a fully static binary — no Node.js, no Python runtime, no virtualenv. In containerised CI environments where you control the base image, a Go Pulumi program has the smallest footprint and the most predictable execution environment.
</Info>

***

## The source code

<CodeGroup>
  ```hcl main.iac theme={"theme":"css-variables"}
  # Identical source to tutorials 42 and 43 — only ubx.iac changes.
  unit "aws_s3_bucket_v2" "store" {
    bucket = "myapp-${input.env}-store"
  }
  ```

  ```hcl inputs.iac theme={"theme":"css-variables"}
  input "env" {
    type    = "string"
    default = "dev"
  }
  ```

  ```hcl outputs.iac theme={"theme":"css-variables"}
  output "bucket_name" {
    value = unit.aws_s3_bucket_v2.store.bucket
  }
  ```

  ```hcl ubx.iac theme={"theme":"css-variables"}
  ubx {
    name    = "runtime-go"
    runtime = "go"
    stacks  = ["dev", "staging", "prod"]
  }

  backend "local" {
    path = ".ubx/state"
  }
  ```
</CodeGroup>

***

## What ubx generates

<CodeGroup>
  ```go main.go theme={"theme":"css-variables"}
  // Generated by ubx — do not edit
  package main

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

  func main() {
      pulumi.Run(func(ctx *pulumi.Context) error {
          cfg := config.New(ctx, "")
          env := cfg.Get("env")
          if env == "" {
              env = "dev"
          }

          store, err := s3.NewBucketV2(ctx, "store", &s3.BucketV2Args{
              Bucket: pulumi.Sprintf("myapp-%s-store", env),
          })
          if err != nil {
              return err
          }

          ctx.Export("bucketName", store.Bucket)
          return nil
      })
  }
  ```

  ```go go.mod theme={"theme":"css-variables"}
  module runtime-go

  go 1.21

  require (
      github.com/pulumi/pulumi/sdk/v3 v3.0.0
      github.com/pulumi/pulumi-aws/sdk/v6 v6.0.0
  )
  ```
</CodeGroup>

***

## All three runtimes — side by side

The same S3 bucket in TypeScript, Python, and Go:

```typescript theme={"theme":"css-variables"}
// TypeScript
const store = new aws.s3.BucketV2("store", { bucket: `myapp-${env}-store` });
export const bucketName = store.bucket;
```

```python theme={"theme":"css-variables"}
# Python
store = aws.s3.BucketV2("store", bucket=f"myapp-{env}-store")
pulumi.export("bucket_name", store.bucket)
```

```go theme={"theme":"css-variables"}
// Go
store, err := s3.NewBucketV2(ctx, "store", &s3.BucketV2Args{
    Bucket: pulumi.Sprintf("myapp-%s-store", env),
})
if err != nil { return err }
ctx.Export("bucketName", store.Bucket)
```

The Go version is more verbose but completely explicit — every operation, every error, every export is visible. ubx generates idiomatic Go that Go developers will recognise.

***

## Run it

```bash theme={"theme":"css-variables"}
ubx validate
ubx plan    # requires AWS credentials
ubx apply
```

***

## What you learned

<Check>`runtime = "go"` generates `main.go` + `go.mod` — idiomatic Go with explicit error handling</Check>
<Check>The `.iac` source is identical across all three runtimes — only `ubx.iac` changes</Check>
<Check>Go produces more verbose but maximally explicit code — every type, every error, every export declared</Check>

***

## Next steps

<CardGroup cols={2}>
  <Card title="Configuration as code (ubx block)" href="/v1/tutorials/45-ubx-block-config-as-code">
    Put all project config in a ubx { } block instead of ubx.yaml
  </Card>

  <Card title="TypeScript runtime" href="/v1/tutorials/42-runtime-typescript">
    Compare with the TypeScript output
  </Card>
</CardGroup>

***

<Info>
  Full runnable example: [github.com/ubiquex/ubx-examples/44-runtime-go](https://github.com/ubiquex/ubx-examples/tree/main/44-runtime-go)
</Info>
