#spacelift (2022-03)

2022-03-01

Managing Infrastructure at Scale | Spacelift Blog avatar
Managing Infrastructure at Scale | Spacelift Blog
02:32:20 PM

SRE vs. DevOps: What’s the Difference Between Them? What does DevOps do? And what about SRE? See our article and find out the differences between DevOps and SRE.

SRE vs. DevOps: What’s the Difference Between Them?attachment image

What does DevOps do? And what about SRE? See our article and find out the differences between DevOps and SRE.

2022-03-03

Managing Infrastructure at Scale | Spacelift Blog avatar
Managing Infrastructure at Scale | Spacelift Blog
07:52:20 PM

What are Terraform Templates? Basics, Use Cases, Examples What are Terraform Templates? What are Terraform Templates used for? See examples and use cases.

What are Terraform Templates? Basics, Use Cases, Examplesattachment image

What are Terraform Templates? What are Terraform Templates used for? See examples and use cases.

2022-03-07

Darrin F avatar
Darrin F

@Andriy Knysh (Cloud Posse) I have a spacelift stack (super generic one) that uses a simple module to create an s3 bucket. Then I added atmos.yaml and stack yaml files from example/tutorial. Spacelift seems to understand there is a stack to create. However, the s3 module code to create the bucket does not seem to get invoked. Is there something needed (in either spacelift or my code) to invoke “atmos terraform plan…” or similar? I’m having trouble understanding how the s3 module code will get invoked.

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

it’s a few steps process:

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)
  1. Create a PR to add the Spacelift stack(s)
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)
  1. Merge the PR and confirm in Spacelift - it will create the stack itself
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)
  1. Open a PR to add TF components (with spacelift.workspace_enabled: true)
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)
  1. terraform plan from the PR will be shown in the “PRs” tab in Spacelift stack
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)
  1. After the PR is merged, Spacelift will create a tracked run, which you could confirm to create the resources
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

in short, Spacelift stack is not the same as the resources that the stack creates

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

Spacelift stack must be created first

Darrin F avatar
Darrin F

I think that’s what I have, but I will verify. Thanks for the quick response!

Darrin F avatar
Darrin F

I have the spacelift stack and tracked runs and pr’s working correctly. My question seems to be more about “What makes adding atmos.yaml and the stack yaml files work?” I notice on the spacelift stack that if I invoke “atmos version” (using their “Tasks” feature) that atmos is not found. What makes adding atmos.yaml perform the composition of the yaml-defined stack/s including diving into ./components/terraform/myModule? Do I need to install atmos onto spacelift instance somehow, or is it enough to add the cloudposse/utils provider? If the latter, I’m still not clear what magic causes the resolution of the stack yaml files into a full terraform stack to be executed. I’ve tried adding the “context.yaml”, and “spacelift”/”stack” modules (to add policies, etc. to the spacelift stacks), but what I’m after is a bare-bones demo of adding atmos stack generation, and I can’t seem to grasp what triggers that feature.

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

in your repo, you should have a Dockerfile

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)
ARG ATMOS_VERSION=1.3.29

# Install Atmos CLI (<https://github.com/cloudposse/atmos>)
ARG ATMOS_VERSION
RUN apt-get update && apt-get install -y atmos="${ATMOS_VERSION}-*"
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

then we build the image (and save it to ECR for example)

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

then each Spacelift stack is configured to use that image

Darrin F avatar
Darrin F

That should make a huge difference! Thanks and I’ll give that a go.

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

every time Spacelift executes a run (or a task), it downloads the image (which has atmos)

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

if you want, open a PR and send to me (MD)

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

I’ll take a look and point out what is missing

Darrin F avatar
Darrin F

Thank you, I’ll get back to this a bit later today and let you know how it’s going. Thanks for your support.

Darrin F avatar
Darrin F

is there any public image with atmos already installed?

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

no, but there are public images for geodesic, and this Dockerfile to add atmos https://github.com/cloudposse/atmos/blob/master/examples/complete/Dockerfile

# Geodesic: <https://github.com/cloudposse/geodesic/>
ARG GEODESIC_VERSION=0.152.2
ARG GEODESIC_OS=debian
# atmos: <https://github.com/cloudposse/atmos>
ARG ATMOS_VERSION=1.3.30
# Terraform
ARG TF_VERSION=1.1.4

