diff --git a/pkg/helper/ressource_block.go b/pkg/helper/ressource_block.go index 5826e9d..fa37eb4 100644 --- a/pkg/helper/ressource_block.go +++ b/pkg/helper/ressource_block.go @@ -1,123 +1,9 @@ package helper -import "strconv" - -// Ressource structure - -// addon -// resource "clevercloud_addon" "%s" { -// name = "%s" -// third_party_provider = "mailpace" -// plan = "clever_solo" -// region = "par" -// } - -// cellar -// resource "clevercloud_cellar" "%s" { -// name = "%s" -// region = "par" -// } - -// cellar bucket -// resource "clevercloud_cellar_bucket" "%s" { -// id = "%s" -// cellar_id = "%s" -// } - -// postgresql -// resource "clevercloud_postgresql" "%s" { -// name = "%s" -// plan = "dev" -// region = "par" -// } - -// nodejs -// resource "clevercloud_nodejs" "%s" { -// name = "%s" -// region = "par" -// min_instance_count = 1 -// max_instance_count = 2 -// smallest_flavor = "XS" -// biggest_flavor = "M" -// redirect_https = true -// sticky_sessions = true -// app_folder = "./app" -// environment = { -// MY_KEY = "myval" -// } -// hooks { -// post_build = "echo \"build is OK!\"" -// } -// dependencies = [] -// } - -// resource "clevercloud_nodejs" "%s" { -// name = "%s" -// region = "par" -// min_instance_count = 1 -// max_instance_count = 2 -// smallest_flavor = "XS" -// biggest_flavor = "M" -// deployment { -// repository = "https://github.com/CleverCloud/nodejs-example.git" -// } -// } - -// php -// resource "clevercloud_php" "%s" { -// name = "%s" -// region = "par" -// min_instance_count = 1 -// max_instance_count = 2 -// smallest_flavor = "XS" -// biggest_flavor = "M" -// php_version = "8" -// additional_vhosts = [ "toto-tf5283457829345.com" ] -// } - -// python -// resource "clevercloud_python" "%s" { -// name = "%s" -// region = "par" -// min_instance_count = 1 -// max_instance_count = 2 -// smallest_flavor = "XS" -// biggest_flavor = "M" -// redirect_https = true -// sticky_sessions = true -// app_folder = "./app" -// python_version = "2.7" -// pip_requirements = "requirements.txt" -// environment = { -// MY_KEY = "myval" -// } -// hooks { -// post_build = "echo \"build is OK!\"" -// } -// dependencies = [] -// } - -// resource "clevercloud_python" "%s" { -// name = "%s" -// region = "par" -// min_instance_count = 1 -// max_instance_count = 2 -// smallest_flavor = "XS" -// biggest_flavor = "M" -// deployment { -// repository = "https://github.com/CleverCloud/flask-example.git" -// } -// } - -// scala -// resource "clevercloud_scala" "%s" { -// name = "%s" -// region = "par" -// min_instance_count = 1 -// max_instance_count = 2 -// smallest_flavor = "XS" -// biggest_flavor = "M" -// } +import ( + "sort" + "strconv" +) type Ressource struct { Ressource string @@ -203,18 +89,34 @@ func (p *Ressource) String() string { ` // check StringValues not empty if len(p.StringValues) != 0 { + // sort StringValues keys + tmp := make([]string, 0, len(p.StringValues)) + for k := range p.StringValues { + tmp = append(tmp, k) + } + sort.Strings(tmp) + + // create StringValues block sstring := `` - for key, value := range p.StringValues { - sstring += ` ` + key + ` = "` + value + `" + for _, k := range tmp { + sstring += ` ` + k + ` = "` + p.StringValues[k] + `" ` } s += sstring } // check IntValues not empty if len(p.IntValues) != 0 { + // sort IntValues keys + tmp := make([]string, 0, len(p.IntValues)) + for k := range p.IntValues { + tmp = append(tmp, k) + } + sort.Strings(tmp) + + // create IntValues block sint := `` - for key, value := range p.IntValues { - sint += ` ` + key + ` = ` + strconv.Itoa(value) + ` + for _, k := range tmp { + sint += ` ` + k + ` = ` + strconv.Itoa(p.IntValues[k]) + ` ` } s += sint diff --git a/pkg/helper/ressource_block_test.go b/pkg/helper/ressource_block_test.go index 0c09360..43f5b98 100644 --- a/pkg/helper/ressource_block_test.go +++ b/pkg/helper/ressource_block_test.go @@ -12,19 +12,19 @@ func TestRessource_String(t *testing.T) { {name: "test1", fields: NewRessource("clevercloud").SetName("test1"), want: `ressource "clevercloud" "test1" { name = "test1" + biggest_flavor = "M" region = "par" smallest_flavor = "XS" - biggest_flavor = "M" - min_instance_count = 1 max_instance_count = 2 + min_instance_count = 1 }`}, {name: "test2", fields: NewRessource("clevercloud_python").SetName("test2").SetIntValues("min_instance_count", 3), want: `ressource "clevercloud_python" "test2" { name = "test2" + biggest_flavor = "M" region = "par" smallest_flavor = "XS" - biggest_flavor = "M" - min_instance_count = 3 max_instance_count = 2 + min_instance_count = 3 }`}, } for _, tt := range tests {