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

Bugfix issue 89 #91

Merged
merged 3 commits into from
Aug 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 65 additions & 2 deletions build/testdata/bundles/terraform/porter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,66 @@ mixins:
name: terraform
version: 0.1.0
registry: getporterci
schemaVersion: 1.0.0

parameters:
- name: file_contents
type: string
applyTo:
- install
- upgrade
- name: map_var

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to add defaults to verify/test yaml notation maintains quotes as expected.

type: object
applyTo:
- install
- upgrade
- name: array_var
type: array
applyTo:
- install
- upgrade
- name: boolean_var
type: boolean
applyTo:
- install
- upgrade
- name: number_var
type: number
applyTo:
- install
- upgrade

install:
- terraform:
description: "Install Terraform assets"
vars:
file_contents: "{{bundle.parameters.file_contents}}"
file_contents: ${bundle.parameters.file_contents}
map_var: ${bundle.parameters.map_var}
array_var: ${bundle.parameters.array_var}
boolean_var: ${bundle.parameters.boolean_var}
number_var: ${bundle.parameters.number_var}
outputs:
- name: file_contents
- name: map_var
- name: array_var
- name: boolean_var
- name: number_var

upgrade:
- terraform:
description: "Upgrade Terraform assets"
vars:
file_contents: "{{ bundle.parameters.file_contents }}"
file_contents: ${bundle.parameters.file_contents}
map_var: ${bundle.parameters.map_var}
array_var: ${bundle.parameters.array_var}
boolean_var: ${bundle.parameters.boolean_var}
number_var: ${bundle.parameters.number_var}
outputs:
- name: file_contents
- name: map_var
- name: array_var
- name: boolean_var
- name: number_var

plan:
- terraform:
Expand All @@ -42,3 +79,29 @@ outputs:
applyTo:
- install
- upgrade
- name: map_var
type: object
applyTo:
- install
- upgrade
- name: array_var
type: array
applyTo:
- install
- upgrade
- name: boolean_var
type: boolean
applyTo:
- install
- upgrade
- name: number_var
type: number
applyTo:
- install
- upgrade

state:
- name: tfstate
path: terraform/terraform.tfstate
- name: tfvars
path: terraform/terraform.tfvars.json
6 changes: 3 additions & 3 deletions build/testdata/bundles/terraform/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "local_file" "foo" {
content = var.file_contents
filename = "${path.module}/foo"
}
content = var.file_contents
filename = "${path.module}/foo"
}
20 changes: 18 additions & 2 deletions build/testdata/bundles/terraform/terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
output "file_contents" {
value = var.file_contents
value = var.file_contents
description = "Contents of the file 'foo'"
}
}

output "map_var" {
value = var.map_var
}

output "array_var" {
value = var.array_var
}

output "boolean_var" {
value = var.boolean_var
}

output "number_var" {
value = var.number_var
}
25 changes: 24 additions & 1 deletion build/testdata/bundles/terraform/terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
variable "file_contents" {
description = "Contents of the file 'foo'"
default = "bar"
default = "bar"
}
variable "map_var" {
description = "Object variable"
type = map(string)
default = { foo = "bar" }
}

variable "array_var" {
description = "Array Variable"
type = list(any)
default = ["mylist"]
}

variable "boolean_var" {
description = "Boolean Variable"
type = bool
default = false
}

variable "number_var" {
description = "Number Variable"
type = number
default = 0
}
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ replace (
)

