-
Notifications
You must be signed in to change notification settings - Fork 127
Add Terraform Outputs to ServiceContext to use them in agent policy test config #1272
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
edd1f62
Test terraform outputs
bhapas 2b0ca25
Add Terraform Outputs to ServiceContext Properties
bhapas 6ca0758
Fix static checks
bhapas 321503f
Add docs
bhapas 16030f9
Add a test
bhapas 5e66d46
Add new package to buildkite precommand
bhapas 09afb88
Fix terrraform files
bhapas 1133a50
Fix PR comments and add unit tests
bhapas 9ada2e7
Merge branch 'main' into terraform-outputs-aws
bhapas 94d00b0
run go mod tidy
bhapas 1b36494
Fix PR comments and go mod tidy
bhapas a0d32b5
Add outputs in build directory instead
bhapas 038d54a
address PR comments
bhapas 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
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
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
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
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 |
|---|---|---|
|
|
@@ -13,3 +13,4 @@ services: | |
| - TF_VAR_REPO=${REPO:-unknown} | ||
| volumes: | ||
| - ${TF_DIR}:/stage | ||
| - ${TF_OUTPUT_DIR}:/output | ||
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
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
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
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
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
128 changes: 128 additions & 0 deletions
128
internal/testrunner/runners/system/servicedeployer/terraform_test.go
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,128 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| package servicedeployer | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestAddTerraformOutputs(t *testing.T) { | ||
| var testCases = []struct { | ||
| testName string | ||
| err string | ||
| ctxt ServiceContext | ||
| runId string | ||
| content []byte | ||
| expectedProps map[string]interface{} | ||
| }{ | ||
| { | ||
| testName: "single_value_output", | ||
| runId: "99999", | ||
| ctxt: ServiceContext{ | ||
| Test: struct{ RunID string }{"99999"}, | ||
| }, | ||
| content: []byte( | ||
| `{ | ||
| "queue_url": { | ||
| "sensitive": false, | ||
| "type": "string", | ||
| "value": "https://sqs.us-east-1.amazonaws.com/1234654/elastic-package-aws-logs-queue-someId" | ||
| } | ||
| }`, | ||
| ), | ||
| expectedProps: map[string]interface{}{ | ||
| "TF_OUTPUT_queue_url": "https://sqs.us-east-1.amazonaws.com/1234654/elastic-package-aws-logs-queue-someId", | ||
| }, | ||
| }, | ||
| { | ||
| testName: "multiple_value_output", | ||
| runId: "23465", | ||
| ctxt: ServiceContext{ | ||
| Test: struct{ RunID string }{"23465"}, | ||
| }, | ||
| content: []byte( | ||
| `{ | ||
| "queue_url": { | ||
| "sensitive": false, | ||
| "type": "string", | ||
| "value": "https://sqs.us-east-1.amazonaws.com/1234654/elastic-package-aws-logs-queue-someId" | ||
| }, | ||
| "instance_id": { | ||
| "sensitive": false, | ||
| "type": "string", | ||
| "value": "some-random-id" | ||
| } | ||
| }`, | ||
| ), | ||
| expectedProps: map[string]interface{}{ | ||
| "TF_OUTPUT_queue_url": "https://sqs.us-east-1.amazonaws.com/1234654/elastic-package-aws-logs-queue-someId", | ||
| "TF_OUTPUT_instance_id": "some-random-id", | ||
| }, | ||
| }, | ||
| { | ||
| testName: "complex_value_output", | ||
| runId: "078907890", | ||
| ctxt: ServiceContext{ | ||
| Test: struct{ RunID string }{"078907890"}, | ||
| }, | ||
| content: []byte( | ||
| `{ | ||
| "queue_url": { | ||
| "sensitive": false, | ||
| "type": "string", | ||
| "value": "https://sqs.us-east-1.amazonaws.com/1234654/elastic-package-aws-logs-queue-someId" | ||
| }, | ||
| "triangle_output": { | ||
| "sensitive": false, | ||
| "type": [ | ||
| "object", | ||
| { | ||
| "description": "string", | ||
| "s_one": "number", | ||
| "s_three": "number", | ||
| "s_two": "number" | ||
| } | ||
| ], | ||
| "value": { | ||
| "value": "this is a triangle", | ||
| "s_one": 1, | ||
| "s_three": 2.5, | ||
| "s_two": 2.5 | ||
| } | ||
| } | ||
| }`, | ||
| ), | ||
| expectedProps: map[string]interface{}{ | ||
| "TF_OUTPUT_queue_url": "https://sqs.us-east-1.amazonaws.com/1234654/elastic-package-aws-logs-queue-someId", | ||
| "TF_OUTPUT_triangle_output": map[string]any{ | ||
| "s_one": 1.0, | ||
| "s_three": 2.5, | ||
| "s_two": 2.5, | ||
| "value": "this is a triangle", | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| t.Parallel() | ||
| for _, tc := range testCases { | ||
|
|
||
| t.Run(tc.testName, func(t *testing.T) { | ||
| tc.ctxt.CustomProperties = make(map[string]interface{}) | ||
| tc.ctxt.OutputDir = t.TempDir() | ||
|
|
||
| if err := os.WriteFile(tc.ctxt.OutputDir+"/tfOutputValues.json", tc.content, 0777); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| // Test that the terraform output values are generated correctly | ||
| addTerraformOutputs(tc.ctxt) | ||
| assert.Equal(t, tc.expectedProps, tc.ctxt.CustomProperties) | ||
| }) | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.