Skip to content
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

Support Derived Components #6

Merged
merged 23 commits into from
Jul 26, 2023
Merged
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
34 changes: 30 additions & 4 deletions .github/workflows/test-positive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ jobs:
runs-on: ubuntu-latest
continue-on-error: true
outputs:
result: "${{ steps.current.outputs.value }}"
base_result: ${{ steps.base.outputs.value }}
derived_result: ${{ steps.derived.outputs.value }}
defaults_result: ${{ steps.defaults.outputs.value }}
steps:
- name: Setup terraform
uses: hashicorp/setup-terraform@v2
Expand All @@ -24,17 +26,41 @@ jobs:
uses: actions/checkout@v3

- uses: ./
id: current
id: base
with:
component: foo
stack: core-ue1-dev
settings-path: level1.level2.level3.secrets-arn

- uses: ./
id: derived
with:
component: derived
stack: core-ue1-dev
settings-path: level1.example

- uses: ./
id: defaults
with:
component: test-defaults
stack: core-ue1-dev
settings-path: level1.example

assert:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: nick-fields/assert-action@v1
with:
expected: arn:aws:secretsmanager:us-east-1:000000000000:secret:MySecret-PlMes3
actual: "${{ needs.test.outputs.result }}"
expected: '"arn:aws:secretsmanager:us-east-1:000000000000:secret:MySecret-PlMes3"'
actual: ${{ needs.test.outputs.base_result }}

- uses: nick-fields/assert-action@v1
with:
expected: '"result"'
actual: ${{ needs.test.outputs.derived_result }}

- uses: nick-fields/assert-action@v1
with:
expected: '"result"'
actual: ${{ needs.test.outputs.defaults_result }}
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,14 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
### Contributors

<!-- markdownlint-disable -->
| [![Matt Calhoun][mcalhoun_avatar]][mcalhoun_homepage]<br/>[Matt Calhoun][mcalhoun_homepage] |
|---|
| [![Matt Calhoun][mcalhoun_avatar]][mcalhoun_homepage]<br/>[Matt Calhoun][mcalhoun_homepage] | [![Daniel Miller][milldr_avatar]][milldr_homepage]<br/>[Daniel Miller][milldr_homepage] |
|---|---|
<!-- markdownlint-restore -->

[mcalhoun_homepage]: https://github.com/mcalhoun
[mcalhoun_avatar]: https://img.cloudposse.com/150x150/https://github.com/mcalhoun.png
[milldr_homepage]: https://github.com/milldr
[milldr_avatar]: https://img.cloudposse.com/150x150/https://github.com/milldr.png

[![README Footer][readme_footer_img]][readme_footer_link]
[![Beacon][beacon]][website]
Expand Down
2 changes: 2 additions & 0 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ include:
contributors:
- name: "Matt Calhoun"
github: "mcalhoun"
- name: "Daniel Miller"
github: "milldr"
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ runs:
- id: settings
shell: bash
run: |
value=$(atmos describe stacks -s ${{ inputs.stack }} --components ${{ inputs.component }} --sections=settings --format json | jq -rc --arg key "${{inputs.settings-path}}" '.. | select(.settings)?| .settings | select(has($key | split(".")[])) | getpath($key | split("."))')
value=$(atmos describe component \
${{ inputs.component }} \
-s ${{ inputs.stack }} \
--format json | \
jq --arg key ${{ inputs.settings-path }} \
'.settings | getpath($key | split("."))' \
)
milldr marked this conversation as resolved.
Show resolved Hide resolved
echo "value=$value" >> $GITHUB_OUTPUT
17 changes: 17 additions & 0 deletions stacks/orgs/demo/dev/defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Test use of atmos default settings with component settings
settings:
level1:
example: default

components:
terraform:
test-defaults:
settings:
level1:
example: result
vars:
namespace: demo
tenant: core
environment: ue1
stage: dev
foo: bar
37 changes: 37 additions & 0 deletions stacks/orgs/demo/dev/derived.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Test derived component overwriting
components:
terraform:
derived/default:
metadata:
component: derived
type: abstract
settings:
level1:
example: default
vars:
namespace: demo
tenant: core
environment: ue1
stage: dev
foo: bar

# This is the component that we want to test getting settings from.
# "derived/default" and "derived/alternate" components should not affect these settings
derived:
metadata:
component: derived
inherits:
- derived/default
settings:
level1:
example: result

# Test adding an alternate component. This should not affect the true "derived" component.
derived/alternate:
metadata:
component: derived
inherits:
- derived/default
settings:
level1:
example: alternate
3 changes: 2 additions & 1 deletion stacks/orgs/demo/dev/dev.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Test basic use
components:
terraform:
foo:
settings:
level1:
level2:
level3:
secrets-arn: arn:aws:secretsmanager:us-east-1:000000000000:secret:MySecret-PlMes3
secrets-arn: "arn:aws:secretsmanager:us-east-1:000000000000:secret:MySecret-PlMes3"
milldr marked this conversation as resolved.
Show resolved Hide resolved
vars:
namespace: demo
tenant: core
Expand Down
Loading