Skip to content

Commit

Permalink
Merge pull request #97 from VinozzZ/main
Browse files Browse the repository at this point in the history
Update repo to use porter v1.0.0-rc.2
  • Loading branch information
VinozzZ committed Sep 21, 2022
2 parents 6199f64 + b5feb0a commit 090064b
Show file tree
Hide file tree
Showing 30 changed files with 452 additions and 1,333 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pool:
steps:
- task: GoTool@0
inputs:
version: '1.17.6'
version: '1.18.6'
displayName: 'Install Go'

- script: go run mage.go ConfigureAgent
Expand Down
2 changes: 1 addition & 1 deletion cmd/terraform/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func buildBuildCommand(m *terraform.Mixin) *cobra.Command {
Use: "build",
Short: "Generate Dockerfile lines for the bundle invocation image",
RunE: func(cmd *cobra.Command, args []string) error {
return m.Build()
return m.Build(cmd.Context())
},
}
return cmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/terraform/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func buildInstallCommand(m *terraform.Mixin) *cobra.Command {
Use: "install",
Short: "Execute the install functionality of this mixin",
RunE: func(cmd *cobra.Command, args []string) error {
return m.Install()
return m.Install(cmd.Context())
},
}
return cmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/terraform/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func buildInvokeCommand(mixin *terraform.Mixin) *cobra.Command {
Use: "invoke",
Short: "Execute the invoke functionality of this mixin",
RunE: func(cmd *cobra.Command, args []string) error {
return mixin.Invoke(opts)
return mixin.Invoke(cmd.Context(), opts)
},
}
flags := cmd.Flags()
Expand Down
48 changes: 40 additions & 8 deletions cmd/terraform/main.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,69 @@
package main

import (
"context"
"fmt"
"io"
"os"
"runtime/debug"

"get.porter.sh/mixin/terraform/pkg/terraform"
"get.porter.sh/porter/pkg/cli"
"github.com/spf13/cobra"
"go.opentelemetry.io/otel/attribute"
)

