Add Go program illustrating use of an SSH-based Docker provider Signed-off-by: Scott Lowe <scott.lowe@scottlowe.org> |
||
|---|---|---|
| .. | ||
| go.mod | ||
| main.go | ||
| Pulumi.yaml | ||
| README.md | ||
Remote Docker Host via SSH on AWS Using Pulumi
These files were created to demonstrate how to create a Pulumi Docker provider that connects via SSH to a remote Flatcar Linux EC2 instance on AWS. This Pulumi program was written in Go.
Based on the "Flatcar Linux on AWS Using Pulumi" code, the Pulumi program here illustrates a couple useful patterns:
- Use of the
slices.Contains()method for checking configuration values passed in from the user - Using the Pulumiverse Time provider to introduce a delay in resource creation (allowing the EC2 instance to become ready)
- Configuring an explicit Docker provider to use SSH
Contents
-
go.mod: This file contains dependencies used by this Go program. -
go.sum: This file contains checksums for each of the direct and indirect dependencies. The checksum is used to validate that none of them has been modified. -
main.go: This Go file is the Pulumi program executed by thepulumiCLI, and contains the resource definitions to create a VPC with only public subnets, a security group to allow SSH access, and a Flatcar Linux-based EC2 instance in one of the public subnets. -
Pulumi.yaml: This is the Pulumi project file. -
README.md: This file you're currently reading.
Instructions
These instructions assume you've already installed and configured Pulumi and all necessary dependencies (Go, for this example). Please refer to the Pulumi documentation for more details on installation or configuration.
-
Copy the contents of this directory down to a directory on your system, or clone the entire repository and then change into the directory where this section of the cloned repository resides.
-
Run
pulumi stack initto create a new stack. -
Run
pulumi config set aws:region <region-name>to set the AWS region where the Pulumi program should create resources. This is a required configuration value; CLI operations will fail if you don't set this value. -
Run
pulumi config set keypair <name-of-aws-keypair>to set the name of the AWS keypair that should be used. This is a required configuration value. -
Run
pulumi config set privatekeyfile <path-to-private-key-file>to set the name of the private key file for the AWS keypair specified in the previous step. This is a required configuration value. -
(Optional) Run
pulumi config setto set configuration values that affect the behavior of the Pulumi program. The optional configuration values are:architecture: Set this to "amd64" or "arm64". The values "x86_64" and "x64" are also supported and will have the same effect as "amd64". The default value is "arm64".networkcidr: Set this to control the CIDR that will be used when the VPC is created. The default value is "10.0.0.0/16".channel: Set this to "stable", "alpha", "beta", or "lts" to control the release channel for the Flatcar Linux instance. The default value is "stable".
-
Run
pulumi upto instantiate the resources. The Pulumi program will create the Flatcar Linux EC2 instance, then use the Docker provider to pull down an image and launch a container---all remotely via SSH.
Enjoy! When you're finished, run pulumi destroy to tear down all the provisioned resources.
License
This content is licensed under the MIT License.