FROM cloudposse/geodesic:${GEODESIC_VERSION}-${GEODESIC_OS}

# Geodesic message of the Day
ENV MOTD_URL="<https://geodesic.sh/motd>"

# Some configuration options for Geodesic
ENV AWS_SAML2AWS_ENABLED=false
ENV AWS_VAULT_ENABLED=false
ENV AWS_VAULT_SERVER_ENABLED=false
ENV GEODESIC_TF_PROMPT_ACTIVE=false
ENV DIRENV_ENABLED=false

# Enable advanced AWS assume role chaining for tools using AWS SDK
# <https://docs.aws.amazon.com/sdk-for-go/api/aws/session/>
ENV AWS_SDK_LOAD_CONFIG=1
ENV AWS_DEFAULT_REGION=us-east-2

# Install specific version of Terraform
ARG TF_VERSION
RUN apt-get update && apt-get install -y -u --allow-downgrades \
  terraform-1="${TF_VERSION}-*" && \
  update-alternatives --set terraform /usr/share/terraform/1/bin/terraform

ARG ATMOS_VERSION
RUN apt-get update && apt-get install -y --allow-downgrades \
  atmos="${ATMOS_VERSION}-*"

COPY rootfs/ /

# Geodesic banner message
ENV BANNER="atmos"

WORKDIR /

2022-03-08

Darrin F avatar
Darrin F

@Andriy Knysh (Cloud Posse) after I create this and run the container I should be able to “atmos version”, correct? I get “atmos: command not found”. Seems odd but could you just confirm it’s working for you?

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)
# Geodesic: <https://github.com/cloudposse/geodesic/>
ARG GEODESIC_VERSION=0.152.2
ARG GEODESIC_OS=debian
# atmos: <https://github.com/cloudposse/atmos>
ARG ATMOS_VERSION=1.3.30
# Terraform
ARG TF_VERSION=1.1.4

FROM cloudposse/geodesic:${GEODESIC_VERSION}-${GEODESIC_OS}

# Geodesic message of the Day
ENV MOTD_URL="<https://geodesic.sh/motd>"

# Some configuration options for Geodesic
ENV AWS_SAML2AWS_ENABLED=false
ENV AWS_VAULT_ENABLED=false
ENV AWS_VAULT_SERVER_ENABLED=false
ENV GEODESIC_TF_PROMPT_ACTIVE=false
ENV DIRENV_ENABLED=false

# Enable advanced AWS assume role chaining for tools using AWS SDK
# <https://docs.aws.amazon.com/sdk-for-go/api/aws/session/>
ENV AWS_SDK_LOAD_CONFIG=1
ENV AWS_DEFAULT_REGION=us-east-2

# Install specific version of Terraform
ARG TF_VERSION
RUN apt-get update && apt-get install -y -u --allow-downgrades \
  terraform-1="${TF_VERSION}-*" && \
  update-alternatives --set terraform /usr/share/terraform/1/bin/terraform

ARG ATMOS_VERSION
RUN apt-get update && apt-get install -y --allow-downgrades \
  atmos="${ATMOS_VERSION}-*"

COPY rootfs/ /

# Geodesic banner message
ENV BANNER="atmos"

WORKDIR /

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

and then atmos version

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

all is ok

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)
Connected.
 ✗ . [none] ~ ⨠ atmos version                                                                                                                               
v1.3.30
Darrin F avatar
Darrin F
Getting close. 
Darrin F avatar
Darrin F

I now have spacelift pointed at this repo https://github.com/dfreeman-cricut/cautious-octo-robot copied from https://github.com/cloudposse/atmos/tree/master/examples/complete

with a working “atmos” image (atop geodesic)

and can run a spacelift “Task” such as atmos terraform plan infra/vpc -s tenant1-ue2-dev

and see output like it would be ready to produce the requested terraform artifacts

Question: What else is needed now to get spacelift to recognize these state changes and permit me to “Confirm” and “Apply”?

Alex Jurkiewicz avatar
Alex Jurkiewicz

Tasks are one-off commands that run. To confirm/apply you need Spacelift to trigger a tracked run. That happens by default when you commit and push to the tracked branch

Darrin F avatar
Darrin F

I ran the Task just to make sure atmos is working in my worker image.

