Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SHELL = /bin/bash

-include $(shell curl -sSL -o .build-harness "https://cloudposse.tools/build-harness"; echo .build-harness)
128 changes: 126 additions & 2 deletions README.md
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't updated because the .github repo for this org isn't in place yet.

Original file line number Diff line number Diff line change
@@ -1,2 +1,126 @@
# context-provider-demo
A demo of using the Cloud Posse context provider
<!-- markdownlint-disable -->
# context-provider-demo <a href="https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse-examples/context-provider-demo&utm_content="><img align="right" src="https://cloudposse.com/logo-300x69.svg" width="150" /></a>
<a href="https://github.com/cloudposse-examples/context-provider-demo/releases/latest"><img src="https://img.shields.io/github/release/cloudposse-examples/context-provider-demo.svg" alt="Latest Release"/></a><a href="https://slack.cloudposse.com"><img src="https://slack.cloudposse.com/badge.svg" alt="Slack Community"/></a><a href="https://ask.sweetops.com/"><img src="https://img.shields.io/discourse/https/ask.sweetops.com/posts.svg" alt="Discourse Forum"/></a>
<!-- markdownlint-restore -->

<!--




** DO NOT EDIT THIS FILE
**
** This file was automatically generated by the `cloudposse/build-harness`.
** 1) Make all changes to `README.yaml`
** 2) Run `make init` (you only need to do this once)
** 3) Run`make readme` to rebuild this file.
**
** (We maintain HUNDREDS of open source projects. This is how we maintain our sanity.)
**





-->