require (
get.porter.sh/magefiles v0.3.1
get.porter.sh/porter v1.0.0-alpha.11
github.com/carolynvs/magex v0.8.0
github.com/ghodss/yaml v1.0.0
github.com/hashicorp/go-multierror v1.1.1
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.1.3
github.com/stretchr/testify v1.7.0
github.com/tidwall/gjson v1.14.2
github.com/xeipuuv/gojsonschema v1.2.0
gopkg.in/yaml.v2 v2.4.0
)
Expand All @@ -32,7 +35,6 @@ require (
github.com/andybalholm/brotli v1.0.0 // indirect
github.com/andybalholm/cascadia v1.0.0 // indirect
github.com/carolynvs/aferox v0.3.0 // indirect
github.com/carolynvs/magex v0.6.0 // indirect
github.com/cbroglie/mustache v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.1 // indirect
github.com/cnabio/cnab-go v0.22.1-0.20220219202519-002f3523865a // indirect
Expand All @@ -53,9 +55,9 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jeremywohl/flatten v1.0.1 // indirect
github.com/karrick/godirwalk v1.16.1 // indirect
github.com/klauspost/compress v1.12.3 // indirect
github.com/klauspost/compress v1.15.1 // indirect
github.com/klauspost/pgzip v1.2.4 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/magefile/mage v1.11.0 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/markbates/errx v1.1.0 // indirect
Expand All @@ -69,7 +71,6 @@ require (
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/mmcdole/gofeed v1.0.0-beta2 // indirect
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/nwaples/rardecode v1.1.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/olekukonko/tablewriter v0.0.4 // indirect
Expand All @@ -89,6 +90,8 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/ulikunitz/xz v0.5.7 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
Expand Down Expand Up @@ -116,7 +119,6 @@ require (
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/ini.v1 v1.56.0 // indirect
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
Expand Down
19 changes: 15 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ contrib.go.opencensus.io/exporter/stackdriver v0.12.1/go.mod h1:iwB6wGarfphGGe/e
contrib.go.opencensus.io/integrations/ocsql v0.1.4/go.mod h1:8DsSdjz3F+APR+0z0WkU1aRorQCFfRxvqjUUPMbF3fE=
contrib.go.opencensus.io/resource v0.1.1/go.mod h1:F361eGI91LCmW1I/Saf+rX0+OFcigGlFvXwEGEnkRLA=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
get.porter.sh/magefiles v0.3.1 h1:YdjBTzPbwHTq22XaJL69DO79mCQosHCMtWbOyCr7OsA=
get.porter.sh/magefiles v0.3.1/go.mod h1:lwDECEEivbBHACLImnDEhwlr8g3E4xZR1W0DO8FOGa8=
get.porter.sh/porter v1.0.0-alpha.11 h1:uCD9cdWneCziXhkmJ/BKTdSQtp7/u0sceVtzrX8K+4c=
get.porter.sh/porter v1.0.0-alpha.11/go.mod h1:Ck2zoFZHEt8F0UJWxgDPrOW77jhPCGsYAz13mVGSWT0=
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
Expand Down Expand Up @@ -234,8 +236,9 @@ github.com/carolynvs/aferox v0.3.0 h1:CMT50zX88amTMbFfFIWSTKRVRaOw6sejUMbbKiCD4z
github.com/carolynvs/aferox v0.3.0/go.mod h1:eb7CHGIO33CCZS//xtnblvPZbuuZMv0p1VbhiSwZnH4=
github.com/carolynvs/datetime-printer v0.2.0/go.mod h1:p9W8ZUhmQUOVD5kiDuGXwRG65/nTkZWlLylY7s+Qw2k=
github.com/carolynvs/go-plugin v1.0.1-acceptstdin/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
github.com/carolynvs/magex v0.6.0 h1:rzz4RnBiR8hr2WYEsmq+mqkRLEstPnEK8ZP9MgxNY9Y=
github.com/carolynvs/magex v0.6.0/go.mod h1:hqaEkr9TAv+kFb/5wgDiTdszF13rpe0Q+bWHmTe6N74=
github.com/carolynvs/magex v0.8.0 h1:BCY0A6fLs37NZrIFBKuOMXda5wEIrUeTF4sHB601JVM=
github.com/carolynvs/magex v0.8.0/go.mod h1:vZB3BkRfkd5ZMtkxJkCGbdFyWGoZiuNPKhx6uEQARmY=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e/go.mod h1:oDpT4efm8tSYHXV5tHSdRvBet/b/QzxZ+XyyPehvm3A=
github.com/cbroglie/mustache v1.0.1 h1:ivMg8MguXq/rrz2eu3tw6g3b16+PQhoTn6EZAhst2mw=
Expand Down Expand Up @@ -872,8 +875,9 @@ github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0
github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.11.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.11.13/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.12.3 h1:G5AfA94pHPysR56qqrkO2pxEexdDzrpFJ6yt/VqWxVU=
github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/klauspost/compress v1.15.1 h1:y9FcTHGyrebwfP0ZZqFiaxTaiDnUrGkJkI+f583BL1A=
github.com/klauspost/compress v1.15.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/pgzip v1.2.4 h1:TQ7CNpYKovDOmqzRHKxJh0BeaBI7UdQZYc6p7pMQh1A=
Expand All @@ -885,6 +889,7 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down Expand Up @@ -1028,7 +1033,6 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
github.com/nwaples/rardecode v1.1.0 h1:vSxaY8vQhOcVr4mm5e8XllHWTiM4JF507A0Katqw7MQ=
Expand Down Expand Up @@ -1289,7 +1293,13 @@ github.com/tdakkota/asciicheck v0.0.0-20200416200610-e657995f937b/go.mod h1:yHp0
github.com/tetafro/godot v0.3.7/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
github.com/tetafro/godot v0.4.2/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
github.com/theupdateframework/notary v0.6.1/go.mod h1:MOfgIfmox8s7/7fduvB2xyPPMJCrjRLRizA8OFwpnKY=
github.com/tidwall/gjson v1.14.2 h1:6BBkirS0rAHjumnjHF6qgy5d2YAJ1TLIaFE2lzfOLqo=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
github.com/timakin/bodyclose v0.0.0-20200424151742-cb6215831a94/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0=
Expand Down Expand Up @@ -1901,8 +1911,9 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20141024133853-64131543e789/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/dancannon/gorethink.v3 v3.0.5/go.mod h1:GXsi1e3N2OcKhcP6nsYABTiUejbWMFO4GY5a4pEaeEc=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
Expand Down
27 changes: 23 additions & 4 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@ package main

import (
"get.porter.sh/porter/mage/mixins"
"github.com/carolynvs/magex/shx"

porter "get.porter.sh/magefiles/porter"
// Import common targets that all mixins should expose to the user
// mage:import
_ "get.porter.sh/porter/mage"
)

const (
mixinName = "terraform"
mixinPackage = "get.porter.sh/mixin/terraform"
mixinBin = "bin/mixins/" + mixinName
mixinName = "terraform"
mixinPackage = "get.porter.sh/mixin/terraform"
mixinBin = "bin/mixins/" + mixinName
porterVersion = "v1.0.0-beta.2"
)

var magefile = mixins.NewMagefile(mixinPackage, mixinName, mixinBin)
var (
magefile = mixins.NewMagefile(mixinPackage, mixinName, mixinBin)
must = shx.CommandBuilder{StopOnError: true}
)

// Build the mixin
func Build() {
Expand All @@ -36,6 +42,8 @@ func TestUnit() {

func Test() {
magefile.Test()
Build()
TestIntegration()
}

// Publish the mixin to github
Expand All @@ -52,3 +60,14 @@ func Install() {
func Clean() {
magefile.Clean()
}

// Install porter locally
func EnsureLocalPorter() {
porter.UseBinForPorterHome()
porter.EnsurePorterAt(porterVersion)
}

func TestIntegration() {
EnsureLocalPorter()
must.Command("./scripts/test/test-cli.sh").RunV()
}
8 changes: 4 additions & 4 deletions pkg/terraform/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ type Instruction struct {

// TerraformFields represent fields specific to Terraform
type TerraformFields struct {
Vars map[string]string `yaml:"vars,omitempty"`
DisableVarFile bool `yaml:"disableVarFile,omitempty"`
LogLevel string `yaml:"logLevel,omitempty"`
BackendConfig map[string]string `yaml:"backendConfig,omitempty"`
Vars map[string]interface{} `yaml:"vars,omitempty"`
DisableVarFile bool `yaml:"disableVarFile,omitempty"`
LogLevel string `yaml:"logLevel,omitempty"`
BackendConfig map[string]interface{} `yaml:"backendConfig,omitempty"`
}

type Output struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/terraform/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewTestMixin(t *testing.T) *TestMixin {
}
}

func sortKeys(m map[string]string) []string {
func sortKeys(m map[string]interface{}) []string {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
Expand Down
8 changes: 4 additions & 4 deletions pkg/terraform/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
)

func TestSortKeys(t *testing.T) {
m := map[string]string{
m := map[string]interface{}{
"delicious": "true",
"apples": "green",
"are": "needed",
"apples": "green",
"are": "needed",
}

expected := []string{
Expand All @@ -20,4 +20,4 @@ func TestSortKeys(t *testing.T) {
}

assert.Equal(t, expected, sortKeys(m))
}
}