Darrin F avatar
Darrin F

Just now I created a new stack on spacelift and pointed it at my repo, and triggered a Run. I get “No changes. Your infrastructure matches the configuration.”

Darrin F avatar
Darrin F

I’m missing somehow the part that would tell spacelift to use atmos when processing the repo.

Alex Jurkiewicz avatar
Alex Jurkiewicz

Good question. I don’t know how that works sorry. I don’t think you can change the Terraform command that Spacelift runs…

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

there are a few more steps to setup using atmos + Spacelift:

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

in the repo in .spacelift/config.yml

version: "1"

stack_defaults:
  before_init:
    - spacelift-configure-paths
    - spacelift-git-use-https
    - spacelift-write-vars
    - spacelift-tf-workspace

  before_plan:
    - spacelift-configure-paths

  before_apply:
    - spacelift-configure-paths

  environment:
    AWS_SDK_LOAD_CONFIG: true
    AWS_CONFIG_FILE: /etc/aws-config/aws-config-cicd
    AWS_PROFILE: <namespace>-gbl-identity
    ATMOS_BASE_PATH: /mnt/workspace/source

stacks:

  infrastructure:
    before_init: []
    before_plan: []
    before_apply: []
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

in rootfs/usr/local/bin/spacelift-configure-paths

# Link the default terraform binary to Spacelift's Terraform installation path of `/bin/terraform`.
# Because the Terraform commands are executed as just `terraform` by `atmos` (unless otherwise specified)
# and also in scripts, and the default PATH has `/usr/bin` before `/bin`,
# plain 'terraform' would otherwise resolve to the Docker container's
# chosen version of Terraform, not Spacelift's configured version.

ln -sfTv /bin/terraform /usr/bin/terraform
echo "Using Terraform: "
which terraform
terraform version
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

in rootfs/usr/local/bin/spacelift-git-use-https

#!/bin/bash

set -ex

# Spacelift uses a PAT via a .netrc file so any [email protected]: urls need to be
# converted to HTTPS urls or spacelift will fail. This allows us to use SSH
# paths throughout the codebase so local plans work and allows spacelift to
# work.

# The URL "[email protected]:" is used by `git` (e.g. `git clone`)
git config --global url."<https://github.com/>".insteadOf "[email protected]:"
# The URL "<ssh://[email protected]/>" is used by Terraform (e.g. `terraform init --from-module=...`)
# NOTE: we use `--add` to append the second URL to the config file
git config --global url."<https://github.com/>".insteadOf "<ssh://[email protected]/>" --add
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

in rootfs/usr/local/bin/spacelift-tf-workspace

terraform init -reconfigure

echo "Selecting Terraform workspace..."
echo "...with AWS_PROFILE=$AWS_PROFILE"
echo "...with AWS_CONFIG_FILE=$AWS_CONFIG_FILE"

atmos terraform workspace "$ATMOS_COMPONENT" --stack="$ATMOS_STACK"
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

in rootfs/usr/local/bin/spacelift-write-vars

function main() {
  if [[ -z $ATMOS_STACK ]] || [[ -z $ATMOS_COMPONENT ]]; then
    echo "Missing required environment variable" >&2
    echo "  ATMOS_STACK=$ATMOS_STACK" >&2
    echo "  ATMOS_COMPONENT=$ATMOS_COMPONENT" >&2
    return 3
  fi

  echo "Writing Stack variables to spacelift.auto.tfvars.json for Spacelift..."

  atmos terraform write varfile "$ATMOS_COMPONENT" --stack="$ATMOS_STACK" -f spacelift.auto.tfvars.json >/dev/null
  jq . <spacelift.auto.tfvars.json
}

main
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

this expects that you are using https://github.com/cloudposse/terraform-spacelift-cloud-infrastructure-automation to create Spacelift stacks since the ENV vars ATMOS_STACK and ATMOS_COMPONENT are set in the module

cloudposse/terraform-spacelift-cloud-infrastructure-automation

Terraform module to provision Spacelift resources for cloud infrastructure automation

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

but you should get the idea and modify for your needs

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

@Darrin F

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

regarding “What else is needed now to get spacelift to recognize these state changes and permit me to “Confirm” and “Apply”?” - if you use s3 backend and Spacelift has access to it, then the state should be in s3, and it should be accessible both locally and from Spacelift

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

