Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
3.1 KiB
Markdown
Raw Permalink Normal View History

Do an editorial pass over programming model docs (#2241) * Do an editorial pass over programming model docs This is an editorial pass over the programming model docs, as part of #1618. This includes rearranging ordering to minimize forward references, getting rid of anything that smells "TypeScript-only", restructuring headers so the ToC is a bit more structured, wordsmithing, fleshing out examples, and trying to simplify the presentation of content -- while also embellishing where it helps. This is not done. The Go and TypeScript pages are empty. There is still quite a number of TypeScript-only hyperlinks and terminology. * Add Vim swp files to gitignore * Use shortcodes to cut down on language-specific text/links This change adds some shortcodes for common language-specific text and associated links. For instance, outputs are Output in JS, Output<T> in TS, Output[T] in Python, Output in Go, and Output<T> in C#, and go to very different places hyperlink-wise. Because of the way our language switcher JavaScript works, we display the JS version by default until it kicks in and picks up the user's choice. This avoids awkward flashes in which all or none of the options are available or missing. I'm not done applying this to all possible codes, but at least it lays the foundation to start paying down this debt. * Fix a couple hygiene issues * Clarify conditional execution of apply * Fix input shortcode * Add shortcodes for most language-specific things This eliminates most (all?) of the language-specific texts and links in the programming model document, replaced with shortcodes. * Fix up some loose ends * Add Go language page and Get Started guides * Fix linter errors * Apply suggestions from code review Co-Authored-By: Christian Nunciato <c@nunciato.org> * Apply additional code review feedback * Use spaces, not tabs. * Use tailwind styles, not inline CSS. Co-authored-by: Christian Nunciato <christian@pulumi.com>
2020-01-21 19:34:59 -08:00
---
2023-06-02 21:41:36 -07:00
title_tag: "Go | Languages & SDKs"
meta_desc: An overview of how to use the Go language with Pulumi for infrastructure as code on any cloud (AWS, Azure, Google Cloud, Kubernetes, etc.).
2023-01-25 18:41:30 +00:00
title: Go
h1: Pulumi & Go
2023-06-08 16:15:52 -07:00
meta_image: /images/docs/meta-images/docs-meta.png
Do an editorial pass over programming model docs (#2241) * Do an editorial pass over programming model docs This is an editorial pass over the programming model docs, as part of #1618. This includes rearranging ordering to minimize forward references, getting rid of anything that smells "TypeScript-only", restructuring headers so the ToC is a bit more structured, wordsmithing, fleshing out examples, and trying to simplify the presentation of content -- while also embellishing where it helps. This is not done. The Go and TypeScript pages are empty. There is still quite a number of TypeScript-only hyperlinks and terminology. * Add Vim swp files to gitignore * Use shortcodes to cut down on language-specific text/links This change adds some shortcodes for common language-specific text and associated links. For instance, outputs are Output in JS, Output<T> in TS, Output[T] in Python, Output in Go, and Output<T> in C#, and go to very different places hyperlink-wise. Because of the way our language switcher JavaScript works, we display the JS version by default until it kicks in and picks up the user's choice. This avoids awkward flashes in which all or none of the options are available or missing. I'm not done applying this to all possible codes, but at least it lays the foundation to start paying down this debt. * Fix a couple hygiene issues * Clarify conditional execution of apply * Fix input shortcode * Add shortcodes for most language-specific things This eliminates most (all?) of the language-specific texts and links in the programming model document, replaced with shortcodes. * Fix up some loose ends * Add Go language page and Get Started guides * Fix linter errors * Apply suggestions from code review Co-Authored-By: Christian Nunciato <c@nunciato.org> * Apply additional code review feedback * Use spaces, not tabs. * Use tailwind styles, not inline CSS. Co-authored-by: Christian Nunciato <christian@pulumi.com>
2020-01-21 19:34:59 -08:00
menu:
languages:
2023-05-18 21:08:00 -07:00
identifier: go
weight: 4
aliases:
- /docs/intro/languages/go/
- /go/
- /golang/
Do an editorial pass over programming model docs (#2241) * Do an editorial pass over programming model docs This is an editorial pass over the programming model docs, as part of #1618. This includes rearranging ordering to minimize forward references, getting rid of anything that smells "TypeScript-only", restructuring headers so the ToC is a bit more structured, wordsmithing, fleshing out examples, and trying to simplify the presentation of content -- while also embellishing where it helps. This is not done. The Go and TypeScript pages are empty. There is still quite a number of TypeScript-only hyperlinks and terminology. * Add Vim swp files to gitignore * Use shortcodes to cut down on language-specific text/links This change adds some shortcodes for common language-specific text and associated links. For instance, outputs are Output in JS, Output<T> in TS, Output[T] in Python, Output in Go, and Output<T> in C#, and go to very different places hyperlink-wise. Because of the way our language switcher JavaScript works, we display the JS version by default until it kicks in and picks up the user's choice. This avoids awkward flashes in which all or none of the options are available or missing. I'm not done applying this to all possible codes, but at least it lays the foundation to start paying down this debt. * Fix a couple hygiene issues * Clarify conditional execution of apply * Fix input shortcode * Add shortcodes for most language-specific things This eliminates most (all?) of the language-specific texts and links in the programming model document, replaced with shortcodes. * Fix up some loose ends * Add Go language page and Get Started guides * Fix linter errors * Apply suggestions from code review Co-Authored-By: Christian Nunciato <c@nunciato.org> * Apply additional code review feedback * Use spaces, not tabs. * Use tailwind styles, not inline CSS. Co-authored-by: Christian Nunciato <christian@pulumi.com>
2020-01-21 19:34:59 -08:00
---
<img src="/logos/tech/logo-golang.png" align="right" width="150" style="padding:8px; margin-top: -64px">
Pulumi supports writing your infrastructure as code in the Go language built for any [supported version](https://go.dev/doc/devel/release#policy).
Do an editorial pass over programming model docs (#2241) * Do an editorial pass over programming model docs This is an editorial pass over the programming model docs, as part of #1618. This includes rearranging ordering to minimize forward references, getting rid of anything that smells "TypeScript-only", restructuring headers so the ToC is a bit more structured, wordsmithing, fleshing out examples, and trying to simplify the presentation of content -- while also embellishing where it helps. This is not done. The Go and TypeScript pages are empty. There is still quite a number of TypeScript-only hyperlinks and terminology. * Add Vim swp files to gitignore * Use shortcodes to cut down on language-specific text/links This change adds some shortcodes for common language-specific text and associated links. For instance, outputs are Output in JS, Output<T> in TS, Output[T] in Python, Output in Go, and Output<T> in C#, and go to very different places hyperlink-wise. Because of the way our language switcher JavaScript works, we display the JS version by default until it kicks in and picks up the user's choice. This avoids awkward flashes in which all or none of the options are available or missing. I'm not done applying this to all possible codes, but at least it lays the foundation to start paying down this debt. * Fix a couple hygiene issues * Clarify conditional execution of apply * Fix input shortcode * Add shortcodes for most language-specific things This eliminates most (all?) of the language-specific texts and links in the programming model document, replaced with shortcodes. * Fix up some loose ends * Add Go language page and Get Started guides * Fix linter errors * Apply suggestions from code review Co-Authored-By: Christian Nunciato <c@nunciato.org> * Apply additional code review feedback * Use spaces, not tabs. * Use tailwind styles, not inline CSS. Co-authored-by: Christian Nunciato <christian@pulumi.com>
2020-01-21 19:34:59 -08:00
2023-05-23 18:42:56 -07:00
<a class="btn btn-secondary" href="https://golang.org/doc/install" target="_blank" title="Install Go">Install Go</a>
Do an editorial pass over programming model docs (#2241) * Do an editorial pass over programming model docs This is an editorial pass over the programming model docs, as part of #1618. This includes rearranging ordering to minimize forward references, getting rid of anything that smells "TypeScript-only", restructuring headers so the ToC is a bit more structured, wordsmithing, fleshing out examples, and trying to simplify the presentation of content -- while also embellishing where it helps. This is not done. The Go and TypeScript pages are empty. There is still quite a number of TypeScript-only hyperlinks and terminology. * Add Vim swp files to gitignore * Use shortcodes to cut down on language-specific text/links This change adds some shortcodes for common language-specific text and associated links. For instance, outputs are Output in JS, Output<T> in TS, Output[T] in Python, Output in Go, and Output<T> in C#, and go to very different places hyperlink-wise. Because of the way our language switcher JavaScript works, we display the JS version by default until it kicks in and picks up the user's choice. This avoids awkward flashes in which all or none of the options are available or missing. I'm not done applying this to all possible codes, but at least it lays the foundation to start paying down this debt. * Fix a couple hygiene issues * Clarify conditional execution of apply * Fix input shortcode * Add shortcodes for most language-specific things This eliminates most (all?) of the language-specific texts and links in the programming model document, replaced with shortcodes. * Fix up some loose ends * Add Go language page and Get Started guides * Fix linter errors * Apply suggestions from code review Co-Authored-By: Christian Nunciato <c@nunciato.org> * Apply additional code review feedback * Use spaces, not tabs. * Use tailwind styles, not inline CSS. Co-authored-by: Christian Nunciato <christian@pulumi.com>
2020-01-21 19:34:59 -08:00
## Templates
The fastest way to get started is to use a template. The template will initialize a Pulumi project.
Do an editorial pass over programming model docs (#2241) * Do an editorial pass over programming model docs This is an editorial pass over the programming model docs, as part of #1618. This includes rearranging ordering to minimize forward references, getting rid of anything that smells "TypeScript-only", restructuring headers so the ToC is a bit more structured, wordsmithing, fleshing out examples, and trying to simplify the presentation of content -- while also embellishing where it helps. This is not done. The Go and TypeScript pages are empty. There is still quite a number of TypeScript-only hyperlinks and terminology. * Add Vim swp files to gitignore * Use shortcodes to cut down on language-specific text/links This change adds some shortcodes for common language-specific text and associated links. For instance, outputs are Output in JS, Output<T> in TS, Output[T] in Python, Output in Go, and Output<T> in C#, and go to very different places hyperlink-wise. Because of the way our language switcher JavaScript works, we display the JS version by default until it kicks in and picks up the user's choice. This avoids awkward flashes in which all or none of the options are available or missing. I'm not done applying this to all possible codes, but at least it lays the foundation to start paying down this debt. * Fix a couple hygiene issues * Clarify conditional execution of apply * Fix input shortcode * Add shortcodes for most language-specific things This eliminates most (all?) of the language-specific texts and links in the programming model document, replaced with shortcodes. * Fix up some loose ends * Add Go language page and Get Started guides * Fix linter errors * Apply suggestions from code review Co-Authored-By: Christian Nunciato <c@nunciato.org> * Apply additional code review feedback * Use spaces, not tabs. * Use tailwind styles, not inline CSS. Co-authored-by: Christian Nunciato <christian@pulumi.com>
2020-01-21 19:34:59 -08:00
From an empty directory, create a new project:
```bash
$ mkdir myproject && cd myproject
$ pulumi new go
```
This will create a `Pulumi.yaml` [project file](/docs/concepts/projects/) containing some minimal metadata about your project (including a name and description which you may wish to change) and a `main.go` file containing your program. The name of the directory is used as the project name in `Pulumi.yaml`. Use your favorite Go dependency manager (such as Go's built-in modules system, by running `go mod init` in your project's directory).
Do an editorial pass over programming model docs (#2241) * Do an editorial pass over programming model docs This is an editorial pass over the programming model docs, as part of #1618. This includes rearranging ordering to minimize forward references, getting rid of anything that smells "TypeScript-only", restructuring headers so the ToC is a bit more structured, wordsmithing, fleshing out examples, and trying to simplify the presentation of content -- while also embellishing where it helps. This is not done. The Go and TypeScript pages are empty. There is still quite a number of TypeScript-only hyperlinks and terminology. * Add Vim swp files to gitignore * Use shortcodes to cut down on language-specific text/links This change adds some shortcodes for common language-specific text and associated links. For instance, outputs are Output in JS, Output<T> in TS, Output[T] in Python, Output in Go, and Output<T> in C#, and go to very different places hyperlink-wise. Because of the way our language switcher JavaScript works, we display the JS version by default until it kicks in and picks up the user's choice. This avoids awkward flashes in which all or none of the options are available or missing. I'm not done applying this to all possible codes, but at least it lays the foundation to start paying down this debt. * Fix a couple hygiene issues * Clarify conditional execution of apply * Fix input shortcode * Add shortcodes for most language-specific things This eliminates most (all?) of the language-specific texts and links in the programming model document, replaced with shortcodes. * Fix up some loose ends * Add Go language page and Get Started guides * Fix linter errors * Apply suggestions from code review Co-Authored-By: Christian Nunciato <c@nunciato.org> * Apply additional code review feedback * Use spaces, not tabs. * Use tailwind styles, not inline CSS. Co-authored-by: Christian Nunciato <christian@pulumi.com>
2020-01-21 19:34:59 -08:00
To deploy your infrastructure, first build your Go program: `go build -o $(basename $(pwd))`. Then run `pulumi up` and Pulumi will perform the operations needed to deploy the infrastructure you have declared.
This `go` template is cloud agnostic, and you will need to install additional Go modules for the cloud provider of your choice. Additional templates are available that do this for you:
* `pulumi new aws-go`: creates a starter AWS Go project
* `pulumi new azure-go`: creates a starter Azure Go project
* `pulumi new gcp-go`: creates a starter Google Cloud Go project
## Pulumi Programming Model
The Pulumi programming model defines the core concepts you will use when creating infrastructure as code programs using
Pulumi. [Concepts](/docs/intro/concepts) describes these concepts
with examples available in Go. These concepts are made available to you in the Pulumi SDK.
The Pulumi SDK is available to Go developers in source form on GitHub. To learn more,
[refer to the Pulumi SDK Reference Guide](https://pkg.go.dev/github.com/pulumi/pulumi/sdk/v3/go/pulumi).
The Pulumi programming model includes a core concept of `Input` and `Output` values, which are used to track how outputs of one resource flow in as inputs to another resource. This concept is important to understand when getting started with Go and Pulumi, and the [Inputs and Outputs](/docs/concepts/inputs-outputs/) documentation is recommended to get a feel for how to work with this core part of Pulumi in common cases.
## Package Documentation
In addition to the standard packages the [Pulumi Registry](/registry/) houses 100+ Go packages.
### Standard Packages
<dl class="tabular">
<dt>Pulumi SDK</dt>
<dd><a href="https://pkg.go.dev/github.com/pulumi/pulumi/sdk/v3/go/pulumi">pulumi</a></dd>
</dl>