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

feat: Support Relative Path Imports #891

Merged
merged 48 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c50d071
Handle relative paths for stack imports
milldr Dec 24, 2024
f79e16a
Tests for relative paths
milldr Dec 24, 2024
74ab1d8
Refactor handling of relative paths in ProcessImportSection
milldr Dec 24, 2024
e2af2db
Handle relative paths in StackImport.Path and string imports
milldr Dec 24, 2024
9d39012
Add new test2/us-west-1.yaml file and update test counts
milldr Dec 24, 2024
12358b0
Update import paths in us-west-1.yaml file
milldr Dec 24, 2024
093ac5e
Merge branch 'main' into feat/DEV-1856_relative-paths
milldr Dec 24, 2024
b9856ff
Merge branch 'main' into feat/DEV-1856_relative-paths
osterman Dec 26, 2024
71eaca0
Merge branch 'main' into feat/DEV-1856_relative-paths
milldr Dec 26, 2024
4f6170c
Merge branch 'feat/DEV-1856_relative-paths' of github.com:cloudposse/…
milldr Dec 26, 2024
362e979
Merge branch 'main' into feat/DEV-1856_relative-paths
milldr Dec 27, 2024
8d76059
Refactor handling of import paths in ProcessImportSection
milldr Dec 27, 2024
1beeb8a
Resolve relative paths in ProcessImportSection function
milldr Dec 27, 2024
dd55c0f
Update internal/exec/stack_processor_utils.go
milldr Dec 27, 2024
dfa5a84
Refactor resolveRelativePath for improved path handling
milldr Dec 27, 2024
507a5dd
Refactor filepath handling for better readability
milldr Dec 27, 2024
cafdfdd
Remove unnecessary path normalization code and simplify logic
milldr Dec 27, 2024
ddde3d5
Improve path resolution handling in stack_processor_utils
milldr Dec 27, 2024
4eeef33
Merge branch 'main' into feat/DEV-1856_relative-paths
milldr Jan 2, 2025
7fa809e
relative path handling improvements for windows; added security check…
milldr Jan 3, 2025
3be0d81
Validate import paths for security and base path inclusion
milldr Jan 3, 2025
2f89d4a
Update path.Join calls to use filepath.Join for consistency
milldr Jan 3, 2025
2c80a89
Update stack_processor_utils.go to use filepath package
milldr Jan 3, 2025
062cf05
validate stack paths to check against the global base path
milldr Jan 3, 2025
3d98cd4
Refactor path resolution and validation logic
milldr Jan 3, 2025
558c324
Refactor resolving relative path logic for clarity
milldr Jan 3, 2025
88740a5
Revert changes
milldr Jan 3, 2025
94886b6
Refactor path resolution for consistency
milldr Jan 3, 2025
1bc256a
Refactor resolveRelativePath function for path consistency
milldr Jan 3, 2025
037e0ba
Convert relative path to base path if starts with "." or ".."
milldr Jan 3, 2025
358128c
Simplify resolving relative paths in stack_processor_utils
milldr Jan 3, 2025
7bf9208
added tests for atmos stacks with relative paths
milldr Jan 3, 2025
29b390d
Merge branch 'main' into feat/DEV-1856_relative-paths
milldr Jan 3, 2025
daefbe1
merge
milldr Jan 7, 2025
10d41dc
PR feedback
milldr Jan 7, 2025
9767879
merged main, incorporate new test fixture pattern
milldr Jan 7, 2025
fcf08fc
Merge branch 'main' into feat/DEV-1856_relative-paths
milldr Jan 9, 2025
229aa91
Add test case for atmos stacks with relative paths
milldr Jan 9, 2025
8e47d61
Delete nonprod and prod cache weather files
milldr Jan 9, 2025
b215eca
Delete outdated Atmos manifest JSON schema
milldr Jan 9, 2025
bcd13ac
consistent indentation
milldr Jan 9, 2025
57b557f
Add ignore rule for cache text files
milldr Jan 9, 2025
6faf6dd
Update stack processor test cases and relative paths
milldr Jan 9, 2025
187e61b
revert cahnges
milldr Jan 9, 2025
a482907
use relative paths in advanced usage example
milldr Jan 9, 2025
dc897c7
use relative paths in advanced usage example
milldr Jan 9, 2025
a427817
reset advanced usage
milldr Jan 9, 2025
fb6ac32
added relative paths to demo-context
milldr Jan 9, 2025
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
10 changes: 10 additions & 0 deletions examples/demo-relative-paths/.gitignore
milldr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/.terraform/**
**/.terraform.lock.hcl
**/.terraform.tfstate/**
**/.terraform.tfstate.backup/**
**/*.tfvars.json
**/*.planfile
**/terraform.tfstate
**/terraform.tfstate.backup
**/terraform.tfstate.d/**
**/cache.*.txt
25 changes: 25 additions & 0 deletions examples/demo-relative-paths/atmos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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

schemas:
atmos:
manifest: "stacks/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json"
50 changes: 50 additions & 0 deletions examples/demo-relative-paths/components/terraform/myapp/README.md
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 examples/demo-relative-paths/components/terraform/myapp/main.tf
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"
}
}
milldr marked this conversation as resolved.
Show resolved Hide resolved

# 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 examples/demo-relative-paths/components/terraform/myapp/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
output "weather" {
value = data.http.weather.response_body
}
milldr marked this conversation as resolved.
Show resolved Hide resolved

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."
}
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"
}
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 examples/demo-relative-paths/stacks/catalog/myapp.yaml
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 examples/demo-relative-paths/stacks/orgs/acme/_defaults.yaml
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
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 examples/demo-relative-paths/stacks/orgs/acme/platform/dev.yaml
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 examples/demo-relative-paths/stacks/orgs/acme/platform/prod.yaml
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
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: staging

import:
- ./_defaults
- catalog/myapp

components:
terraform:
myapp:
vars:
location: Los Angeles
lang: en
Loading
Loading