for Spacelift to be able to access your s3 backend, it should be able to assume a corresponding IAM role

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

see the .spacelift/config.yml file above

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)
AWS_CONFIG_FILE: /etc/aws-config/aws-config-cicd
    AWS_PROFILE: <namespace>-gbl-identity
Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

AWS_CONFIG_FILE has all the required profiles (not only for the current account, but all profiles to access all the accounts you are provisioning resources to

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

AWS_PROFILE is the name of the profile in the /etc/aws-config/aws-config-cicd file that defines an IAM role that has all the required permissions to 1) provision the resources into the account; 2) access s3 terraform state backend (which can be in the same account or in a different centralized account that stores TF state for all environments)

Darrin F avatar
Darrin F

Thanks for the info Andriy. Seems there’s a bit more to it than I understood. I appreciate the info and I’ll give that a shot.

Andriy Knysh (Cloud Posse) avatar
Andriy Knysh (Cloud Posse)

you don’t need to use all the scripts that I provided, just the general idea: 1) Spacelift needs to assume some IAM role with permissions to access AWS and s3 backend; 2) Spacelift needs to call atmos terraform write varfile to parse the YAML config and write the varfile for the component in the stack; 3) the component and the stack are provided to Spacelift using the two ENV vars (but you can provide it in any other way as you see fit)

Darrin F avatar
Darrin F

I’m trying to demo the bare bones needs/concept to my team, so thank you for clarifying and I’ll try and make as few updates as possible for now to get it capable.

Darrin F avatar
Darrin F

Thanks for kicking in this week and helping me out. Got a cloudposse infra/vpc demo working on spacelift. Pretty slick stuff. I’ll jump back here when there are more questions…

2022-03-09

2022-03-11

2022-03-17

Darrin F avatar
Darrin F

Had a terrific demo to my team with spacelift and cloudposse’s terraform modules/approach. Truly appreciate the help in this group; we’ll be in touch!

5
1
Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)

Oh cool! Glad to hear it. Keep us posted if you roll it out.

2022-03-18

Managing Infrastructure at Scale | Spacelift Blog avatar
Managing Infrastructure at Scale | Spacelift Blog
11:32:16 AM

Terraform vs. AWS CloudFormation: The Ultimate Comparison Terraform and CloudFormation are both tools for Infrastructure as Code (IaC). We are comparing the two of them and outlining some of the key differences.

Terraform vs. AWS CloudFormation : The Ultimate Comparisonattachment image

Terraform and CloudFormation are both tools for Infrastructure as Code (IaC). We are comparing the two of them and outlining some of the key differences.

2022-03-20

2022-03-21

Managing Infrastructure at Scale | Spacelift Blog avatar
Managing Infrastructure at Scale | Spacelift Blog
10:52:18 AM

Terraform Init &#8211; Command Overview with Quick Usage Examples What does terraform init command do? See examples and quick usages. Learn how to init your infrastructure with Terraform.

Terraform Init - Command Overview with Quick Usage Examplesattachment image

What does terraform init command do? See examples and quick usages. Learn how to init your infrastructure with Terraform.

2022-03-23

Managing Infrastructure at Scale | Spacelift Blog avatar
Managing Infrastructure at Scale | Spacelift Blog
02:32:18 PM

What is Pulumi? Key Concepts and Features Overview In this article you’ll learn what Pulumi is, how it works and why it can be helpful for your Infrastructure as Code (IaC).

What is Pulumi? Key Concepts and Features Overviewattachment image

In this article you’ll learn what Pulumi is, how it works and why it can be helpful for your Infrastructure as Code (IaC).

2022-03-28

Managing Infrastructure at Scale | Spacelift Blog avatar
Managing Infrastructure at Scale | Spacelift Blog
07:02:17 PM

Working with Ansible Playbooks &#8211; Tips &#038; Tricks with Examples Playbooks are one of the basic components of Ansible. Learn how to use them and see detailed examples with best practices.

Working with Ansible Playbooks - Tips & Tricks with Examplesattachment image

Playbooks are one of the basic components of Ansible. Learn how to use them and see detailed examples with best practices.

 avatar
07:02:48 PM

@ has joined the channel

    keyboard_arrow_up