diff --git a/pkg/resources/addon/provider_test_block.tf b/pkg/resources/addon/provider_test_block.tf deleted file mode 100644 index ad9d8c2..0000000 --- a/pkg/resources/addon/provider_test_block.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "clevercloud" { - organisation = "%s" -} diff --git a/pkg/resources/addon/resource_addon_test.go b/pkg/resources/addon/resource_addon_test.go index 06b20bc..56f33ca 100644 --- a/pkg/resources/addon/resource_addon_test.go +++ b/pkg/resources/addon/resource_addon_test.go @@ -13,17 +13,12 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "go.clever-cloud.com/terraform-provider/pkg/helper" "go.clever-cloud.com/terraform-provider/pkg/provider/impl" "go.clever-cloud.com/terraform-provider/pkg/tmp" "go.clever-cloud.dev/client" ) -//go:embed resource_addon_test_block.tf -var addonBlock string - -//go:embed provider_test_block.tf -var providerBlock string - var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){ "clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()), } @@ -33,6 +28,16 @@ func TestAccAddon_basic(t *testing.T) { fullName := fmt.Sprintf("clevercloud_addon.%s", rName) cc := client.New(client.WithAutoOauthConfig()) org := os.Getenv("ORGANISATION") + providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String() + addonBlock := helper.NewRessource( + "clevercloud_addon", + rName, + helper.SetKeyValues(map[string]any{ + "name": rName, + "region": "par", + "plan": "clever_solo", + "third_party_provider": "mailpace", + })).String() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -57,7 +62,7 @@ func TestAccAddon_basic(t *testing.T) { }, Steps: []resource.TestStep{{ ResourceName: rName, - Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(addonBlock, rName, rName), + Config: providerBlock + addonBlock, Check: resource.ComposeAggregateTestCheckFunc( resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^addon_.*`)), //resource.TestMatchResourceAttr(fullName, "password", regexp.MustCompile(`^[a-zA-Z0-9]+$`)), diff --git a/pkg/resources/addon/resource_addon_test_block.tf b/pkg/resources/addon/resource_addon_test_block.tf deleted file mode 100644 index b116082..0000000 --- a/pkg/resources/addon/resource_addon_test_block.tf +++ /dev/null @@ -1,7 +0,0 @@ - -resource "clevercloud_addon" "%s" { - name = "%s" - third_party_provider = "mailpace" - plan = "clever_solo" - region = "par" -} diff --git a/pkg/resources/cellar/bucket/provider_test_block.tf b/pkg/resources/cellar/bucket/provider_test_block.tf deleted file mode 100644 index ad9d8c2..0000000 --- a/pkg/resources/cellar/bucket/provider_test_block.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "clevercloud" { - organisation = "%s" -} diff --git a/pkg/resources/cellar/bucket/resource_cellar_bucket_test.go b/pkg/resources/cellar/bucket/resource_cellar_bucket_test.go index 335c56e..8fc0c1a 100644 --- a/pkg/resources/cellar/bucket/resource_cellar_bucket_test.go +++ b/pkg/resources/cellar/bucket/resource_cellar_bucket_test.go @@ -13,27 +13,23 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "go.clever-cloud.com/terraform-provider/pkg/helper" "go.clever-cloud.com/terraform-provider/pkg/provider/impl" "go.clever-cloud.com/terraform-provider/pkg/s3" "go.clever-cloud.com/terraform-provider/pkg/tmp" "go.clever-cloud.dev/client" ) -//go:embed resource_cellar_bucket_test_block.tf -var cellarBucketBlock string - -//go:embed provider_test_block.tf -var TestProviderBlock string - var TestProtoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){ "clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()), } func TestAccCellarBucket_basic(t *testing.T) { ctx := context.Background() - bName := fmt.Sprintf("my-bucket-%d", time.Now().UnixMilli()) + rName := fmt.Sprintf("my-bucket-%d", time.Now().UnixMilli()) cc := client.New(client.WithAutoOauthConfig()) org := os.Getenv("ORGANISATION") + providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String() cellar := &tmp.AddonResponse{} if os.Getenv("TF_ACC") == "1" { @@ -48,6 +44,7 @@ func TestAccCellarBucket_basic(t *testing.T) { } cellar = res.Payload() + fmt.Print(cellar) defer func() { rmRes := tmp.DeleteAddon(ctx, cc, org, cellar.ID) @@ -57,6 +54,14 @@ func TestAccCellarBucket_basic(t *testing.T) { }() } + cellarBucketBlock := helper.NewRessource( + "clevercloud_cellar_bucket", + rName, + helper.SetKeyValues(map[string]any{ + "id": rName, + "cellar_id": cellar.RealID, + })).String() + resource.Test(t, resource.TestCase{ PreCheck: func() { if org == "" { @@ -68,8 +73,8 @@ func TestAccCellarBucket_basic(t *testing.T) { }, ProtoV6ProviderFactories: TestProtoV6Provider, Steps: []resource.TestStep{{ - ResourceName: "cellar_bucket_" + bName, - Config: fmt.Sprintf(TestProviderBlock, org) + fmt.Sprintf(cellarBucketBlock, bName, bName, cellar.RealID), + ResourceName: "cellar_bucket_" + rName, + Config: providerBlock + cellarBucketBlock, Check: resource.ComposeAggregateTestCheckFunc( func(*terraform.State) error { return nil @@ -92,7 +97,7 @@ func TestAccCellarBucket_basic(t *testing.T) { return fmt.Errorf("unexpectd error: %s", res.Error().Error()) } - exists, err := minioClient.BucketExists(ctx, bName) + exists, err := minioClient.BucketExists(ctx, rName) if err != nil { return fmt.Errorf("unexpectd error: %s", res.Error().Error()) } diff --git a/pkg/resources/cellar/bucket/resource_cellar_bucket_test_block.tf b/pkg/resources/cellar/bucket/resource_cellar_bucket_test_block.tf deleted file mode 100644 index ccd1310..0000000 --- a/pkg/resources/cellar/bucket/resource_cellar_bucket_test_block.tf +++ /dev/null @@ -1,4 +0,0 @@ -resource "clevercloud_cellar_bucket" "%s" { - id = "%s" - cellar_id = "%s" -} diff --git a/pkg/resources/cellar/provider_test_block.tf b/pkg/resources/cellar/provider_test_block.tf deleted file mode 100644 index ad9d8c2..0000000 --- a/pkg/resources/cellar/provider_test_block.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "clevercloud" { - organisation = "%s" -} diff --git a/pkg/resources/cellar/resource_cellar_test.go b/pkg/resources/cellar/resource_cellar_test.go index 2b31b16..09f4733 100644 --- a/pkg/resources/cellar/resource_cellar_test.go +++ b/pkg/resources/cellar/resource_cellar_test.go @@ -13,27 +13,30 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "go.clever-cloud.com/terraform-provider/pkg/helper" "go.clever-cloud.com/terraform-provider/pkg/provider/impl" "go.clever-cloud.com/terraform-provider/pkg/tmp" "go.clever-cloud.dev/client" ) -//go:embed resource_cellar_test_block.tf -var cellarBlock string - -//go:embed provider_test_block.tf -var providerBlock string - var TestProtoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){ "clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()), } func TestAccCellar_basic(t *testing.T) { ctx := context.Background() - cName := fmt.Sprintf("tf-test-cellar-%d", time.Now().UnixMilli()) - fullName := fmt.Sprintf("clevercloud_cellar.%s", cName) + rName := fmt.Sprintf("tf-test-cellar-%d", time.Now().UnixMilli()) + fullName := fmt.Sprintf("clevercloud_cellar.%s", rName) cc := client.New(client.WithAutoOauthConfig()) org := os.Getenv("ORGANISATION") + providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String() + cellarBlock := helper.NewRessource( + "clevercloud_cellar", + rName, + helper.SetKeyValues(map[string]any{ + "name": rName, + "region": "par", + })).String() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -43,8 +46,8 @@ func TestAccCellar_basic(t *testing.T) { }, ProtoV6ProviderFactories: TestProtoV6Provider, Steps: []resource.TestStep{{ - ResourceName: "cellar_" + cName, - Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(cellarBlock, cName, cName), + ResourceName: "cellar_" + rName, + Config: providerBlock + cellarBlock, Check: resource.ComposeAggregateTestCheckFunc( resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^cellar_.*`)), resource.TestMatchResourceAttr(fullName, "host", regexp.MustCompile(`^.*\.services.clever-cloud.com$`)), diff --git a/pkg/resources/cellar/resource_cellar_test_block.tf b/pkg/resources/cellar/resource_cellar_test_block.tf deleted file mode 100644 index 034819b..0000000 --- a/pkg/resources/cellar/resource_cellar_test_block.tf +++ /dev/null @@ -1,5 +0,0 @@ - -resource "clevercloud_cellar" "%s" { - name = "%s" - region = "par" -} diff --git a/pkg/resources/java/provider_test_block.tf b/pkg/resources/java/provider_test_block.tf deleted file mode 100644 index ad9d8c2..0000000 --- a/pkg/resources/java/provider_test_block.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "clevercloud" { - organisation = "%s" -} diff --git a/pkg/resources/java/resource_java_test.go b/pkg/resources/java/resource_java_test.go index b6cecda..c965726 100644 --- a/pkg/resources/java/resource_java_test.go +++ b/pkg/resources/java/resource_java_test.go @@ -13,17 +13,12 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "go.clever-cloud.com/terraform-provider/pkg/helper" "go.clever-cloud.com/terraform-provider/pkg/provider/impl" "go.clever-cloud.com/terraform-provider/pkg/tmp" "go.clever-cloud.dev/client" ) -//go:embed provider_test_block.tf -var providerBlock string - -//go:embed resource_java_test_block.tf -var javaBlock string - var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){ "clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()), } @@ -34,6 +29,18 @@ func TestAccJava_basic(t *testing.T) { fullName := fmt.Sprintf("clevercloud_java_war.%s", rName) cc := client.New(client.WithAutoOauthConfig()) org := os.Getenv("ORGANISATION") + providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String() + javaBlock := helper.NewRessource( + "clevercloud_java_war", + rName, + helper.SetKeyValues(map[string]any{ + "name": rName, + "region": "par", + "min_instance_count": 1, + "max_instance_count": 2, + "smallest_flavor": "XS", + "biggest_flavor": "M", + })).String() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -45,7 +52,7 @@ func TestAccJava_basic(t *testing.T) { Steps: []resource.TestStep{{ Destroy: false, ResourceName: rName, - Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(javaBlock, rName, rName), + Config: providerBlock + javaBlock, Check: resource.ComposeAggregateTestCheckFunc( resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^app_.*$`)), resource.TestMatchResourceAttr(fullName, "deploy_url", regexp.MustCompile(`^git\+ssh.*\.git$`)), diff --git a/pkg/resources/java/resource_java_test_block.tf b/pkg/resources/java/resource_java_test_block.tf deleted file mode 100644 index 8a15623..0000000 --- a/pkg/resources/java/resource_java_test_block.tf +++ /dev/null @@ -1,8 +0,0 @@ -resource "clevercloud_java_war" "%s" { - name = "%s" - region = "par" - min_instance_count = 1 - max_instance_count = 2 - smallest_flavor = "XS" - biggest_flavor = "M" -} diff --git a/pkg/resources/materiakv/provider_test_block.tf b/pkg/resources/materiakv/provider_test_block.tf deleted file mode 100644 index ad9d8c2..0000000 --- a/pkg/resources/materiakv/provider_test_block.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "clevercloud" { - organisation = "%s" -} diff --git a/pkg/resources/materiakv/resource_materiakv_test.go b/pkg/resources/materiakv/resource_materiakv_test.go index 57dfbe1..9a47ffc 100644 --- a/pkg/resources/materiakv/resource_materiakv_test.go +++ b/pkg/resources/materiakv/resource_materiakv_test.go @@ -13,17 +13,12 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "go.clever-cloud.com/terraform-provider/pkg/helper" "go.clever-cloud.com/terraform-provider/pkg/provider/impl" "go.clever-cloud.com/terraform-provider/pkg/tmp" "go.clever-cloud.dev/client" ) -//go:embed resource_materiakv_test_block.tf -var materiakvBlock string - -//go:embed provider_test_block.tf -var providerBlock string - var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){ "clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()), } @@ -34,6 +29,8 @@ func TestAccMateriaKV_basic(t *testing.T) { fullName := fmt.Sprintf("clevercloud_materiadb_kv.%s", rName) cc := client.New(client.WithAutoOauthConfig()) org := os.Getenv("ORGANISATION") + providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String() + materiakvBlock := helper.NewRessource("clevercloud_materiadb_kv", rName, helper.SetKeyValues(map[string]any{"name": rName})).String() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -61,7 +58,7 @@ func TestAccMateriaKV_basic(t *testing.T) { }, Steps: []resource.TestStep{{ ResourceName: rName, - Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(materiakvBlock, rName, rName), + Config: providerBlock + materiakvBlock, Check: resource.ComposeAggregateTestCheckFunc( resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^kv_.*`)), resource.TestMatchResourceAttr(fullName, "host", regexp.MustCompile(`^.*clever-cloud.com$`)), diff --git a/pkg/resources/materiakv/resource_materiakv_test_block.tf b/pkg/resources/materiakv/resource_materiakv_test_block.tf deleted file mode 100644 index 265e5bc..0000000 --- a/pkg/resources/materiakv/resource_materiakv_test_block.tf +++ /dev/null @@ -1,3 +0,0 @@ -resource "clevercloud_materiadb_kv" "%s" { - name = "%s" -} diff --git a/pkg/resources/nodejs/provider_test_block.tf b/pkg/resources/nodejs/provider_test_block.tf deleted file mode 100644 index ad9d8c2..0000000 --- a/pkg/resources/nodejs/provider_test_block.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "clevercloud" { - organisation = "%s" -} diff --git a/pkg/resources/nodejs/resource_nodejs_test.go b/pkg/resources/nodejs/resource_nodejs_test.go index 66ba631..04a6ffc 100644 --- a/pkg/resources/nodejs/resource_nodejs_test.go +++ b/pkg/resources/nodejs/resource_nodejs_test.go @@ -15,20 +15,12 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "go.clever-cloud.com/terraform-provider/pkg" + "go.clever-cloud.com/terraform-provider/pkg/helper" "go.clever-cloud.com/terraform-provider/pkg/provider/impl" "go.clever-cloud.com/terraform-provider/pkg/tmp" "go.clever-cloud.dev/client" ) -//go:embed resource_nodejs_test_block.tf -var nodejsBlock string - -//go:embed resource_nodejs_test_block2.tf -var nodejsBlock2 string - -//go:embed provider_test_block.tf -var providerBlock string - var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){ "clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()), } @@ -41,6 +33,37 @@ func TestAccNodejs_basic(t *testing.T) { fullName2 := fmt.Sprintf("clevercloud_nodejs.%s", rName2) cc := client.New(client.WithAutoOauthConfig()) org := os.Getenv("ORGANISATION") + providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String() + nodejsBlock := helper.NewRessource( + "clevercloud_nodejs", + rName, + helper.SetKeyValues(map[string]any{ + "name": rName, + "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": map[string]any{"MY_KEY": "myval"}, + "dependencies": []string{}, + }), + helper.SetBlockValues("hooks", map[string]any{"post_build": "echo \"build is OK!\""}), + ).String() + nodejsBlock2 := helper.NewRessource( + "clevercloud_nodejs", + rName2, + helper.SetKeyValues(map[string]any{ + "name": rName2, + "region": "par", + "min_instance_count": 1, + "max_instance_count": 2, + "smallest_flavor": "XS", + "biggest_flavor": "M", + }), + helper.SetBlockValues("deployment", map[string]any{"repository": "https://github.com/CleverCloud/nodejs-example.git"})).String() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -68,7 +91,7 @@ func TestAccNodejs_basic(t *testing.T) { }, Steps: []resource.TestStep{{ ResourceName: rName, - Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(nodejsBlock, rName, rName), + Config: providerBlock + nodejsBlock, Check: resource.ComposeAggregateTestCheckFunc( // Test the state for provider's populated values resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^app_.*$`)), @@ -143,7 +166,7 @@ func TestAccNodejs_basic(t *testing.T) { ), }, { ResourceName: rName2, - Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(nodejsBlock2, rName2, rName2), + Config: providerBlock + nodejsBlock2, Check: func(state *terraform.State) error { id := state.RootModule().Resources[fullName2].Primary.ID diff --git a/pkg/resources/nodejs/resource_nodejs_test_block.tf b/pkg/resources/nodejs/resource_nodejs_test_block.tf deleted file mode 100644 index 25bc2a2..0000000 --- a/pkg/resources/nodejs/resource_nodejs_test_block.tf +++ /dev/null @@ -1,18 +0,0 @@ -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 = [] -} diff --git a/pkg/resources/nodejs/resource_nodejs_test_block2.tf b/pkg/resources/nodejs/resource_nodejs_test_block2.tf deleted file mode 100644 index 50eacba..0000000 --- a/pkg/resources/nodejs/resource_nodejs_test_block2.tf +++ /dev/null @@ -1,11 +0,0 @@ -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" - } -} diff --git a/pkg/resources/php/provider_test_block.tf b/pkg/resources/php/provider_test_block.tf deleted file mode 100644 index ad9d8c2..0000000 --- a/pkg/resources/php/provider_test_block.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "clevercloud" { - organisation = "%s" -} diff --git a/pkg/resources/php/resource_php_test.go b/pkg/resources/php/resource_php_test.go index 3216273..cb19d4b 100644 --- a/pkg/resources/php/resource_php_test.go +++ b/pkg/resources/php/resource_php_test.go @@ -13,17 +13,12 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "go.clever-cloud.com/terraform-provider/pkg/helper" "go.clever-cloud.com/terraform-provider/pkg/provider/impl" "go.clever-cloud.com/terraform-provider/pkg/tmp" "go.clever-cloud.dev/client" ) -//go:embed provider_test_block.tf -var providerBlock string - -//go:embed resource_php_test_block.tf -var phpBlock string - var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){ "clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()), } @@ -34,6 +29,20 @@ func TestAccPHP_basic(t *testing.T) { fullName := fmt.Sprintf("clevercloud_php.%s", rName) cc := client.New(client.WithAutoOauthConfig()) org := os.Getenv("ORGANISATION") + providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String() + phpBlock := helper.NewRessource( + "clevercloud_php", + rName, + helper.SetKeyValues(map[string]any{ + "name": rName, + "region": "par", + "min_instance_count": 1, + "max_instance_count": 2, + "smallest_flavor": "XS", + "biggest_flavor": "M", + "php_version": "8", + "additional_vhosts": [1]string{"toto-tf5283457829345.com"}, + })).String() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -45,7 +54,7 @@ func TestAccPHP_basic(t *testing.T) { Steps: []resource.TestStep{{ Destroy: false, ResourceName: rName, - Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(phpBlock, rName, rName), + Config: providerBlock + phpBlock, Check: resource.ComposeAggregateTestCheckFunc( resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^app_.*$`)), resource.TestMatchResourceAttr(fullName, "deploy_url", regexp.MustCompile(`^git\+ssh.*\.git$`)), diff --git a/pkg/resources/php/resource_php_test_block.tf b/pkg/resources/php/resource_php_test_block.tf deleted file mode 100644 index 9ae6e1e..0000000 --- a/pkg/resources/php/resource_php_test_block.tf +++ /dev/null @@ -1,10 +0,0 @@ -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" ] -} diff --git a/pkg/resources/postgresql/provider_test_block.tf b/pkg/resources/postgresql/provider_test_block.tf deleted file mode 100644 index ad9d8c2..0000000 --- a/pkg/resources/postgresql/provider_test_block.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "clevercloud" { - organisation = "%s" -} diff --git a/pkg/resources/postgresql/resource_postgresql_test.go b/pkg/resources/postgresql/resource_postgresql_test.go index f0a1127..df081c9 100644 --- a/pkg/resources/postgresql/resource_postgresql_test.go +++ b/pkg/resources/postgresql/resource_postgresql_test.go @@ -13,17 +13,12 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "go.clever-cloud.com/terraform-provider/pkg/helper" "go.clever-cloud.com/terraform-provider/pkg/provider/impl" "go.clever-cloud.com/terraform-provider/pkg/tmp" "go.clever-cloud.dev/client" ) -//go:embed resource_postgresql_test_block.tf -var postgresqlBlock string - -//go:embed provider_test_block.tf -var providerBlock string - var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){ "clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()), } @@ -33,6 +28,15 @@ func TestAccPostgreSQL_basic(t *testing.T) { fullName := fmt.Sprintf("clevercloud_postgresql.%s", rName) cc := client.New(client.WithAutoOauthConfig()) org := os.Getenv("ORGANISATION") + providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String() + postgresqlBlock := helper.NewRessource( + "clevercloud_postgresql", + rName, + helper.SetKeyValues(map[string]any{ + "name": rName, + "region": "par", + "plan": "dev", + })).String() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -60,7 +64,7 @@ func TestAccPostgreSQL_basic(t *testing.T) { }, Steps: []resource.TestStep{{ ResourceName: rName, - Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(postgresqlBlock, rName, rName), + Config: providerBlock + postgresqlBlock, Check: resource.ComposeAggregateTestCheckFunc( resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^addon_.*`)), resource.TestMatchResourceAttr(fullName, "host", regexp.MustCompile(`^.*-postgresql\.services\.clever-cloud\.com$`)), @@ -78,6 +82,15 @@ func TestAccPostgreSQL_RefreshDeleted(t *testing.T) { //fullName := fmt.Sprintf("clevercloud_postgresql.%s", rName) cc := client.New(client.WithAutoOauthConfig()) org := os.Getenv("ORGANISATION") + providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String() + postgresqlBlock := helper.NewRessource( + "clevercloud_postgresql", + rName, + helper.SetKeyValues(map[string]any{ + "name": rName, + "region": "par", + "plan": "dev", + })).String() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -107,7 +120,7 @@ func TestAccPostgreSQL_RefreshDeleted(t *testing.T) { // create a database instance on first step { ResourceName: rName, - Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(postgresqlBlock, rName, rName), + Config: providerBlock + postgresqlBlock, }, { ResourceName: rName, diff --git a/pkg/resources/postgresql/resource_postgresql_test_block.tf b/pkg/resources/postgresql/resource_postgresql_test_block.tf deleted file mode 100644 index c122f71..0000000 --- a/pkg/resources/postgresql/resource_postgresql_test_block.tf +++ /dev/null @@ -1,5 +0,0 @@ -resource "clevercloud_postgresql" "%s" { - name = "%s" - plan = "dev" - region = "par" -} diff --git a/pkg/resources/scala/provider_test_block.tf b/pkg/resources/scala/provider_test_block.tf deleted file mode 100644 index ad9d8c2..0000000 --- a/pkg/resources/scala/provider_test_block.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "clevercloud" { - organisation = "%s" -} diff --git a/pkg/resources/scala/resource_scala_test.go b/pkg/resources/scala/resource_scala_test.go index 7c862fb..4d4bb44 100644 --- a/pkg/resources/scala/resource_scala_test.go +++ b/pkg/resources/scala/resource_scala_test.go @@ -13,17 +13,12 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "go.clever-cloud.com/terraform-provider/pkg/helper" "go.clever-cloud.com/terraform-provider/pkg/provider/impl" "go.clever-cloud.com/terraform-provider/pkg/tmp" "go.clever-cloud.dev/client" ) -//go:embed provider_test_block.tf -var providerBlock string - -//go:embed resource_scala_test_block.tf -var scalaBlock string - var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){ "clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()), } @@ -34,6 +29,18 @@ func TestAccScala_basic(t *testing.T) { fullName := fmt.Sprintf("clevercloud_scala.%s", rName) cc := client.New(client.WithAutoOauthConfig()) org := os.Getenv("ORGANISATION") + providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String() + scalaBlock := helper.NewRessource( + "clevercloud_scala", + rName, + helper.SetKeyValues(map[string]any{ + "name": rName, + "region": "par", + "min_instance_count": 1, + "max_instance_count": 2, + "smallest_flavor": "XS", + "biggest_flavor": "M", + })).String() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -45,7 +52,7 @@ func TestAccScala_basic(t *testing.T) { Steps: []resource.TestStep{{ Destroy: false, ResourceName: rName, - Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(scalaBlock, rName, rName), + Config: providerBlock + scalaBlock, Check: resource.ComposeAggregateTestCheckFunc( resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^app_.*$`)), resource.TestMatchResourceAttr(fullName, "deploy_url", regexp.MustCompile(`^git\+ssh.*\.git$`)), diff --git a/pkg/resources/scala/resource_scala_test_block.tf b/pkg/resources/scala/resource_scala_test_block.tf deleted file mode 100644 index 6881259..0000000 --- a/pkg/resources/scala/resource_scala_test_block.tf +++ /dev/null @@ -1,8 +0,0 @@ -resource "clevercloud_scala" "%s" { - name = "%s" - region = "par" - min_instance_count = 1 - max_instance_count = 2 - smallest_flavor = "XS" - biggest_flavor = "M" -} diff --git a/pkg/resources/static/provider_test_block.tf b/pkg/resources/static/provider_test_block.tf deleted file mode 100644 index ad9d8c2..0000000 --- a/pkg/resources/static/provider_test_block.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "clevercloud" { - organisation = "%s" -} diff --git a/pkg/resources/static/resource_static_test.go b/pkg/resources/static/resource_static_test.go index af9425b..10e4d81 100644 --- a/pkg/resources/static/resource_static_test.go +++ b/pkg/resources/static/resource_static_test.go @@ -13,17 +13,12 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "go.clever-cloud.com/terraform-provider/pkg/helper" "go.clever-cloud.com/terraform-provider/pkg/provider/impl" "go.clever-cloud.com/terraform-provider/pkg/tmp" "go.clever-cloud.dev/client" ) -//go:embed provider_test_block.tf -var providerBlock string - -//go:embed resource_static_test_block.tf -var staticBlock string - var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){ "clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()), } @@ -34,6 +29,18 @@ func TestAccStatic_basic(t *testing.T) { fullName := fmt.Sprintf("clevercloud_static.%s", rName) cc := client.New(client.WithAutoOauthConfig()) org := os.Getenv("ORGANISATION") + providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String() + staticBlock := helper.NewRessource( + "clevercloud_static", + rName, + helper.SetKeyValues(map[string]any{ + "name": rName, + "region": "par", + "min_instance_count": 1, + "max_instance_count": 2, + "smallest_flavor": "XS", + "biggest_flavor": "M", + })).String() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -45,7 +52,7 @@ func TestAccStatic_basic(t *testing.T) { Steps: []resource.TestStep{{ Destroy: false, ResourceName: rName, - Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(staticBlock, rName, rName), + Config: providerBlock + staticBlock, Check: resource.ComposeAggregateTestCheckFunc( resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^app_.*$`)), resource.TestMatchResourceAttr(fullName, "deploy_url", regexp.MustCompile(`^git\+ssh.*\.git$`)), diff --git a/pkg/resources/static/resource_static_test_block.tf b/pkg/resources/static/resource_static_test_block.tf deleted file mode 100644 index d33e7a8..0000000 --- a/pkg/resources/static/resource_static_test_block.tf +++ /dev/null @@ -1,8 +0,0 @@ -resource "clevercloud_static" "%s" { - name = "%s" - region = "par" - min_instance_count = 1 - max_instance_count = 2 - smallest_flavor = "XS" - biggest_flavor = "M" -}