Skip to content

Commit

Permalink
chore: Checking in working code with debugging
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Gettys <[email protected]>
  • Loading branch information
sgettys committed Mar 24, 2024
1 parent 7464f51 commit 5f612da
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 20 deletions.
4 changes: 2 additions & 2 deletions examples/multiple-mixin-configs/infra1/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "local_file" "foo" {
content = "foo"
filename = "${path.module}/foo"
content = var.infra1_var
filename = "${path.module}/infra1"
}
3 changes: 3 additions & 0 deletions examples/multiple-mixin-configs/infra1/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "infra1_output" {
value = var.infra1_var
}
5 changes: 4 additions & 1 deletion examples/multiple-mixin-configs/infra1/variables.tf
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@

variable "infra1_var" {
type = string
description = "Variable for infra 1 working dir"
}
4 changes: 2 additions & 2 deletions examples/multiple-mixin-configs/infra2/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "local_file" "foo" {
content = "bar"
filename = "${path.module}/foo"
content = var.infra2_var
filename = "${path.module}/infra1"
}
3 changes: 3 additions & 0 deletions examples/multiple-mixin-configs/infra2/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "infra2_output" {
value = var.infra2_var
}
4 changes: 4 additions & 0 deletions examples/multiple-mixin-configs/infra2/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "infra2_var" {
type = string
description = "Variable for infra 2 working dir"
}
50 changes: 48 additions & 2 deletions examples/multiple-mixin-configs/porter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ name: mulitple-mixin-configs
version: 0.1.0
registry: ghcr.io/getporter

parameters:
- name: infra1_var
type: string
default: 'infra1'
applyTo:
- 'install'
- 'upgrade'
- 'uninstall'
- name: infra2_var
type: string
default: 'infra2'
applyTo:
- 'install'
- 'upgrade'
- 'uninstall'
mixins:
- terraform:
workingDirs:
Expand All @@ -13,22 +28,53 @@ install:
- terraform:
description: 'infra 1'
workingDir: 'infra1'
vars:
infra1_var: ${bundle.parameters.infra1_var}
outputs:
- name: infra1_output
- terraform:
description: 'infra 2'
workingDir: 'infra2'
vars:
infra2_var: ${bundle.parameters.infra2_var}
outputs:
- name: infra2_output

upgrade:
- terraform:
description: 'Upgrade infra 1 assets'
workingDir: 'infra1'
vars:
infra1_var: ${bundle.parameters.infra1_var}
outputs:
- name: infra1_output
- terraform:
description: 'Upgrade infra 2 assets'
description: 'infra 2'
workingDir: 'infra2'
vars:
infra2_var: ${bundle.parameters.infra2_var}
outputs:
- name: infra2_output

uninstall:
- terraform:
description: 'Uninstall infra 1 assets'
workingDir: 'infra1'
vars:
infra1_var: ${bundle.parameters.infra1_var}
- terraform:
description: 'Uninstall infra 2 assets'
description: 'infra 2'
workingDir: 'infra2'
vars:
infra2_var: ${bundle.parameters.infra2_var}
outputs:
- name: infra1_output
type: string
applyTo:
- 'install'
- 'upgrade'
- name: infra2_output
type: string
applyTo:
- 'install'
- 'upgrade'
2 changes: 2 additions & 0 deletions pkg/terraform/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const defaultTerraformVarsFilename = "terraform.tfvars.json"

// Install runs a terraform apply
func (m *Mixin) Install(ctx context.Context) error {
fmt.Fprintf(m.Err, "\n\nIN INSTALL\n\n")
fmt.Printf("\n\nIN INSTALL\n\n")
action, err := m.loadAction(ctx)
if err != nil {
return err
Expand Down
20 changes: 7 additions & 13 deletions pkg/terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,18 @@ func (m *Mixin) commandPreRun(ctx context.Context, step *Step) error {
if step.LogLevel != "" {
os.Setenv("TF_LOG", step.LogLevel)
}

fmt.Fprintf(m.Err, "\n\nSTEP:\n\n%+v\n\n", step)
fmt.Fprintf(m.Err, "\n\nCONFIG:\n\n%+v\n\n", m.config)
// Determine the working directory for this step.
// If the config has WorkingDirs set then validate that the step has WorkingDir set to one of the values
// in the configs "WorkingDirs"
if m.config.WorkingDirs != nil {
// Validate that the step working dir is one of the values in the mixin config
validDir := false
if step.WorkingDir != "" {
stepDir := step.GetWorkingDir()
for _, dir := range m.config.WorkingDirs {
if dir == stepDir {
validDir = true
break
}
}
if !validDir {
return fmt.Errorf("requested working dir %s not found in configs working dirs", stepDir)
}
fmt.Fprintf(m.Err, "\n\nCDing STEP WORKINGDIR to %v\n\n", stepDir)
// Validate that the step working dir is one of the values in the mixin config
m.Chdir(stepDir)
} else {
fmt.Fprintf(m.Err, "\n\nCDing CONFIG to %v\n\n", m.config.WorkingDir)
m.Chdir(m.config.WorkingDir)
}
if m.DebugMode {
Expand All @@ -169,6 +162,7 @@ func (m *Mixin) commandPreRun(ctx context.Context, step *Step) error {

// Initialize Terraform
fmt.Println("Initializing Terraform...")
fmt.Println("HELLO")
err := m.Init(ctx, step.BackendConfig)
if err != nil {
return fmt.Errorf("could not init terraform, %s", err)
Expand Down

0 comments on commit 5f612da

Please sign in to comment.