This repository is a demonstration of how to use the `context` provider to pass context between modules in a
[atmos](https://atmos.tools) environment.


---



## Introduction

This is an introduction.











## Related Projects

Check out these related projects.

- [terraform-provider-context](https://github.com/cloudposse/terraform-provider-context) - The Terraform `contest` provider is a custom provider that allows you to pass context between modules in a
Terraform configuration.


## References

For additional context, refer to some of these links.



## ✨ Contributing

This project is under active development, and we encourage contributions from our community.
Many thanks to our outstanding contributors:

<a href="https://github.com/cloudposse-examples/context-provider-demo/graphs/contributors">
<img src="https://contrib.rocks/image?repo=cloudposse-examples/context-provider-demo&max=24" />
</a>


### 🌎 Slack Community

Join our [Open Source Community](https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse-examples/context-provider-demo&utm_content=slack) on Slack. It's **FREE** for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally *sweet* infrastructure.

### 📰 Newsletter

Sign up for [our newsletter](https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse-examples/context-provider-demo&utm_content=newsletter) and join 3,000+ DevOps engineers, CTOs, and founders who get insider access to the latest DevOps trends, so you can always stay in the know.
Dropped straight into your Inbox every week — and usually a 5-minute read.

### 📆 Office Hours <a href="https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse-examples/context-provider-demo&utm_content=office_hours"><img src="https://img.cloudposse.com/fit-in/200x200/https://cloudposse.com/wp-content/uploads/2019/08/Powered-by-Zoom.png" align="right" /></a>

[Join us every Wednesday via Zoom](https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse-examples/context-provider-demo&utm_content=office_hours) for your weekly dose of insider DevOps trends, AWS news and Terraform insights, all sourced from our SweetOps community, plus a _live Q&A_ that you can’t find anywhere else.
It's **FREE** for everyone!

## About

This project is maintained by <a href="https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse-examples/context-provider-demo&utm_content=">Cloud Posse, LLC</a>.
<a href="https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse-examples/context-provider-demo&utm_content="><img src="https://cloudposse.com/logo-300x69.svg" align="right" /></a>

We are a [**DevOps Accelerator**](https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse-examples/context-provider-demo&utm_content=commercial_support) for funded startups and enterprises.
Use our ready-to-go terraform architecture blueprints for AWS to get up and running quickly.
We build it with you. You own everything. Your team wins. Plus, we stick around until you succeed.

<a href="https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse-examples/context-provider-demo&utm_content=commercial_support"><img alt="Learn More" src="https://img.shields.io/badge/learn%20more-success.svg?style=for-the-badge"/></a>

*Your team can operate like a pro today.*

Ensure that your team succeeds by using our proven process and turnkey blueprints. Plus, we stick around until you succeed.

<details>
<summary>📚 <strong>See What's Included</strong></summary>

- **Reference Architecture.** You'll get everything you need from the ground up built using 100% infrastructure as code.
- **Deployment Strategy.** You'll have a battle-tested deployment strategy using GitHub Actions that's automated and repeatable.
- **Site Reliability Engineering.** You'll have total visibility into your apps and microservices.
- **Security Baseline.** You'll have built-in governance with accountability and audit logs for all changes.
- **GitOps.** You'll be able to operate your infrastructure via Pull Requests.
- **Training.** You'll receive hands-on training so your team can operate what we build.
- **Questions.** You'll have a direct line of communication between our teams via a Shared Slack channel.
- **Troubleshooting.** You'll get help to triage when things aren't working.
- **Code Reviews.** You'll receive constructive feedback on Pull Requests.
- **Bug Fixes.** We'll rapidly work with you to fix any bugs in our projects.
</details>

<a href="https://cloudposse.com/readme/commercial-support/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse-examples/context-provider-demo&utm_content=readme_commercial_support_link"><img src="https://cloudposse.com/readme/commercial-support/img"/></a>
## Copyrights

Copyright © 2024-2024 [Cloud Posse, LLC](https://cloudposse.com)



<a href="https://cloudposse.com/readme/footer/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse-examples/context-provider-demo&utm_content=readme_footer_link"><img alt="README footer" src="https://cloudposse.com/readme/footer/img"/></a>

<img alt="Beacon" width="0" src="https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse-examples/context-provider-demo?pixel&cs=github&cm=readme&an=context-provider-demo"/>
73 changes: 73 additions & 0 deletions README.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#
# This is the canonical configuration for the `README.md`
# Run `make readme` to rebuild the `README.md`
#

# Name of this project
name: context-provider-demo

# Logo for this project
#logo: docs/logo.png

# License of this project
license: "APACHE2"

# Copyrights
copyrights:
- name: "Cloud Posse, LLC"
url: "https://cloudposse.com"
year: "2024"

# Canonical GitHub repo
github_repo: cloudposse-examples/context-provider-demo

# Badges to display
badges:
- name: "Latest Release"
image: "https://img.shields.io/github/release/cloudposse-examples/context-provider-demo.svg"
url: "https://github.com/cloudposse-examples/context-provider-demo/releases/latest"
- name: "Slack Community"
image: "https://slack.cloudposse.com/badge.svg"
url: "https://slack.cloudposse.com"
- name: "Discourse Forum"
image: "https://img.shields.io/discourse/https/ask.sweetops.com/posts.svg"
url: "https://ask.sweetops.com/"

# List any related terraform modules that this module may be used with or that this module depends on.
related:
- name: "terraform-provider-context"
description: |-
The Terraform `contest` provider is a custom provider that allows you to pass context between modules in a
Terraform configuration.
url: "https://github.com/cloudposse/terraform-provider-context"

# List any resources helpful for someone to get started. For example, link to the hashicorp documentation or AWS documentation.
references:

# Short description of this project
description: |-
This repository is a demonstration of how to use the `context` provider to pass context between modules in a
[atmos](https://atmos.tools) environment.

# Introduction to the project
introduction: |-
This is an introduction.

# How to use this module. Should be an easy example to copy and paste.
#usage: |-
# For a complete example, see [examples/complete](examples/complete).

# Example usage
#examples: |-
# Here is an example of using this module:
# - [`examples/complete`](https://github.com/cloudposse-examples/context-provider-demo/) - complete example of using this module

# How to get started quickly
#quickstart: |-
# Here's how to get started...

# Other files to include in this README from the project folder
include: []

# Contributors to this project
contributors: []
122 changes: 122 additions & 0 deletions atmos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# CLI config is loaded from the following locations (from lowest to highest priority):
# system dir (`/usr/local/etc/atmos` on Linux, `%LOCALAPPDATA%/atmos` on Windows)
# home dir (~/.atmos)
# current directory
# ENV vars
# Command-line arguments
#
# It supports POSIX-style Globs for file names/paths (double-star `**` is supported)
# https://en.wikipedia.org/wiki/Glob_(programming)

# Base path for components, stacks and workflows configurations.
# Can also be set using `ATMOS_BASE_PATH` ENV var, or `--base-path` command-line argument.
# Supports both absolute and relative paths.
# If not provided or is an empty string, `components.terraform.base_path`, `components.helmfile.base_path`, `stacks.base_path` and `workflows.base_path`
# are independent settings (supporting both absolute and relative paths).
# If `base_path` is provided, `components.terraform.base_path`, `components.helmfile.base_path`, `stacks.base_path` and `workflows.base_path`
# are considered paths relative to `base_path`.
base_path: ""

components:
terraform:
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_BASE_PATH` ENV var, or `--terraform-dir` command-line argument
# Supports both absolute and relative paths
base_path: "components/terraform"
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_APPLY_AUTO_APPROVE` ENV var
apply_auto_approve: false
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_DEPLOY_RUN_INIT` ENV var, or `--deploy-run-init` command-line argument
deploy_run_init: true
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_INIT_RUN_RECONFIGURE` ENV var, or `--init-run-reconfigure` command-line argument
init_run_reconfigure: true
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_AUTO_GENERATE_BACKEND_FILE` ENV var, or `--auto-generate-backend-file` command-line argument
auto_generate_backend_file: true
helmfile:
# Can also be set using `ATMOS_COMPONENTS_HELMFILE_BASE_PATH` ENV var, or `--helmfile-dir` command-line argument
# Supports both absolute and relative paths
base_path: "components/helmfile"
# Can also be set using `ATMOS_COMPONENTS_HELMFILE_KUBECONFIG_PATH` ENV var
kubeconfig_path: "/conf/.kube/"
# Can also be set using `ATMOS_COMPONENTS_HELMFILE_HELM_AWS_PROFILE_PATTERN` ENV var
helm_aws_profile_pattern: "{namespace}-{tenant}-gbl-{stage}-helm"
# Can also be set using `ATMOS_COMPONENTS_HELMFILE_CLUSTER_NAME_PATTERN` ENV var
cluster_name_pattern: "{namespace}-{tenant}-{environment}-{stage}-eks-cluster"

stacks:
# Can also be set using `ATMOS_STACKS_BASE_PATH` ENV var, or `--config-dir` and `--stacks-dir` command-line arguments
# Supports both absolute and relative paths
base_path: "stacks"
# Can also be set using `ATMOS_STACKS_INCLUDED_PATHS` ENV var (comma-separated values string)
# Since we are distinguishing stacks based on namespace, and namespace is not part
# of the stack name, we have to set `included_paths` via the ENV var in the Dockerfile
included_paths:
- "orgs/**/*"
# Can also be set using `ATMOS_STACKS_EXCLUDED_PATHS` ENV var (comma-separated values string)
excluded_paths:
- "**/_defaults.yaml"
- "workflows/**/*"

# Can also be set using `ATMOS_STACKS_NAME_PATTERN` ENV var
# name_pattern: "{tenant}-{environment}-{stage}"
name_template: "{{.providers.context.values.ou}}-{{.providers.context.values.account}}-{{.providers.context.values.region}}"

workflows:
# Can also be set using `ATMOS_WORKFLOWS_BASE_PATH` ENV var, or `--workflows-dir` command-line arguments
# Supports both absolute and relative paths
base_path: "stacks/workflows"

# Custom CLI commands
commands:
# prereq
# echo "export INFRACOST_API_KEY=$(AWS_PROFILE=cplive-core-gbl-auto-admin chamber read infracost token -q)" > .envrc-infracost
# source .envrc-infracost
- name: infracost
description: Runs infracost on existing plans
# subcommands
commands:
- name: plan
description: This command runs infracost on a planfile
arguments:
- name: component
description: Name of the component
flags:
- name: stack
shorthand: s
description: Name of the stack
required: true
env:
- key: ATMOS_COMPONENT
value: "{{ .Arguments.component }}"
- key: ATMOS_STACK
value: "{{ .Flags.stack }}"
steps:
- atmos-infracost $ATMOS_COMPONENT $ATMOS_STACK
# - ATMOS_BASE_COMPONENT=$(atmos describe component $ATMOS_COMPONENT --stack=$ATMOS_STACK | yq .metadata.component)
# - ATMOS_WORKSPACE=$(atmos describe component $ATMOS_COMPONENT --stack $ATMOS_STACK | yq .workspace)"
# - atmos terraform plan {{ .Arguments.component }} -s {{ .Flags.stack }}
# - infracost breakdown --path components/terraform/$ATMOS_BASE_COMPONENT/$ATMOS_WORKSPACE.planfile

# Validation schemas (for validating atmos stacks and components)
schemas:
# https://json-schema.org
jsonschema:
# Can also be set using `ATMOS_SCHEMAS_JSONSCHEMA_BASE_PATH` ENV var, or `--schemas-jsonschema-dir` command-line arguments
# Supports both absolute and relative paths
base_path: "stacks/schemas/jsonschema"
# https://www.openpolicyagent.org
opa:
# Can also be set using `ATMOS_SCHEMAS_OPA_BASE_PATH` ENV var, or `--schemas-opa-dir` command-line arguments
# Supports both absolute and relative paths
base_path: "stacks/schemas/opa"
# https://cuelang.org
cue:
# Can also be set using `ATMOS_SCHEMAS_CUE_BASE_PATH` ENV var, or `--schemas-cue-dir` command-line arguments
# Supports both absolute and relative paths
base_path: "stacks/schemas/cue"

logs:
verbose: false
colors: true
file: "/dev/stdout"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using `ATMOS_LOGS_LEVEL` ENV var, or `--log-level` command-line argument
level: Info
50 changes: 50 additions & 0 deletions components/terraform/demo-ec2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
locals {
enabled = data.context_config.this.enabled
}

# Get the context so we can read properties (enabled) from it
data "context_config" "this" {}

# Create a label based on the context
data "context_label" "name" {
count = local.enabled ? 1 : 0
values = {
"name" = "demo"
}
}

# Create tags based on the context. Add the value of the name label to the tags
data "context_tags" "this" {
count = local.enabled ? 1 : 0

values = {
"name" = data.context_label.name[0].rendered
}
}

# Lookup the latest Ubuntu AMI
data "aws_ami" "ubuntu" {
count = local.enabled ? 1 : 0
most_recent = true

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = ["099720109477"] # Canonical
}

# Deply an EC2 instance and set the tags based on the context
resource "aws_instance" "demo" {
count = local.enabled ? 1 : 0
ami = data.aws_ami.ubuntu[0].id
instance_type = "t3.micro"

tags = data.context_tags.this[0].tags
}
6 changes: 6 additions & 0 deletions components/terraform/demo-ec2/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

provider "aws" {
}

provider "context" {
}
Empty file.
Loading