Skip to content

Commit

Permalink
Merged in TER-235-add-create-ghost-app-feature (pull request #3)
Browse files Browse the repository at this point in the history
TER-235 add create ghost app feature

Approved-by: Jordan Caussat <[email protected]>
Approved-by: Patrick Decat <[email protected]>
Approved-by: Jérôme Respaut <[email protected]>
  • Loading branch information
Jordan Caussat authored and Shr3ps committed Mar 30, 2018
2 parents 4c6d612 + 45d2a08 commit c8dee63
Show file tree
Hide file tree
Showing 14 changed files with 1,351 additions and 136 deletions.
3 changes: 3 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ test:
testacc:
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m

testacc-no-cache:
TF_ACC=1 GOCACHE=off go test $(TEST) -v $(TESTARGS) -timeout 120m

vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
Expand Down
47 changes: 41 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,47 @@ resource "ghost_app" "test" {
environment_infos = {
instance_profile = "iam.ec2.demo"
key_name = "ghost-demo"
root_block_device = {}
optional_volumes = []
root_block_device = {
name = "testblockdevice"
size = 20
}
optional_volumes = [{
device_name = "/dev/xvdd"
volume_type = "gp2"
volume_size = 20
}]
subnet_ids = ["subnet-a7e849fe"]
security_groups = ["sg-6814f60c"]
security_groups = ["sg-6814f60c", "sg-2414f60c"]
instance_tags = [{
tag_name = "Name"
tag_value = "wordpress"
},
{
tag_name = "Type"
tag_value = "front"
}]
}
autoscale = {
name = ""
name = "autoscale"
min = 1
max = 3
}
modules = [{
name = "symfony2"
pre_deploy = "ZXhpdCAx"
name = "wordpress"
pre_deploy = ""
path = "/var/www"
scope = "code"
git_repo = "https://github.com/KnpLabs/KnpIpsum.git"
},
{
name = "wordpress2"
pre_deploy = "ZXhpdCAx"
post_deploy = "ZXhpdCAx"
path = "/var/www"
scope = "code"
git_repo = "https://github.com/KnpLabs/KnpIpsum.git"
}]
features = [{
Expand All @@ -112,5 +137,15 @@ resource "ghost_app" "test" {
version = "2.2"
name = "apache2"
}]
lifecycle_hooks = {
pre_buildimage = "#!/usr/bin/env bash"
post_buildimage = "#!/usr/bin/env bash"
}
environment_variables = [{
key = "myvar"
value = "myvalue"
}]
}
```
47 changes: 41 additions & 6 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,47 @@ resource "ghost_app" "test" {
environment_infos = {
instance_profile = "iam.ec2.demo"
key_name = "ghost-demo"
root_block_device = {}
optional_volumes = []
root_block_device = {
name = "testblockdevice"
size = 20
}
optional_volumes = [{
device_name = "/dev/xvdd"
volume_type = "gp2"
volume_size = 20
}]
subnet_ids = ["subnet-a7e849fe"]
security_groups = ["sg-6814f60c"]
security_groups = ["sg-6814f60c", "sg-2414f60c"]
instance_tags = [{
tag_name = "Name"
tag_value = "wordpress"
},
{
tag_name = "Type"
tag_value = "front"
}]
}

autoscale = {
name = ""
name = "autoscale"
min = 1
max = 3
}

modules = [{
name = "symfony2"
pre_deploy = "ZXhpdCAx"
name = "wordpress"
pre_deploy = ""
path = "/var/www"
scope = "code"
git_repo = "https://github.com/KnpLabs/KnpIpsum.git"
},
{
name = "wordpress2"
pre_deploy = "ZXhpdCAx"
post_deploy = "ZXhpdCAx"
path = "/var/www"
scope = "code"
git_repo = "https://github.com/KnpLabs/KnpIpsum.git"
}]

features = [{
Expand All @@ -52,4 +77,14 @@ resource "ghost_app" "test" {
version = "2.2"
name = "apache2"
}]

lifecycle_hooks = {
pre_buildimage = "#!/usr/bin/env bash"
post_buildimage = "#!/usr/bin/env bash"
}

environment_variables = [{
key = "myvar"
value = "myvalue"
}]
}
27 changes: 27 additions & 0 deletions ghost/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ghost

import (
"encoding/base64"
"fmt"
"regexp"
)

func StrToB64(data string) string {
return base64.StdEncoding.EncodeToString([]byte(data))
}

func B64ToStr(data string) string {
str, _ := base64.StdEncoding.DecodeString(data)

return string(str)
}

func MatchesRegexp(exp string) func(v interface{}, k string) (ws []string, errors []error) {
return func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(exp).MatchString(value) {
errors = append(errors, fmt.Errorf("%q must match %s", k, exp))
}
return
}
}
62 changes: 62 additions & 0 deletions ghost/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ghost

import (
"reflect"
"testing"
)

func TestStrToB64(t *testing.T) {
cases := []struct {
Input string
ExpectedOutput string
}{
{"mystring", "bXlzdHJpbmc="},
{"", ""},
}

for _, tc := range cases {
output := StrToB64(tc.Input)
if !reflect.DeepEqual(output, tc.ExpectedOutput) {
t.Fatalf("Unexpected output from StrToB64.\nExpected: %#v\nGiven: %#v",
tc.ExpectedOutput, output)
}
}
}

func TestB64ToStr(t *testing.T) {
cases := []struct {
Input string
ExpectedOutput string
}{
{"bXlzdHJpbmc=", "mystring"},
{"", ""},
{"-1", ""},
{"()", ""},
}

for _, tc := range cases {
output := B64ToStr(tc.Input)
if !reflect.DeepEqual(output, tc.ExpectedOutput) {
t.Fatalf("Unexpected output from B64ToStr.\nExpected: %#v\nGiven: %#v",
tc.ExpectedOutput, output)
}
}
}

func TestMatchesRegexp(t *testing.T) {
cases := []struct {
Function func(v interface{}, k string) (ws []string, errors []error)
Value string
Valid bool
}{
{MatchesRegexp(`^[a-zA-Z0-9]*$`), "thisIsAPositiveTest", true},
{MatchesRegexp(`^[a-zA-Z0-9]*$`), "thisIsANegativeTest-", false},
}

for _, tc := range cases {
_, err := tc.Function(tc.Value, tc.Value)
if (tc.Valid && (err != nil)) || (!tc.Valid && (err == nil)) {
t.Fatalf("Unexpected output from MatchesRegexp: %v", err)
}
}
}
Loading

0 comments on commit c8dee63

Please sign in to comment.