func main() {
cmd := buildRootCommand(os.Stdin)
if err := cmd.Execute(); err != nil {
fmt.Printf("err: %s\n", err)
os.Exit(1)
run := func() int {
ctx := context.Background()
m := terraform.New()
if err := m.ConfigureLogging(ctx); err != nil {
fmt.Println(err)
os.Exit(cli.ExitCodeErr)
}
cmd := buildRootCommand(m, os.Stdin)

// We don't have tracing working inside a bundle working currently.
// We are using StartRootSpan anyway because it creates a TraceLogger and sets it
// on the context, so we can grab it later
ctx, log := m.StartRootSpan(ctx, "terraform")
defer func() {
// Capture panics and trace them
if panicErr := recover(); panicErr != nil {
log.Error(fmt.Errorf("%s", panicErr),
attribute.Bool("panic", true),
attribute.String("stackTrace", string(debug.Stack())))
log.EndSpan()
m.Close()
os.Exit(cli.ExitCodeErr)
} else {
log.Close()
m.Close()
}
}()

if err := cmd.ExecuteContext(ctx); err != nil {
return cli.ExitCodeErr
}
return cli.ExitCodeSuccess
}
os.Exit(run())
}

func buildRootCommand(in io.Reader) *cobra.Command {
m := terraform.New()
m.In = in
func buildRootCommand(m *terraform.Mixin, in io.Reader) *cobra.Command {
cmd := &cobra.Command{
Use: "terraform",
Long: "A terraform mixin for porter 👩🏽‍✈️",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Enable swapping out stdout/stderr for testing
m.In = in
m.Out = cmd.OutOrStdout()
m.Err = cmd.OutOrStderr()
},
SilenceUsage: true,
}

cmd.PersistentFlags().BoolVar(&m.Debug, "debug", false, "Enable debug logging")
cmd.PersistentFlags().BoolVar(&m.DebugMode, "debug", false, "Enable debug logging")

cmd.AddCommand(buildVersionCommand(m))
cmd.AddCommand(buildSchemaCommand(m))
Expand Down
2 changes: 1 addition & 1 deletion cmd/terraform/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func buildUninstallCommand(m *terraform.Mixin) *cobra.Command {
Use: "uninstall",
Short: "Execute the uninstall functionality of this mixin",
RunE: func(cmd *cobra.Command, args []string) error {
return m.Uninstall()
return m.Uninstall(cmd.Context())
},
}
return cmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/terraform/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func buildUpgradeCommand(m *terraform.Mixin) *cobra.Command {
Use: "upgrade",
Short: "Execute the upgrade functionality of this mixin",
RunE: func(cmd *cobra.Command, args []string) error {
return m.Upgrade()
return m.Upgrade(cmd.Context())
},
}
return cmd
Expand Down
45 changes: 23 additions & 22 deletions examples/azure-aks/porter.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
mixins:
- terraform:
initFile: providers.tf

schemaVersion: 1.0.0
name: terraform-aks
version: 0.1.0
registry: getporter
version: 0.2.0
registry: ghcr.io/getporter

credentials:
- name: subscription_id
Expand Down Expand Up @@ -62,6 +59,10 @@ parameters:
default: "porteraks"
env: TF_VAR_resource_group_name

mixins:
- terraform:
initFile: providers.tf

customActions:
show:
description: "Invoke 'terraform show'"
Expand All @@ -71,34 +72,34 @@ install:
- terraform:
description: "Install Azure Kubernetes Service"
backendConfig:
key: "{{ bundle.name }}.tfstate"
storage_account_name: "{{ bundle.credentials.backend_storage_account }}"
container_name: "{{ bundle.credentials.backend_storage_container }}"
access_key: "{{ bundle.credentials.backend_storage_access_key }}"
key: ${ bundle.name }.tfstate
storage_account_name: ${ bundle.credentials.backend_storage_account }
container_name: ${ bundle.credentials.backend_storage_container }
access_key: ${ bundle.credentials.backend_storage_access_key }

upgrade:
- terraform:
description: "Upgrade Azure Kubernetes Service"
backendConfig:
key: "{{ bundle.name }}.tfstate"
storage_account_name: "{{ bundle.credentials.backend_storage_account }}"
container_name: "{{ bundle.credentials.backend_storage_container }}"
access_key: "{{ bundle.credentials.backend_storage_access_key }}"
key: ${ bundle.name }.tfstate
storage_account_name: ${ bundle.credentials.backend_storage_account }
container_name: ${ bundle.credentials.backend_storage_container }
access_key: ${ bundle.credentials.backend_storage_access_key }

show:
- terraform:
description: "Invoke 'terraform show'"
backendConfig:
key: "{{ bundle.name }}.tfstate"
storage_account_name: "{{ bundle.credentials.backend_storage_account }}"
container_name: "{{ bundle.credentials.backend_storage_container }}"
access_key: "{{ bundle.credentials.backend_storage_access_key }}"
key: ${ bundle.name }.tfstate
storage_account_name: ${ bundle.credentials.backend_storage_account }
container_name: ${ bundle.credentials.backend_storage_container }
access_key: ${ bundle.credentials.backend_storage_access_key }

uninstall:
- terraform:
description: "Uninstall Azure Kubernetes Service"
backendConfig:
key: "{{ bundle.name }}.tfstate"
storage_account_name: "{{ bundle.credentials.backend_storage_account }}"
container_name: "{{ bundle.credentials.backend_storage_container }}"
access_key: "{{ bundle.credentials.backend_storage_access_key }}"
key: ${ bundle.name }.tfstate
storage_account_name: ${ bundle.credentials.backend_storage_account }
container_name: ${ bundle.credentials.backend_storage_container }
access_key: ${ bundle.credentials.backend_storage_access_key }
4 changes: 2 additions & 2 deletions examples/azure-aks/terraform/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ provider "azurerm" {
}

terraform {
required_version = "1.0.4"
required_version = "1.2.9"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.72.0"
version = "=3.22.0"
}
}
backend "azurerm" {}
Expand Down
46 changes: 24 additions & 22 deletions examples/azure-keyvault/porter.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
mixins:
- exec
- terraform:
initFile: providers.tf

schemaVersion: 1.0.0
name: terraform-keyvault
version: 0.1.0
registry: getporter
version: 0.2.0
registry: ghcr.io/getporter

credentials:
- name: subscription_id
Expand Down Expand Up @@ -45,6 +42,11 @@ parameters:
default: "porterkvtest"
env: TF_VAR_resource_group_name

mixins:
- exec
- terraform:
initFile: providers.tf

customActions:
show:
description: "Invoke 'terraform show'"
Expand All @@ -54,40 +56,40 @@ install:
- terraform:
description: "Install Azure Key Vault"
backendConfig:
key: "{{ bundle.name }}.tfstate"
storage_account_name: "{{ bundle.credentials.backend_storage_account }}"
container_name: "{{ bundle.credentials.backend_storage_container }}"
access_key: "{{ bundle.credentials.backend_storage_access_key }}"
key: ${ bundle.name }.tfstate
storage_account_name: ${ bundle.credentials.backend_storage_account }
container_name: ${ bundle.credentials.backend_storage_container }
access_key: ${ bundle.credentials.backend_storage_access_key }
outputs:
- name: vault_uri

upgrade:
- terraform:
description: "Upgrade Azure Key Vault"
backendConfig:
key: "{{ bundle.name }}.tfstate"
storage_account_name: "{{ bundle.credentials.backend_storage_account }}"
container_name: "{{ bundle.credentials.backend_storage_container }}"
access_key: "{{ bundle.credentials.backend_storage_access_key }}"
key: ${ bundle.name }.tfstate
storage_account_name: ${ bundle.credentials.backend_storage_account }
container_name: ${ bundle.credentials.backend_storage_container }
access_key: ${ bundle.credentials.backend_storage_access_key }
outputs:
- name: vault_uri

show:
- terraform:
description: "Invoke 'terraform show'"
backendConfig:
key: "{{ bundle.name }}.tfstate"
storage_account_name: "{{ bundle.credentials.backend_storage_account }}"
container_name: "{{ bundle.credentials.backend_storage_container }}"
access_key: "{{ bundle.credentials.backend_storage_access_key }}"
key: ${ bundle.name }.tfstate
storage_account_name: ${ bundle.credentials.backend_storage_account }
container_name: ${ bundle.credentials.backend_storage_container }
access_key: ${ bundle.credentials.backend_storage_access_key }
outputs:
- name: vault_uri

uninstall:
- terraform:
description: "Uninstall Azure Key Vault"
backendConfig:
key: "{{ bundle.name }}.tfstate"
storage_account_name: "{{ bundle.credentials.backend_storage_account }}"
container_name: "{{ bundle.credentials.backend_storage_container }}"
access_key: "{{ bundle.credentials.backend_storage_access_key }}"
key: ${ bundle.name }.tfstate
storage_account_name: ${ bundle.credentials.backend_storage_account }
container_name: ${ bundle.credentials.backend_storage_container }
access_key: ${ bundle.credentials.backend_storage_access_key }
4 changes: 2 additions & 2 deletions examples/azure-keyvault/terraform/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ provider "azurerm" {
}

terraform {
required_version = "1.0.4"
required_version = "1.2.9"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.72.0"
version = "=3.22.0"
}
}
backend "azurerm" {}
Expand Down
17 changes: 9 additions & 8 deletions examples/basic-tf-example/porter.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
mixins:
- terraform:
clientVersion: 1.0.0

schemaVersion: 1.0.0
name: basic-tf-example
version: 0.1.0
registry: getporterci
version: 0.2.0
registry: ghcr.io/getporter

parameters:
- name: tfstate
Expand All @@ -25,20 +23,23 @@ outputs:
applyTo:
- install
- upgrade
mixins:
- terraform:
clientVersion: 1.0.0

install:
- terraform:
description: "Install Terraform assets"
vars:
myvar: "{{bundle.parameters.myvar}}"
myvar: ${bundle.parameters.myvar}
outputs:
- name: myvar

upgrade:
- terraform:
description: "Upgrade Terraform assets"
vars:
myvar: "{{bundle.parameters.myvar}}"
myvar: ${bundle.parameters.myvar}
outputs:
- name: myvar

Expand All @@ -53,7 +54,7 @@ plan:
no-color:
out: "/dev/null"
var:
- "'myvar={{bundle.parameters.myvar}}'"
- "'myvar=${bundle.parameters.myvar}'"

# Note: this can't be 'version:' as this would conflict with top-level field
# Hence the need for the 'arguments:' override
Expand Down
Loading

0 comments on commit 090064b

Please sign in to comment.