Skip to content
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
20 changes: 15 additions & 5 deletions api/v1alpha1/blueprint_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ type TerraformComponent struct {
// FullPath is the complete path, not serialized to YAML.
FullPath string `yaml:"-"`

// DependsOn lists dependencies of this terraform component.
DependsOn []string `yaml:"dependsOn,omitempty"`

// Values are configuration values for the module.
Values map[string]any `yaml:"values,omitempty"`

Expand Down Expand Up @@ -235,12 +238,15 @@ func (b *Blueprint) DeepCopy() *Blueprint {
valuesCopy := make(map[string]any, len(component.Values))
maps.Copy(valuesCopy, component.Values)

dependsOnCopy := append([]string{}, component.DependsOn...)

terraformComponentsCopy[i] = TerraformComponent{
Source: component.Source,
Path: component.Path,
FullPath: component.FullPath,
Values: valuesCopy,
Destroy: component.Destroy,
Source: component.Source,
Path: component.Path,
FullPath: component.FullPath,
DependsOn: dependsOnCopy,
Values: valuesCopy,
Destroy: component.Destroy,
}
}

Expand Down Expand Up @@ -341,6 +347,10 @@ func (b *Blueprint) Merge(overlay *Blueprint) {
mergedComponent.FullPath = overlayComponent.FullPath
}

if overlayComponent.DependsOn != nil {
mergedComponent.DependsOn = overlayComponent.DependsOn
}

if overlayComponent.Destroy != nil {
mergedComponent.Destroy = overlayComponent.Destroy
}
Expand Down
55 changes: 33 additions & 22 deletions api/v1alpha1/blueprint_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ func TestBlueprint_Merge(t *testing.T) {
},
TerraformComponents: []TerraformComponent{
{
Source: "source1",
Path: "module/path1",
Values: map[string]any{"key1": "value1"},
FullPath: "original/full/path",
Destroy: ptrBool(true),
Source: "source1",
Path: "module/path1",
Values: map[string]any{"key1": "value1"},
FullPath: "original/full/path",
DependsOn: []string{},
Destroy: ptrBool(true),
},
},
Kustomizations: []Kustomization{
Expand Down Expand Up @@ -80,18 +81,20 @@ func TestBlueprint_Merge(t *testing.T) {
},
TerraformComponents: []TerraformComponent{
{
Source: "source1",
Path: "module/path1",
Values: map[string]any{"key2": "value2"},
FullPath: "updated/full/path",
Destroy: ptrBool(false),
Source: "source1",
Path: "module/path1",
Values: map[string]any{"key2": "value2"},
FullPath: "updated/full/path",
DependsOn: []string{"module/path2"},
Destroy: ptrBool(false),
},
{
Source: "source2",
Path: "module/path2",
Values: map[string]any{"key3": "value3"},
FullPath: "new/full/path",
Destroy: ptrBool(true),
Source: "source2",
Path: "module/path2",
Values: map[string]any{"key3": "value3"},
FullPath: "new/full/path",
DependsOn: []string{},
Destroy: ptrBool(true),
},
},
Kustomizations: []Kustomization{
Expand Down Expand Up @@ -170,6 +173,9 @@ func TestBlueprint_Merge(t *testing.T) {
if component1.FullPath != "updated/full/path" {
t.Errorf("Expected FullPath to be 'updated/full/path', but got '%s'", component1.FullPath)
}
if len(component1.DependsOn) != 1 || component1.DependsOn[0] != "module/path2" {
t.Errorf("Expected DependsOn to contain ['module/path2'], but got %v", component1.DependsOn)
}
if component1.Destroy == nil || *component1.Destroy != false {
t.Errorf("Expected Destroy to be false, but got %v", component1.Destroy)
}
Expand All @@ -181,6 +187,9 @@ func TestBlueprint_Merge(t *testing.T) {
if component2.FullPath != "new/full/path" {
t.Errorf("Expected FullPath to be 'new/full/path', but got '%s'", component2.FullPath)
}
if len(component2.DependsOn) != 0 {
t.Errorf("Expected DependsOn to be empty, but got %v", component2.DependsOn)
}
if component2.Destroy == nil || *component2.Destroy != true {
t.Errorf("Expected Destroy to be true, but got %v", component2.Destroy)
}
Expand Down Expand Up @@ -216,11 +225,12 @@ func TestBlueprint_Merge(t *testing.T) {
ApiVersion: "v1alpha1",
TerraformComponents: []TerraformComponent{
{
Source: "source1",
Path: "module/path1",
Values: nil, // Initialize with nil
FullPath: "original/full/path",
Destroy: ptrBool(true),
Source: "source1",
Path: "module/path1",
Values: nil, // Initialize with nil
FullPath: "original/full/path",
DependsOn: []string{},
Destroy: ptrBool(true),
},
},
}
Expand All @@ -233,8 +243,9 @@ func TestBlueprint_Merge(t *testing.T) {
Values: map[string]any{
"key1": "value1",
},
FullPath: "overlay/full/path",
Destroy: ptrBool(false),
FullPath: "overlay/full/path",
DependsOn: []string{"dependency1"},
Destroy: ptrBool(false),
},
},
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/env/shims.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package env

import (
"crypto/rand"
"encoding/json"
"os"
"os/exec"
"path/filepath"
Expand All @@ -28,6 +29,7 @@ type Shims struct {
ReadDir func(string) ([]os.DirEntry, error)
YamlUnmarshal func([]byte, any) error
YamlMarshal func(any) ([]byte, error)
JsonUnmarshal func([]byte, any) error
Remove func(string) error
RemoveAll func(string) error
CryptoRandRead func([]byte) (int, error)
Expand Down Expand Up @@ -55,6 +57,7 @@ func NewShims() *Shims {
ReadDir: os.ReadDir,
YamlUnmarshal: yaml.Unmarshal,
YamlMarshal: yaml.Marshal,
JsonUnmarshal: json.Unmarshal,
Remove: os.Remove,
RemoveAll: os.RemoveAll,
CryptoRandRead: func(b []byte) (int, error) { return rand.Read(b) },
Expand Down
Loading
Loading