Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit 8825f73

Browse files
authored
Add Spotinst integration (#113)
1 parent b6f7d66 commit 8825f73

25 files changed

+1540
-5
lines changed

Dockerfile

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG VERSION=0.146.4
1+
ARG VERSION=0.147.7
22
ARG OS=alpine
33
FROM cloudposse/geodesic:$VERSION-$OS
44

@@ -32,10 +32,29 @@ ENV TF_BUCKET_REGION="${AWS_REGION}"
3232
ENV TF_BUCKET="${NAMESPACE}-${STAGE}-terraform-state"
3333
ENV TF_DYNAMODB_TABLE="${NAMESPACE}-${STAGE}-terraform-state-lock"
3434

35+
# Our older Geodesic configurations relied on `direnv`, which we no longer recommend,
36+
# preferring YAML configuration files instead.
37+
ENV DIRENV_ENABLED=true
38+
# Our older Geodesic configuration uses multiple Makefiles, like Makefile.tasks
39+
# and depends on this setting, however this setting is set by default by `direnv`
40+
# due to rootfs/conf/.envrc, but `direnv` is now disabled by default, too.
41+
# If you are using (and therefore enable) `direnv`, consider the advantage
42+
# of using `direnv` to set MAKE_INCLUDES, which is that it will only set
43+
# it for trusted directories under `/conf` and therefore it will not affect
44+
# `make` outside of this directory tree.
45+
ENV MAKE_INCLUDES="Makefile Makefile.*"
46+
3547
# Default AWS Profile name
3648
ENV AWS_DEFAULT_PROFILE="${NAMESPACE}-${STAGE}-admin"
3749
ENV AWS_MFA_PROFILE="${NAMESPACE}-root-admin"
3850

51+
# aws-vault setup
52+
ENV AWS_VAULT_ASSUME_ROLE_TTL=1h
53+
ENV AWS_VAULT_SERVER_ENABLED=false
54+
ENV AWS_VAULT_BACKEND=file
55+
ENV AWS_VAULT_ENABLED=true
56+
RUN apk add -u aws-vault@cloudposse~=4
57+
3958
# Install go for running terratest
4059
RUN apk add -uU go
4160

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
zone_name = "testing.cloudposse.co"
2-
region = "us-west-2"
2+
region = "us-west-2"
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
region="us-west-2"
2-
zone_name="testing.cloudposse.co"
1+
region = "us-west-2"
2+
zone_name = "testing.cloudposse.co"
33

44
cluster_id = "us-west-2.testing.cloudposse.co"

conf/kops/terraform.tfvars

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
zone_name = "testing.cloudposse.co"
2-
region = "us-west-2"
2+
region = "us-west-2"

conf/spotinst-integration/.envrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Import the remote module
2+
export TF_CLI_PLAN_PARALLELISM=2
3+
4+
use terraform 1
5+
use tfenv

conf/spotinst-integration/Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Initialize terraform remote state
2+
init:
3+
[ -f .terraform/terraform.tfstate ] || terraform $@
4+
5+
## Clean up the project
6+
clean:
7+
rm -rf .terraform *.tfstate*
8+
9+
## Pass arguments through to terraform which require remote state
10+
apply console destroy graph plan output providers show: init
11+
terraform $@
12+
13+
## Pass arguments through to terraform which do not require remote state
14+
get fmt validate version:
15+
terraform $@
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Fetch the remote terraform module
2+
deps:
3+
terraform init
4+
5+
## Reset this project
6+
reset:
7+
rm -rf .terraform

conf/spotinst-integration/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Component: `spotinst-integration`
2+
3+
This component is responsible for provisioning the IAM policies, roles, and instance profile for integrating an account with [Spotinst](https://spot.io/).
4+
5+
See the [documentation on configuring Spotinst here](./spotinst-configuration.md) for full details on obtaining a Spotinst API Key and providing that to the account.
6+
7+
## Usage
8+
9+
This component cannot be installed via Atlantis because it requires multiple manual interventions.
10+
The procedure in [spotinst-configuration.md](./spotinst-configuration.md)
11+
also does not work because it assumes a late 2021 (`atmos`, stacks, etc.)
12+
environment.
13+
14+
The procedure in [spotinst-manual-configuration.md](./spotinst-manual-configuration.md)
15+
to set up Spotinst is closer, but still not quite, because it too assumes
16+
there is a `namespace`-gbl-`stage`-helm role to use, which we
17+
do not have, and it assumes we have a paid account, which we do not.
18+
19+
So this set up is very manual, but you can leverage the tools
20+
in [spotinst-manual-configuration.md](./spotinst-manual-configuration.md) to help.
21+
22+
Basic steps:
23+
24+
- Get an Admin API token for Spotinst (via the web UI) and save it in an environment variable.
25+
- Create a Spotinst account for this AWS account (via `curl`). Except on the free plan, we can only have 1 account,
26+
and it has already been created.
27+
- Create (via `curl`) a programmatic user and associated API token and save the token in SSM.
28+
Actually, we do not need to save it in SSM, but it is handy there.
29+
Where it really needs to go is in a GitHub Secret as `SPOTINST_TOKEN`.
30+
- Create an "external ID" for the Spotinst API role and save it in SSM.
31+
- Run `terraform apply` to provision:
32+
- An IAM Role for Spotinst API to use to manage resources in the account
33+
- An IAM Role to give the EKS installed Ocean Controller the access it needs
34+
- An EC2 Instance Profile to assign the Ocean Controller IAM Role to an instance
35+
- Configure (via `curl`) the Spotinst API to use the API IAM Role
36+
37+
When done, the Spot.io Dashboard should show that the account status is "connected".
38+
39+
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"terraform": {
3+
"backend": {
4+
"s3": {
5+
"acl": "bucket-owner-full-control",
6+
"bucket": "cpco-testing-terraform-state",
7+
"dynamodb_table": "cpco-testing-terraform-state-lock",
8+
"encrypt": true,
9+
"key": "terraform.tfstate",
10+
"region": "us-west-2",
11+
"workspace_key_prefix": "spotinst-integration"
12+
}
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)