-
Notifications
You must be signed in to change notification settings - Fork 0
initial implementation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mcalhoun
wants to merge
3
commits into
main
Choose a base branch
from
feature/initial-implementation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| # context-provider-demo | ||
|
|
||
| A demo of using the Cloud Posse context provider |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 EC@ 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
|
|
||
| provider "aws" { | ||
| } | ||
|
|
||
| provider "context" { | ||
| } |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| terraform { | ||
| required_version = ">= 1.0.0" | ||
|
|
||
| required_providers { | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = ">= 4.9.0" | ||
| } | ||
| context = { | ||
| source = "cloudposse/context" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # This mixin is imported into every region of the `network` account. | ||
| # Here we are defining the 'account' value for the `context` provider. | ||
| terraform: | ||
| providers: | ||
| context: | ||
| values: | ||
| account: network |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # This mixin is imported into every region of the `prod` account. | ||
| # Here we are defining the 'account' value for the `context` provider. | ||
| terraform: | ||
| providers: | ||
| context: | ||
| values: | ||
| account: prod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # This mixin is imported into the `us-east-1` region of every account. Here we are defining the 'region' value for the | ||
| # `context` provider as well as the region property for `aws` provider. | ||
| terraform: | ||
| providers: | ||
| context: | ||
| values: | ||
| region: ue1 | ||
| aws: | ||
| region: us-east-1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| terraform: | ||
| backend_type: local | ||
| providers: | ||
| context: | ||
| enabled: true | ||
| delimitier: "-" | ||
| property_order: | ||
| - namespace | ||
| - ou | ||
| - account | ||
| - region | ||
| - name | ||
| properties: | ||
| namespace: | ||
| required: true | ||
| ou: | ||
| required: true | ||
| validation_regex: "^core|plat$" | ||
| account: | ||
| required: true | ||
| region: | ||
| required: true | ||
| max_length: 3 | ||
| component: {} | ||
| repo: {} | ||
| stack: {} | ||
| stack_file: {} | ||
| name: {} | ||
| support_email: | ||
| required: true | ||
| validation_regex: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$" | ||
| tags_key_case: title | ||
| values: | ||
| namespace: acme | ||
| component: "{{.atmos_component}}" | ||
| repo: context-provider-demo | ||
| stack: "{{.atmos_stack}}" | ||
| stack_file: "{{.atmos_stack_file}}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import: | ||
| - orgs/acme/_defaults.yaml | ||
|
|
||
| # These are the default values for the `core` ou. Here we are setting the `ou` value to `core` in the `context` | ||
| # provider. | ||
| terraform: | ||
| providers: | ||
| context: | ||
| values: | ||
| ou: core |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import: | ||
| - mixins/account/network | ||
| - orgs/acme/core/_defaults | ||
|
|
||
| # This is imported into every region of the `network` account. Here we are defining the 'support_email' value for the | ||
| # `context` provider. | ||
| terraform: | ||
| providers: | ||
| context: | ||
| values: | ||
| support_email: [email protected] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import: | ||
| - mixins/region/us-east-1 | ||
| - orgs/acme/core/network/_defaults | ||
|
|
||
| # Create an EC2 instance in the `us-east-1` region. | ||
| components: | ||
| terraform: | ||
| demo-ec2: {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import: | ||
| - orgs/acme/_defaults.yaml | ||
|
|
||
| # These are the default values for the `plat` ou. Here we are setting the `ou` value to `plat` in the `context` | ||
| # provider. | ||
| terraform: | ||
| providers: | ||
| context: | ||
| values: | ||
| ou: plat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import: | ||
| - mixins/account/prod | ||
| - orgs/acme/plat/_defaults | ||
|
|
||
| # This is imported into every region of the `prod` account. Here we are defining the 'support_email' value for the | ||
| # `context` provider. | ||
| terraform: | ||
| providers: | ||
| context: | ||
| values: | ||
| support_email: [email protected] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
.githubrepo for this org isn't in place yet.