Pulumi logo
Get Started

    Slack
    Docs
    Registry
    Pulumi AI
    Contact Us
    Sign In

Docs Home
Pulumi IaC
Pulumi ESC
Pulumi Insights
Pulumi IDP
Pulumi Cloud
Packages
Tutorials

        Download & install

Get started
Concepts
Languages & SDKs
Clouds
Using Pulumi

    Organizing Projects & Stacks
    Least privilege security

Automation API

    Getting Started
    Concepts

Extending Pulumi
Policy as code

    Continuous delivery

Adopting Pulumi
Pulumi CLI

        Support

    Docs
    Pulumi IaC
    Using Pulumi
    Automation API
    Get started

Get started with Automation API

Pulumi’s Automation API enables you to provision your infrastructure programmatically using the Pulumi engine by exposing Pulumi programs and stacks as strongly-typed and composable building blocks.

In this guide, you will deploy an inline Pulumi program to create a static website using Automation API.
Prerequisites
Install Pulumi

    macOS
    Windows
    Linux 

choco install pulumi

Copy
Other installation options are available.

Test your new installation by running the `pulumi version` command:

pulumi version
v3.177.0

Copy

If this doesn't work, you may need to restart your terminal to ensure the directory containing the pulumi.exe command is on your PATH.

Install the required language runtime, if you have not already.
Install language runtime
Choose your language

    TypeScript
    JavaScript
    Python
    Go
    C#
    Java 

Install Go.

Pulumi requires a supported version of Go— this typically refers to the two most recent major releases. Note that Go calls 1.20, 1.21, etc. major releases, unlike semantic versioning. If you're using Linux, your distribution may not provide an up to date version of the Go compiler. To check what version of Go you have installed, use: go version.
Obtain a Pulumi access token

You’ll need a Pulumi access token so that your programs can store the resulting state in the Pulumi Cloud. The easiest way to obtain a token is to run pulumi login from the command line.
Define your Pulumi program

    TypeScript
    JavaScript
    Python
    Go
    C#
    Java 

First, define the Pulumi program you want to run as a function within your overall program. Note how it looks like a standard Pulumi program.
This tutorial is based on the inline_program example, which is a complete example of how to construct a simple Automation API program.

deployFunc := func(ctx *pulumi.Context) error {
    // Similar go git_repo_program, our program defines a s3 website.
    // Here we create the bucket.
    siteBucket, err := s3.NewBucketV2(ctx, "s3-website-bucket", nil)
    if err != nil {
        return err
    }

    // We define and upload our HTML inline.
    indexContent := `<html><head>
<title>Hello S3</title><meta charset="UTF-8">
</head>
<body><p>Hello, world!</p><p>Made with ❤️ with <a href="https://pulumi.com">Pulumi</a></p>
</body></html>
`

    ownershipControls, err := s3.NewBucketOwnershipControls(ctx, "ownership-controls", &s3.BucketOwnershipControlsArgs{
        Bucket: siteBucket.ID(),
        Rule: &s3.BucketOwnershipControlsRuleArgs{
            ObjectOwnership: pulumi.String("ObjectWriter"),
        },
    })
    if err != nil {
        return err
    }

    publicAccessBlock, err := s3.NewBucketPublicAccessBlock(ctx, "public-access-block", &s3.BucketPublicAccessBlockArgs{
        Bucket:          siteBucket.ID(),
        BlockPublicAcls: pulumi.Bool(false),
    })
    if err != nil {
        return err
    }

    website, err := s3.NewBucketWebsiteConfigurationV2(ctx, "website", &s3.BucketWebsiteConfigurationV2Args{
        Bucket: siteBucket.ID(),
        IndexDocument: &s3.BucketWebsiteConfigurationV2IndexDocumentArgs{
            Suffix: pulumi.String("index.html"),
        },
    })
    if err != nil {
        return err
    }
    // Upload our index.html.
    if _, err := s3.NewBucketObject(ctx, "index", &s3.BucketObjectArgs{
        Bucket:      siteBucket.ID(), // Reference to the s3.Bucket object.
        Content:     pulumi.String(indexContent),
        Acl:         pulumi.String("public-read"),
        Key:         pulumi.String("index.html"),               // Set the key of the object.
        ContentType: pulumi.String("text/html; charset=utf-8"), // Set the MIME type of the file.
    }, pulumi.DependsOn([]pulumi.Resource{
        publicAccessBlock,
        ownershipControls,
        website,
    })); err != nil {
        return err
    }

    // Export the website URL.
    ctx.Export("websiteUrl", website.WebsiteEndpoint)
    return nil
}

Copy
Associate with a stack

As with executing Pulumi programs through the CLI, you need to associate your Pulumi program with a Stack. Automation API provides methods to create or select stacks.

Here’s a convenient method to select an existing Stack or create one if none exists:

    TypeScript
    JavaScript
    Python
    Go
    C#
    Java 

projectName := "inlineS3Project"
stackName := "dev"
s, err := auto.UpsertStackInlineSource(ctx, stackName, projectName, deployFunc)

Copy

A Stack object operates within the context of a Workspace. A Workspace is the execution context containing a single Pulumi project, a program, and multiple stacks. Workspaces are used to manage the execution environment, providing various utilities such as plugin installation, environment configuration ($PULUMI_HOME), and creation, deletion, and listing of stacks. Because you are deploying AWS resources in this tutorial, you must install the AWS provider plugin within your Workspace so that your Pulumi program will have it available during execution.
Configure your provider plugins

The AWS plugin also needs configuration. You can provide that configuration just as you would with other Pulumi programs: either through stack configuration or environment variables. In this tutorial, you’ll use the Stack object to set the AWS region for the AWS provider plugin.

    TypeScript
    JavaScript
    Python
    Go
    C#
    Java 

err = w.InstallPlugin(ctx, "aws", "v4.0.0")
if err != nil {
  fmt.Printf("Failed to install program plugins: %v\n", err)
  os.Exit(1)
}

s.SetConfig(ctx, "aws:region", auto.ConfigValue{Value: "us-west-2"})

Copy
Invoke Pulumi commands against the stack

You’re now ready to execute commands against the Stack, including update, preview, refresh, destroy, import, and export. If you want to update the stack, invoke the update method (up) against the Stack object:

    TypeScript
    JavaScript
    Python
    Go
    C#
    Java 

res, err := s.Up(ctx, stdoutStreamer)
if err != nil {
  fmt.Printf("Failed to update stack: %v\n\n", err)
  os.Exit(1)
}

Copy

Notice how you can choose to have a callback function for standard output. In addition, the command returns a result of the update, which you can programmatically use to drive decisions within your program. For example, the result includes the stack outputs as well as a summary of the changes. This means you could choose to take different actions if there were no resources updated. Conversely, you could use the stack outputs to drive another Pulumi program within the same Automation program.

By now, you’ve hopefully gained a clearer understanding of how to utilize the Automation API. For additional ideas, see the Automation API examples.
On this page

    Prerequisites
    Install Pulumi
    Install language runtime
    Obtain a Pulumi access token
    Define your Pulumi program
    Associate with a stack
    Configure your provider plugins
    Invoke Pulumi commands against the stack

    Edit this Page
    Request a Change

Was this page helpful?
Yes
No

Pulumi is open source

© Pulumi 2025

    Terms & conditions
    Privacy policy
    Acceptable use policy
    Trademark usage
    Professional services agreement




make a simple golang api that creates a new machine on openstack based on api post payload