-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support Relative Path Imports (#891)
* Handle relative paths for stack imports * Tests for relative paths * Refactor handling of relative paths in ProcessImportSection * Handle relative paths in StackImport.Path and string imports * Add new test2/us-west-1.yaml file and update test counts * Update import paths in us-west-1.yaml file * Refactor handling of import paths in ProcessImportSection * Resolve relative paths in ProcessImportSection function * Update internal/exec/stack_processor_utils.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Refactor resolveRelativePath for improved path handling * Refactor filepath handling for better readability * Remove unnecessary path normalization code and simplify logic * Improve path resolution handling in stack_processor_utils * relative path handling improvements for windows; added security checks for import paths * Validate import paths for security and base path inclusion * Update path.Join calls to use filepath.Join for consistency * Update stack_processor_utils.go to use filepath package * validate stack paths to check against the global base path * Refactor path resolution and validation logic * Refactor resolving relative path logic for clarity * Revert changes * Refactor path resolution for consistency * Refactor resolveRelativePath function for path consistency * Convert relative path to base path if starts with "." or ".." * Simplify resolving relative paths in stack_processor_utils * added tests for atmos stacks with relative paths * PR feedback * merged main, incorporate new test fixture pattern * Delete nonprod and prod cache weather files * Delete outdated Atmos manifest JSON schema * consistent indentation * Add ignore rule for cache text files * Update stack processor test cases and relative paths * revert cahnges * use relative paths in advanced usage example * use relative paths in advanced usage example * reset advanced usage * added relative paths to demo-context --------- Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
059eccb
commit b13a2fd
Showing
19 changed files
with
337 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -35,3 +35,4 @@ | |
.direnv/ | ||
|
||
.atmos/cache.yaml | ||
**/cache.*.txt |
This file contains 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 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 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 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 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 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,21 @@ | ||
base_path: "./" | ||
|
||
components: | ||
terraform: | ||
base_path: "components/terraform" | ||
apply_auto_approve: false | ||
deploy_run_init: true | ||
init_run_reconfigure: true | ||
auto_generate_backend_file: false | ||
|
||
stacks: | ||
base_path: "stacks" | ||
included_paths: | ||
- "orgs/**/*" | ||
excluded_paths: | ||
- "**/_defaults.yaml" | ||
name_pattern: "{namespace}-{tenant}-{stage}" | ||
|
||
logs: | ||
file: "/dev/stderr" | ||
level: Info |
50 changes: 50 additions & 0 deletions
50
tests/fixtures/scenarios/relative-paths/components/terraform/myapp/README.md
This file contains 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 @@ | ||
# Example Terraform Weather Component | ||
|
||
This Terraform "root" module fetches weather information for a specified location with custom display options. | ||
It queries data from the [`wttr.in`](https://wttr.in) weather service and stores the result in a local file (`cache.txt`). | ||
It also provides several outputs like weather information, request URL, stage, location, language, and units of measurement. | ||
|
||
## Features | ||
|
||
- Fetch weather updates for a location using HTTP request. | ||
- Write the obtained weather data in a local file. | ||
- Customizable display options. | ||
- View the request URL. | ||
- Get informed about the stage, location, language, and units in the metadata. | ||
|
||
## Usage | ||
|
||
To include this module in your [Atmos Stacks](https://atmos.tools/core-concepts/stacks) configuration: | ||
|
||
```yaml | ||
components: | ||
terraform: | ||
weather: | ||
vars: | ||
stage: dev | ||
location: New York | ||
options: 0T | ||
format: v2 | ||
lang: en | ||
units: m | ||
``` | ||
### Inputs | ||
- `stage`: Stage where it will be deployed. | ||
- `location`: Location for which the weather is reported. Default is "Los Angeles". | ||
- `options`: Options to customize the output. Default is "0T". | ||
- `format`: Specifies the output format. Default is "v2". | ||
- `lang`: Language in which the weather will be displayed. Default is "en". | ||
- `units`: Units in which the weather will be displayed. Default is "m". | ||
|
||
### Outputs | ||
- `weather`: The fetched weather data. | ||
- `url`: Requested URL. | ||
- `stage`: Stage of deployment. | ||
- `location`: Location of the reported weather. | ||
- `lang`: Language used for weather data. | ||
- `units`: Units of measurement for the weather data. | ||
|
||
Please note, this module requires Terraform version >=1.0.0, and you need to specify no other required providers. | ||
|
||
Happy Weather Tracking! |
22 changes: 22 additions & 0 deletions
22
tests/fixtures/scenarios/relative-paths/components/terraform/myapp/main.tf
This file contains 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,22 @@ | ||
locals { | ||
url = format("https://wttr.in/%v?%v&format=%v&lang=%v&u=%v", | ||
urlencode(var.location), | ||
urlencode(var.options), | ||
urlencode(var.format), | ||
urlencode(var.lang), | ||
urlencode(var.units), | ||
) | ||
} | ||
|
||
data "http" "weather" { | ||
url = local.url | ||
request_headers = { | ||
User-Agent = "curl" | ||
} | ||
} | ||
|
||
# Now write this to a file (as an example of a resource) | ||
resource "local_file" "cache" { | ||
filename = "cache.${var.stage}.txt" | ||
content = data.http.weather.response_body | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/fixtures/scenarios/relative-paths/components/terraform/myapp/outputs.tf
This file contains 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,27 @@ | ||
output "weather" { | ||
value = data.http.weather.response_body | ||
} | ||
|
||
output "url" { | ||
value = local.url | ||
} | ||
|
||
output "stage" { | ||
value = var.stage | ||
description = "Stage where it was deployed" | ||
} | ||
|
||
output "location" { | ||
value = var.location | ||
description = "Location of the weather report." | ||
} | ||
|
||
output "lang" { | ||
value = var.lang | ||
description = "Language which the weather is displayed." | ||
} | ||
|
||
output "units" { | ||
value = var.units | ||
description = "Units the weather is displayed." | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/fixtures/scenarios/relative-paths/components/terraform/myapp/variables.tf
This file contains 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,34 @@ | ||
variable "stage" { | ||
description = "Stage where it will be deployed" | ||
type = string | ||
} | ||
|
||
variable "location" { | ||
description = "Location for which the weather." | ||
type = string | ||
default = "Los Angeles" | ||
} | ||
|
||
variable "options" { | ||
description = "Options to customize the output." | ||
type = string | ||
default = "0T" | ||
} | ||
|
||
variable "format" { | ||
description = "Format of the output." | ||
type = string | ||
default = "v2" | ||
} | ||
|
||
variable "lang" { | ||
description = "Language in which the weather is displayed." | ||
type = string | ||
default = "en" | ||
} | ||
|
||
variable "units" { | ||
description = "Units in which the weather is displayed." | ||
type = string | ||
default = "m" | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/fixtures/scenarios/relative-paths/components/terraform/myapp/versions.tf
This file contains 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,5 @@ | ||
terraform { | ||
required_version = ">= 1.0.0" | ||
|
||
required_providers {} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/fixtures/scenarios/relative-paths/stacks/catalog/myapp.yaml
This file contains 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 @@ | ||
# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json | ||
|
||
components: | ||
terraform: | ||
myapp: | ||
vars: | ||
location: Los Angeles | ||
lang: en | ||
format: '' | ||
options: '0' | ||
units: m |
4 changes: 4 additions & 0 deletions
4
tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/_defaults.yaml
This file contains 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,4 @@ | ||
# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json | ||
|
||
vars: | ||
namespace: acme |
7 changes: 7 additions & 0 deletions
7
tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/_defaults.yaml
This file contains 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 @@ | ||
# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json | ||
|
||
import: | ||
- ../_defaults | ||
|
||
vars: | ||
tenant: platform |
15 changes: 15 additions & 0 deletions
15
tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/dev.yaml
This file contains 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,15 @@ | ||
# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json | ||
|
||
vars: | ||
stage: dev | ||
|
||
import: | ||
- ./_defaults | ||
- catalog/myapp | ||
|
||
components: | ||
terraform: | ||
myapp: | ||
vars: | ||
location: Stockholm | ||
lang: se |
15 changes: 15 additions & 0 deletions
15
tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/prod.yaml
This file contains 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,15 @@ | ||
# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json | ||
|
||
vars: | ||
stage: prod | ||
|
||
import: | ||
- ./_defaults | ||
- catalog/myapp | ||
|
||
components: | ||
terraform: | ||
myapp: | ||
vars: | ||
location: Los Angeles | ||
lang: en |
Oops, something went wrong.