Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
TER-250: add parameters to feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Caussat committed Mar 29, 2018
1 parent 6e0c63f commit aef1eed
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 5 deletions.
16 changes: 16 additions & 0 deletions ghost/resource_ghost_app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ghost

import (
"encoding/json"
"fmt"
"log"

Expand Down Expand Up @@ -326,6 +327,11 @@ func resourceGhostApp() *schema.Resource {
Optional: true,
ValidateFunc: MatchesRegexp(`^[a-zA-Z0-9]*$`),
},
"parameters": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.ValidateJsonString,
},
},
},
},
Expand Down Expand Up @@ -706,12 +712,21 @@ func expandGhostAppFeatures(d []interface{}) *[]ghost.Feature {

for _, config := range d {
data := config.(map[string]interface{})

feature := ghost.Feature{
Name: data["name"].(string),
Version: data["version"].(string),
Provisioner: data["provisioner"].(string),
}

if param := data["parameters"]; param != nil {
var jsonDoc interface{}
if err := json.Unmarshal([]byte(param.(string)), &jsonDoc); err != nil {
log.Printf("Error loading feature paramaters json: %v", err)
}
feature.Parameters = jsonDoc
}

*features = append(*features, feature)
}

Expand All @@ -730,6 +745,7 @@ func flattenGhostAppFeatures(features *[]ghost.Feature) []interface{} {
"name": feature.Name,
"version": feature.Version,
"provisioner": feature.Provisioner,
"parameters": feature.Parameters,
}

featureList = append(featureList, values)
Expand Down
82 changes: 80 additions & 2 deletions ghost/resource_ghost_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,17 @@ func testAccGhostAppConfig(name string) string {
name = "php5"
},
{
version = "2.2"
name = "apache2"
version = ""
name = "package"
provisioner = "ansible"
parameters = <<JSON
{
"package_name" : [
"test",
"nano"
]
}
JSON
}]
lifecycle_hooks = {
Expand Down Expand Up @@ -166,6 +175,7 @@ var (
Name: "feature",
Version: "1.0",
Provisioner: "ansible",
Parameters: nil,
}},
Autoscale: &ghost.Autoscale{
Name: "autoscale",
Expand Down Expand Up @@ -411,16 +421,63 @@ func TestExpandGhostAppFeatures(t *testing.T) {
Input []interface{}
ExpectedOutput *[]ghost.Feature
}{
// Parameters nil
{
[]interface{}{
map[string]interface{}{
"name": "feature",
"version": "1.0",
"provisioner": "ansible",
"parameters": nil,
},
},
app.Features,
},
// Valid parameters json
{
[]interface{}{
map[string]interface{}{
"name": "feature",
"version": "1",
"provisioner": "ansible",
"parameters": `{
"package_name" : [
"test",
"nano"
]
}`,
},
},
&[]ghost.Feature{{
Name: "feature",
Version: "1",
Provisioner: "ansible",
Parameters: map[string]interface{}{
"package_name": []interface{}{"test", "nano"},
},
}},
},
// Wrong parameters json
{
[]interface{}{
map[string]interface{}{
"name": "feature",
"version": "1",
"provisioner": "ansible",
"parameters": `{
"package_name" : [
"test",
"nano"
}`,
},
},
&[]ghost.Feature{{
Name: "feature",
Version: "1",
Provisioner: "ansible",
Parameters: nil,
}},
},
{
nil,
&[]ghost.Feature{},
Expand Down Expand Up @@ -768,6 +825,27 @@ func TestFlattenGhostAppFeatures(t *testing.T) {
"name": "feature",
"version": "1.0",
"provisioner": "ansible",
"parameters": nil,
},
},
},
{
&[]ghost.Feature{{
Name: "feature",
Version: "1",
Provisioner: "ansible",
Parameters: map[string]interface{}{
"package_name": []interface{}{"test", "nano"},
},
}},
[]interface{}{
map[string]interface{}{
"name": "feature",
"version": "1",
"provisioner": "ansible",
"parameters": map[string]interface{}{
"package_name": []interface{}{"test", "nano"},
},
},
},
},
Expand Down
7 changes: 4 additions & 3 deletions vendor/cloud-deploy.io/go-st/spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aef1eed

Please sign in to comment.