diff --git a/docs/data-sources/armada_region.md b/docs/data-sources/core_region.md similarity index 97% rename from docs/data-sources/armada_region.md rename to docs/data-sources/core_region.md index 7b198a7..2fc79a0 100644 --- a/docs/data-sources/armada_region.md +++ b/docs/data-sources/core_region.md @@ -1,12 +1,12 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "ec_armada_region Data Source - terraform-provider-ec" +page_title: "ec_core_region Data Source - terraform-provider-ec" subcategory: "" description: |- Use this data source to access information about an existing Region. --- -# ec_armada_region (Data Source) +# ec_core_region (Data Source) Use this data source to access information about an existing Region. diff --git a/docs/data-sources/armada_region_v1.md b/docs/data-sources/core_region_v1.md similarity index 97% rename from docs/data-sources/armada_region_v1.md rename to docs/data-sources/core_region_v1.md index e3b9c41..73ec2d5 100644 --- a/docs/data-sources/armada_region_v1.md +++ b/docs/data-sources/core_region_v1.md @@ -1,12 +1,12 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "ec_armada_region_v1 Data Source - terraform-provider-ec" +page_title: "ec_core_region_v1 Data Source - terraform-provider-ec" subcategory: "" description: |- Use this data source to access information about an existing Region. --- -# ec_armada_region_v1 (Data Source) +# ec_core_region_v1 (Data Source) Use this data source to access information about an existing Region. diff --git a/docs/data-sources/armada_site.md b/docs/data-sources/core_site.md similarity index 99% rename from docs/data-sources/armada_site.md rename to docs/data-sources/core_site.md index 1cd5cd6..e66b5a7 100644 --- a/docs/data-sources/armada_site.md +++ b/docs/data-sources/core_site.md @@ -1,12 +1,12 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "ec_armada_site Data Source - terraform-provider-ec" +page_title: "ec_core_site Data Source - terraform-provider-ec" subcategory: "" description: |- Use this data source to access information about an existing Site. --- -# ec_armada_site (Data Source) +# ec_core_site (Data Source) Use this data source to access information about an existing Site. diff --git a/docs/data-sources/armada_site_v1.md b/docs/data-sources/core_site_v1.md similarity index 99% rename from docs/data-sources/armada_site_v1.md rename to docs/data-sources/core_site_v1.md index 4171e80..0f8236b 100644 --- a/docs/data-sources/armada_site_v1.md +++ b/docs/data-sources/core_site_v1.md @@ -1,12 +1,12 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "ec_armada_site_v1 Data Source - terraform-provider-ec" +page_title: "ec_core_site_v1 Data Source - terraform-provider-ec" subcategory: "" description: |- Use this data source to access information about an existing Site. --- -# ec_armada_site_v1 (Data Source) +# ec_core_site_v1 (Data Source) Use this data source to access information about an existing Site. diff --git a/docs/index.md b/docs/index.md index d4fa22d..37f175e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -26,7 +26,7 @@ provider "ec" { host = "" } -resource "ec_armada_site" "test" { +resource "ec_core_site" "test" { metadata { name = "test" } diff --git a/docs/resources/core_environment.md b/docs/resources/core_environment.md index c6dc9b0..c17e43e 100644 --- a/docs/resources/core_environment.md +++ b/docs/resources/core_environment.md @@ -3,12 +3,12 @@ page_title: "ec_core_environment Resource - terraform-provider-ec" subcategory: "" description: |- - An Environment provides a connection to deployment capacity. + An Environment provides a mechanism to isolate groups of resources. --- # ec_core_environment (Resource) -An Environment provides a connection to deployment capacity. +An Environment provides a mechanism to isolate groups of resources. diff --git a/docs/resources/core_environment_v1.md b/docs/resources/core_environment_v1.md index 1bed10b..4816fb6 100644 --- a/docs/resources/core_environment_v1.md +++ b/docs/resources/core_environment_v1.md @@ -3,12 +3,12 @@ page_title: "ec_core_environment_v1 Resource - terraform-provider-ec" subcategory: "" description: |- - An Environment provides a connection to deployment capacity. + An Environment provides a mechanism to isolate groups of resources. --- # ec_core_environment_v1 (Resource) -An Environment provides a connection to deployment capacity. +An Environment provides a mechanism to isolate groups of resources. diff --git a/docs/resources/armada_region.md b/docs/resources/core_region.md similarity index 97% rename from docs/resources/armada_region.md rename to docs/resources/core_region.md index 2c5ebbf..26dcfeb 100644 --- a/docs/resources/armada_region.md +++ b/docs/resources/core_region.md @@ -1,12 +1,12 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "ec_armada_region Resource - terraform-provider-ec" +page_title: "ec_core_region Resource - terraform-provider-ec" subcategory: "" description: |- A Region determines how Armadas are distributed across Sites. --- -# ec_armada_region (Resource) +# ec_core_region (Resource) A Region determines how Armadas are distributed across Sites. diff --git a/docs/resources/armada_region_v1.md b/docs/resources/core_region_v1.md similarity index 97% rename from docs/resources/armada_region_v1.md rename to docs/resources/core_region_v1.md index 31fd899..2ca7c3c 100644 --- a/docs/resources/armada_region_v1.md +++ b/docs/resources/core_region_v1.md @@ -1,12 +1,12 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "ec_armada_region_v1 Resource - terraform-provider-ec" +page_title: "ec_core_region_v1 Resource - terraform-provider-ec" subcategory: "" description: |- A Region determines how Armadas are distributed across Sites. --- -# ec_armada_region_v1 (Resource) +# ec_core_region_v1 (Resource) A Region determines how Armadas are distributed across Sites. diff --git a/docs/resources/armada_site.md b/docs/resources/core_site.md similarity index 99% rename from docs/resources/armada_site.md rename to docs/resources/core_site.md index 525b915..8b436d1 100644 --- a/docs/resources/armada_site.md +++ b/docs/resources/core_site.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "ec_armada_site Resource - terraform-provider-ec" +page_title: "ec_core_site Resource - terraform-provider-ec" subcategory: "" description: |- A Site provides a connection to deployment capacity. --- -# ec_armada_site (Resource) +# ec_core_site (Resource) A Site provides a connection to deployment capacity. ## Example Usage ```terraform -resource "ec_armada_site" "test" { +resource "ec_core_site" "test" { metadata { name = "test" } diff --git a/docs/resources/armada_site_v1.md b/docs/resources/core_site_v1.md similarity index 99% rename from docs/resources/armada_site_v1.md rename to docs/resources/core_site_v1.md index 87add9c..2d628b5 100644 --- a/docs/resources/armada_site_v1.md +++ b/docs/resources/core_site_v1.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "ec_armada_site_v1 Resource - terraform-provider-ec" +page_title: "ec_core_site_v1 Resource - terraform-provider-ec" subcategory: "" description: |- A Site provides a connection to deployment capacity. --- -# ec_armada_site_v1 (Resource) +# ec_core_site_v1 (Resource) A Site provides a connection to deployment capacity. ## Example Usage ```terraform -resource "ec_armada_site_v1" "test" { +resource "ec_core_site" "test" { metadata { name = "test" } diff --git a/ec/armada/data_source_armada_armada.go b/ec/armada/data_source_armada.go similarity index 53% rename from ec/armada/data_source_armada_armada.go rename to ec/armada/data_source_armada.go index f3dbd01..d0061d8 100644 --- a/ec/armada/data_source_armada_armada.go +++ b/ec/armada/data_source_armada.go @@ -7,18 +7,18 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -// DataSourceArmadaArmada returns the data source resource for an Armada. -func DataSourceArmadaArmada() *schema.Resource { +// DataSourceArmada returns the data source resource for an Armada. +func DataSourceArmada() *schema.Resource { return &schema.Resource{ Description: "Use this data source to access information about an existing Armada.", - ReadContext: dataSourceArmadaArmadaRead, + ReadContext: dataSourceArmadaRead, Schema: armadaSchema(), } } -func dataSourceArmadaArmadaRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func dataSourceArmadaRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { name := d.Get("metadata.0.name").(string) d.SetId(name) - return resourceArmadaArmadaRead(ctx, d, m) + return resourceArmadaRead(ctx, d, m) } diff --git a/ec/armada/data_source_armada_region_test.go b/ec/armada/data_source_armada_region_test.go deleted file mode 100644 index ec5e1f8..0000000 --- a/ec/armada/data_source_armada_region_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package armada_test - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" -) - -func TestArmadaDataSourceRegions(t *testing.T) { - name := "my-region" - pf, _ := providertest.SetupProviderFactories(t) - - resource.Test(t, resource.TestCase{ - IsUnitTest: true, - ProviderFactories: pf, - Steps: []resource.TestStep{ - { - Config: testArmadasDataSourceRegionsConfigBasic(name), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ec_armada_region.test", "metadata.0.name", name), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.#", "1"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.description", "My Region"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.#", "1"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.name", "my-type"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.sites.#", "2"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.sites.0", "test-site-1"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.sites.1", "test-site-2"), - ), - }, - { - Config: testArmadasDataSourceRegionsConfigBasic(name) + - testArmadaDataSourceRegionConfigRead(), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.ec_armada_region.test", "metadata.0.name", name), - resource.TestCheckResourceAttr("data.ec_armada_region.test", "spec.#", "1"), - resource.TestCheckResourceAttr("data.ec_armada_region.test", "spec.0.description", "My Region"), - resource.TestCheckResourceAttr("data.ec_armada_region.test", "spec.0.types.#", "1"), - resource.TestCheckResourceAttr("data.ec_armada_region.test", "spec.0.types.0.name", "my-type"), - resource.TestCheckResourceAttr("data.ec_armada_region.test", "spec.0.types.0.sites.#", "2"), - resource.TestCheckResourceAttr("data.ec_armada_region.test", "spec.0.types.0.sites.0", "test-site-1"), - resource.TestCheckResourceAttr("data.ec_armada_region.test", "spec.0.types.0.sites.1", "test-site-2"), - ), - }, - }, - }) -} - -func testArmadasDataSourceRegionsConfigBasic(name string) string { - return fmt.Sprintf(`resource "ec_armada_region" "test" { - metadata { - name = "%s" - } - spec { - description = "My Region" - types { - name = "my-type" - sites = ["test-site-1", "test-site-2"] - } - } -} -`, name) -} - -func testArmadaDataSourceRegionConfigRead() string { - return `data "ec_armada_region" "test" { - metadata { - name = "${ec_armada_region.test.metadata.0.name}" - } -} -` -} diff --git a/ec/armada/data_source_armada_site_test.go b/ec/armada/data_source_armada_site_test.go deleted file mode 100644 index 6850164..0000000 --- a/ec/armada/data_source_armada_site_test.go +++ /dev/null @@ -1,92 +0,0 @@ -package armada_test - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" -) - -func TestArmadaDataSourceSites(t *testing.T) { - name := "my-site" - pf, _ := providertest.SetupProviderFactories(t) - - resource.Test(t, resource.TestCase{ - IsUnitTest: true, - ProviderFactories: pf, - Steps: []resource.TestStep{ - { - Config: testArmadasDataSourceSitesConfigBasic(name), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ec_armada_site.test", "metadata.0.name", name), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.#", "1"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.description", "My Site"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.endpoint", "endpoint"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.certificate", "cert"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.namespace", "ns"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.token", "tok"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.resources.0.cpu", "250m"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.resources.0.memory", "1Gi"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.template.0.image_pull_secrets.0", "test-secret"), - ), - }, - { - Config: testArmadasDataSourceSitesConfigBasic(name) + - testArmadaDataSourceSiteConfigRead(), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.ec_armada_site.test", "metadata.0.name", name), - resource.TestCheckResourceAttr("data.ec_armada_site.test", "spec.#", "1"), - resource.TestCheckResourceAttr("data.ec_armada_site.test", "spec.0.description", "My Site"), - resource.TestCheckResourceAttr("data.ec_armada_site.test", "spec.0.credentials.0.endpoint", "endpoint"), - resource.TestCheckResourceAttr("data.ec_armada_site.test", "spec.0.credentials.0.certificate", "cert"), - resource.TestCheckResourceAttr("data.ec_armada_site.test", "spec.0.credentials.0.namespace", "ns"), - resource.TestCheckResourceAttr("data.ec_armada_site.test", "spec.0.credentials.0.token", "tok"), - resource.TestCheckResourceAttr("data.ec_armada_site.test", "spec.0.resources.0.cpu", "250m"), - resource.TestCheckResourceAttr("data.ec_armada_site.test", "spec.0.resources.0.memory", "1Gi"), - resource.TestCheckResourceAttr("data.ec_armada_site.test", "spec.0.template.0.image_pull_secrets.0", "test-secret"), - resource.TestCheckResourceAttr("data.ec_armada_site.test", "spec.0.template.0.env.0.name", "foo"), - resource.TestCheckResourceAttr("data.ec_armada_site.test", "spec.0.template.0.env.0.value", "bar"), - ), - }, - }, - }) -} - -func testArmadasDataSourceSitesConfigBasic(name string) string { - return fmt.Sprintf(`resource "ec_armada_site" "test" { - metadata { - name = "%s" - } - spec { - description = "My Site" - credentials { - endpoint = "endpoint" - certificate = "cert" - namespace = "ns" - token = "tok" - } - resources { - cpu = "250m" - memory = "1Gi" - } - template { - env { - name = "foo" - value = "bar" - } - image_pull_secrets = [ "test-secret" ] - } - } -} -`, name) -} - -func testArmadaDataSourceSiteConfigRead() string { - return `data "ec_armada_site" "test" { - metadata { - name = "${ec_armada_site.test.metadata.0.name}" - } -} -` -} diff --git a/ec/armada/data_source_armada_armada_test.go b/ec/armada/data_source_armada_test.go similarity index 92% rename from ec/armada/data_source_armada_armada_test.go rename to ec/armada/data_source_armada_test.go index a0bac4e..0371847 100644 --- a/ec/armada/data_source_armada_armada_test.go +++ b/ec/armada/data_source_armada_test.go @@ -8,7 +8,7 @@ import ( "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" ) -func TestArmadaDataSourceArmadas(t *testing.T) { +func TestDataSourceArmadas(t *testing.T) { name := "my-armada" pf, _ := providertest.SetupProviderFactories(t) @@ -17,7 +17,7 @@ func TestArmadaDataSourceArmadas(t *testing.T) { ProviderFactories: pf, Steps: []resource.TestStep{ { - Config: testArmadasDataSourceArmadasConfigBasic(name), + Config: testDataSourceArmadasConfigBasic(name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("ec_armada_armada.test", "metadata.0.name", name), resource.TestCheckResourceAttr("ec_armada_armada.test", "spec.#", "1"), @@ -35,8 +35,8 @@ func TestArmadaDataSourceArmadas(t *testing.T) { ), }, { - Config: testArmadasDataSourceArmadasConfigBasic(name) + - testArmadaDataSourceArmadaConfigRead(), + Config: testDataSourceArmadasConfigBasic(name) + + testDataSourceArmadaConfigRead(), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.ec_armada_armada.test", "metadata.0.name", name), resource.TestCheckResourceAttr("data.ec_armada_armada.test", "spec.#", "1"), @@ -57,7 +57,7 @@ func TestArmadaDataSourceArmadas(t *testing.T) { }) } -func testArmadasDataSourceArmadasConfigBasic(name string) string { +func testDataSourceArmadasConfigBasic(name string) string { return fmt.Sprintf(`resource "ec_armada_armada" "test" { metadata { name = "%s" @@ -90,7 +90,7 @@ func testArmadasDataSourceArmadasConfigBasic(name string) string { `, name) } -func testArmadaDataSourceArmadaConfigRead() string { +func testDataSourceArmadaConfigRead() string { return `data "ec_armada_armada" "test" { metadata { name = "${ec_armada_armada.test.metadata.0.name}" diff --git a/ec/armada/data_source_armada_armadaset.go b/ec/armada/data_source_armadaset.go similarity index 52% rename from ec/armada/data_source_armada_armadaset.go rename to ec/armada/data_source_armadaset.go index 3f643a5..bb97204 100644 --- a/ec/armada/data_source_armada_armadaset.go +++ b/ec/armada/data_source_armadaset.go @@ -7,18 +7,18 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -// DataSourceArmadaArmadaSet returns the data source resource for an ArmadaSet. -func DataSourceArmadaArmadaSet() *schema.Resource { +// DataSourceArmadaSet returns the data source resource for an ArmadaSet. +func DataSourceArmadaSet() *schema.Resource { return &schema.Resource{ Description: "Use this data source to access information about an existing ArmadaSet.", - ReadContext: dataSourceArmadaArmadaSetRead, + ReadContext: dataSourceArmadaSetRead, Schema: armadaSetSchema(), } } -func dataSourceArmadaArmadaSetRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func dataSourceArmadaSetRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { name := d.Get("metadata.0.name").(string) d.SetId(name) - return resourceArmadaArmadaSetRead(ctx, d, m) + return resourceArmadaSetRead(ctx, d, m) } diff --git a/ec/armada/data_source_armada_armadaset_test.go b/ec/armada/data_source_armadaset_test.go similarity index 92% rename from ec/armada/data_source_armada_armadaset_test.go rename to ec/armada/data_source_armadaset_test.go index f6693a0..41f2fd6 100644 --- a/ec/armada/data_source_armada_armadaset_test.go +++ b/ec/armada/data_source_armadaset_test.go @@ -8,7 +8,7 @@ import ( "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" ) -func TestArmadaDataSourceArmadaSets(t *testing.T) { +func TestDataSourceArmadaSets(t *testing.T) { name := "my-armadaset" pf, _ := providertest.SetupProviderFactories(t) @@ -17,7 +17,7 @@ func TestArmadaDataSourceArmadaSets(t *testing.T) { ProviderFactories: pf, Steps: []resource.TestStep{ { - Config: testArmadasDataSourceArmadaSetsConfigBasic(name), + Config: testDataSourceArmadaSetsConfigBasic(name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("ec_armada_armadaset.test", "metadata.0.name", name), resource.TestCheckResourceAttr("ec_armada_armadaset.test", "spec.#", "1"), @@ -35,8 +35,8 @@ func TestArmadaDataSourceArmadaSets(t *testing.T) { ), }, { - Config: testArmadasDataSourceArmadaSetsConfigBasic(name) + - testArmadaDataSourceArmadaSetConfigRead(), + Config: testDataSourceArmadaSetsConfigBasic(name) + + testDataSourceArmadaSetConfigRead(), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.ec_armada_armadaset.test", "metadata.0.name", name), resource.TestCheckResourceAttr("data.ec_armada_armadaset.test", "spec.#", "1"), @@ -57,7 +57,7 @@ func TestArmadaDataSourceArmadaSets(t *testing.T) { }) } -func testArmadasDataSourceArmadaSetsConfigBasic(name string) string { +func testDataSourceArmadaSetsConfigBasic(name string) string { return fmt.Sprintf(`resource "ec_armada_armadaset" "test" { metadata { name = "%s" @@ -93,7 +93,7 @@ func testArmadasDataSourceArmadaSetsConfigBasic(name string) string { `, name) } -func testArmadaDataSourceArmadaSetConfigRead() string { +func testDataSourceArmadaSetConfigRead() string { return `data "ec_armada_armadaset" "test" { metadata { name = "${ec_armada_armadaset.test.metadata.0.name}" diff --git a/ec/armada/resource_armada_armada.go b/ec/armada/resource_armada.go similarity index 76% rename from ec/armada/resource_armada_armada.go rename to ec/armada/resource_armada.go index 77114e2..0e0e26b 100644 --- a/ec/armada/resource_armada_armada.go +++ b/ec/armada/resource_armada.go @@ -9,17 +9,17 @@ import ( "github.com/nitrado/terraform-provider-ec/pkg/resource" "gitlab.com/nitrado/b2b/ec/apicore/api/errors" metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" - armadav1 "gitlab.com/nitrado/b2b/ec/armada/pkg/api/armada/v1" + armadav1 "gitlab.com/nitrado/b2b/ec/core/pkg/api/armada/v1" ) -// ResourceArmadaArmada returns the resource for an Armada. -func ResourceArmadaArmada() *schema.Resource { +// ResourceArmada returns the resource for an Armada. +func ResourceArmada() *schema.Resource { return &schema.Resource{ Description: "An Armada distributes a specified number of Game Servers across a Region.", - ReadContext: resourceArmadaArmadaRead, - CreateContext: resourceArmadaArmadaCreate, - UpdateContext: resourceArmadaArmadaUpdate, - DeleteContext: resourceArmadaArmadaDelete, + ReadContext: resourceArmadaRead, + CreateContext: resourceArmadaCreate, + UpdateContext: resourceArmadaUpdate, + DeleteContext: resourceArmadaDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -27,7 +27,7 @@ func ResourceArmadaArmada() *schema.Resource { } } -func resourceArmadaArmadaRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceArmadaRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -57,7 +57,7 @@ func resourceArmadaArmadaRead(ctx context.Context, d *schema.ResourceData, m any return nil } -func resourceArmadaArmadaCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceArmadaCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -79,10 +79,10 @@ func resourceArmadaArmadaCreate(ctx context.Context, d *schema.ResourceData, m a } d.SetId(ec.ScopedName(out.Environment, out.Name)) - return resourceArmadaArmadaRead(ctx, d, m) + return resourceArmadaRead(ctx, d, m) } -func resourceArmadaArmadaUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceArmadaUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -104,10 +104,10 @@ func resourceArmadaArmadaUpdate(ctx context.Context, d *schema.ResourceData, m a } d.SetId(ec.ScopedName(out.Environment, out.Name)) - return resourceArmadaArmadaRead(ctx, d, m) + return resourceArmadaRead(ctx, d, m) } -func resourceArmadaArmadaDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceArmadaDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) diff --git a/ec/armada/resource_armada_region_test.go b/ec/armada/resource_armada_region_test.go deleted file mode 100644 index afc0b64..0000000 --- a/ec/armada/resource_armada_region_test.go +++ /dev/null @@ -1,131 +0,0 @@ -package armada_test - -import ( - "context" - "fmt" - "strings" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" - metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" - "gitlab.com/nitrado/b2b/ec/armada/pkg/apiclient/clientset" -) - -func TestArmadaResourceRegions(t *testing.T) { - name := "my-region" - env := "dflt" - pf, cs := providertest.SetupProviderFactories(t) - - resource.Test(t, resource.TestCase{ - IsUnitTest: true, - ProviderFactories: pf, - CheckDestroy: testCheckArmadaRegionDestroy(cs), - Steps: []resource.TestStep{ - { - Config: testArmadasResourceRegionsConfigBasic(env, name), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ec_armada_region.test", "metadata.0.name", name), - resource.TestCheckResourceAttr("ec_armada_region.test", "metadata.0.environment", env), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.#", "1"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.description", "My Region"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.#", "1"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.name", "my-type"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.sites.#", "2"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.sites.0", "test-site-1"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.sites.1", "test-site-2"), - ), - }, - { - Config: testArmadasResourceRegionsConfigBasicWithEnv(env, name), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ec_armada_region.test", "metadata.0.name", name), - resource.TestCheckResourceAttr("ec_armada_region.test", "metadata.0.environment", env), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.#", "1"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.description", "My Region"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.#", "1"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.name", "my-type"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.sites.#", "2"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.sites.0", "test-site-1"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.sites.1", "test-site-2"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.template.0.env.#", "2"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.template.0.env.0.name", "foo"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.template.0.env.0.value", "bar"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.template.0.env.1.name", "baz"), - resource.TestCheckResourceAttr("ec_armada_region.test", "spec.0.types.0.template.0.env.1.value_from.0.config_file_key_ref.0.name", "bat"), - ), - }, - { - ResourceName: "ec_armada_region.test", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testArmadasResourceRegionsConfigBasic(env, name string) string { - return fmt.Sprintf(`resource "ec_armada_region" "test" { - metadata { - name = "%s" - environment = "%s" - } - spec { - description = "My Region" - types { - name = "my-type" - sites = ["test-site-1", "test-site-2"] - } - } -}`, name, env) -} - -func testArmadasResourceRegionsConfigBasicWithEnv(env, name string) string { - return fmt.Sprintf(`resource "ec_armada_region" "test" { - metadata { - name = "%s" - environment = "%s" - } - spec { - description = "My Region" - types { - name = "my-type" - sites = ["test-site-1", "test-site-2"] - template { - env { - name = "foo" - value = "bar" - } - env { - name = "baz" - value_from { - config_file_key_ref { - name = "bat" - } - } - } - } - } - } -}`, name, env) -} - -func testCheckArmadaRegionDestroy(cs clientset.Interface) func(s *terraform.State) error { - return func(s *terraform.State) error { - for _, rs := range s.RootModule().Resources { - if rs.Type != "ec_armada_region" { - continue - } - - env, name, _ := strings.Cut(rs.Primary.ID, "/") - resp, err := cs.ArmadaV1().Regions(env).Get(context.Background(), name, metav1.GetOptions{}) - if err == nil { - if resp.Name == rs.Primary.ID { - return fmt.Errorf("region still exists: %s", rs.Primary.ID) - } - } - } - return nil - } -} diff --git a/ec/armada/resource_armada_site_test.go b/ec/armada/resource_armada_site_test.go deleted file mode 100644 index a957f5c..0000000 --- a/ec/armada/resource_armada_site_test.go +++ /dev/null @@ -1,185 +0,0 @@ -package armada_test - -import ( - "context" - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" - metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" - "gitlab.com/nitrado/b2b/ec/armada/pkg/apiclient/clientset" -) - -func TestArmadaResourceSites(t *testing.T) { - name := "my-site" - pf, cs := providertest.SetupProviderFactories(t) - - resource.Test(t, resource.TestCase{ - IsUnitTest: true, - ProviderFactories: pf, - CheckDestroy: testCheckArmadaSiteDestroy(cs), - Steps: []resource.TestStep{ - { - Config: testArmadasResourceSitesConfigBasic(name), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ec_armada_site.test", "metadata.0.name", name), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.#", "1"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.description", "My Site"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.endpoint", "endpoint"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.certificate", "cert"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.namespace", "ns"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.token", "tok"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.resources.0.cpu", "250m"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.resources.0.memory", "1Gi"), - ), - }, - { - Config: testArmadasResourceSitesConfigBasic2(name), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ec_armada_site.test", "metadata.0.name", name), - resource.TestCheckResourceAttr("ec_armada_site.test", "metadata.0.labels.foo", "bar"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.#", "1"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.description", "My Other Site"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.endpoint", "endpoint"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.certificate", "cert"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.namespace", "ns"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.token", "tok"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.resources.0.cpu", "250m"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.resources.0.memory", "1Gi"), - ), - }, - { - Config: testArmadasResourceSitesConfigBasicWithEnv(name), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ec_armada_site.test", "metadata.0.name", name), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.#", "1"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.description", "My Other Site"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.endpoint", "endpoint"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.certificate", "cert"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.namespace", "ns"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.credentials.0.token", "tok"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.resources.0.cpu", "250m"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.resources.0.memory", "1Gi"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.template.0.env.#", "2"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.template.0.env.0.name", "foo"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.template.0.env.0.value", "bar"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.template.0.env.1.name", "baz"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.template.0.env.1.value_from.0.config_file_key_ref.0.name", "bat"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.template.0.security_context.0.allow_privilege_escalation.#", "1"), - resource.TestCheckResourceAttr("ec_armada_site.test", "spec.0.template.0.security_context.0.allow_privilege_escalation.0.value", "false"), - ), - }, - { - ResourceName: "ec_armada_site.test", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testArmadasResourceSitesConfigBasic(name string) string { - return fmt.Sprintf(`resource "ec_armada_site" "test" { - metadata { - name = "%s" - } - spec { - description = "My Site" - credentials { - endpoint = "endpoint" - certificate = "cert" - namespace = "ns" - token = "tok" - } - resources { - cpu = "250m" - memory = "1Gi" - } - } -}`, name) -} - -func testArmadasResourceSitesConfigBasic2(name string) string { - return fmt.Sprintf(`resource "ec_armada_site" "test" { - metadata { - name = "%s" - labels = { - "foo" = "bar" - } - } - spec { - description = "My Other Site" - credentials { - endpoint = "endpoint" - certificate = "cert" - namespace = "ns" - token = "tok" - } - resources { - cpu = "250m" - memory = "1Gi" - } - } -}`, name) -} - -func testArmadasResourceSitesConfigBasicWithEnv(name string) string { - return fmt.Sprintf(`resource "ec_armada_site" "test" { - metadata { - name = "%s" - } - spec { - description = "My Other Site" - credentials { - endpoint = "endpoint" - certificate = "cert" - namespace = "ns" - token = "tok" - } - resources { - cpu = "250m" - memory = "1Gi" - } - template { - env { - name = "foo" - value = "bar" - } - env { - name = "baz" - value_from { - config_file_key_ref { - name = "bat" - } - } - } - security_context { - allow_privilege_escalation { - value = false - } - } - } - } -}`, name) -} - -func testCheckArmadaSiteDestroy(cs clientset.Interface) func(s *terraform.State) error { - return func(s *terraform.State) error { - for _, rs := range s.RootModule().Resources { - if rs.Type != "ec_armada_site" { - continue - } - - name := rs.Primary.ID - resp, err := cs.ArmadaV1().Sites().Get(context.Background(), name, metav1.GetOptions{}) - if err == nil { - if resp.Name == rs.Primary.ID { - return fmt.Errorf("Site still exists: %s", rs.Primary.ID) - } - } - } - return nil - } -} diff --git a/ec/armada/resource_armada_armada_test.go b/ec/armada/resource_armada_test.go similarity index 91% rename from ec/armada/resource_armada_armada_test.go rename to ec/armada/resource_armada_test.go index bb13f00..ad224c4 100644 --- a/ec/armada/resource_armada_armada_test.go +++ b/ec/armada/resource_armada_test.go @@ -10,10 +10,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" - "gitlab.com/nitrado/b2b/ec/armada/pkg/apiclient/clientset" + "gitlab.com/nitrado/b2b/ec/core/pkg/apiclient/clientset" ) -func TestArmadaResourceArmadas(t *testing.T) { +func TestResourceArmadas(t *testing.T) { name := "my-armada" env := "dflt" pf, cs := providertest.SetupProviderFactories(t) @@ -21,10 +21,10 @@ func TestArmadaResourceArmadas(t *testing.T) { resource.Test(t, resource.TestCase{ IsUnitTest: true, ProviderFactories: pf, - CheckDestroy: testCheckArmadaArmadasDestroy(cs), + CheckDestroy: testCheckArmadasDestroy(cs), Steps: []resource.TestStep{ { - Config: testArmadasResourceArmadasConfigBasic(env, name), + Config: testResourceArmadasConfigBasic(env, name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("ec_armada_armada.test", "metadata.0.name", name), resource.TestCheckResourceAttr("ec_armada_armada.test", "metadata.0.environment", env), @@ -43,7 +43,7 @@ func TestArmadaResourceArmadas(t *testing.T) { ), }, { - Config: testArmadasResourceArmadasConfigBasicWithEnv(env, name), + Config: testResourceArmadasConfigBasicWithEnv(env, name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("ec_armada_armada.test", "metadata.0.name", name), resource.TestCheckResourceAttr("ec_armada_armada.test", "metadata.0.environment", env), @@ -75,7 +75,7 @@ func TestArmadaResourceArmadas(t *testing.T) { }) } -func testArmadasResourceArmadasConfigBasic(env, name string) string { +func testResourceArmadasConfigBasic(env, name string) string { return fmt.Sprintf(`resource "ec_armada_armada" "test" { metadata { name = "%s" @@ -108,7 +108,7 @@ func testArmadasResourceArmadasConfigBasic(env, name string) string { }`, name, env) } -func testArmadasResourceArmadasConfigBasicWithEnv(env, name string) string { +func testResourceArmadasConfigBasicWithEnv(env, name string) string { return fmt.Sprintf(`resource "ec_armada_armada" "test" { metadata { name = "%s" @@ -153,7 +153,7 @@ func testArmadasResourceArmadasConfigBasicWithEnv(env, name string) string { }`, name, env) } -func testCheckArmadaArmadasDestroy(cs clientset.Interface) func(s *terraform.State) error { +func testCheckArmadasDestroy(cs clientset.Interface) func(s *terraform.State) error { return func(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "ec_armada_armada" { diff --git a/ec/armada/resource_armada_armadaset.go b/ec/armada/resource_armadaset.go similarity index 76% rename from ec/armada/resource_armada_armadaset.go rename to ec/armada/resource_armadaset.go index 12186e4..3cf9de6 100644 --- a/ec/armada/resource_armada_armadaset.go +++ b/ec/armada/resource_armadaset.go @@ -9,17 +9,17 @@ import ( "github.com/nitrado/terraform-provider-ec/pkg/resource" "gitlab.com/nitrado/b2b/ec/apicore/api/errors" metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" - armadav1 "gitlab.com/nitrado/b2b/ec/armada/pkg/api/armada/v1" + armadav1 "gitlab.com/nitrado/b2b/ec/core/pkg/api/armada/v1" ) -// ResourceArmadaArmadaSet returns the resource for an ArmadaSet. -func ResourceArmadaArmadaSet() *schema.Resource { +// ResourceArmadaSet returns the resource for an ArmadaSet. +func ResourceArmadaSet() *schema.Resource { return &schema.Resource{ Description: "An ArmadaSet manages Armadas across multiple Regions, while sharing a common specification.", - ReadContext: resourceArmadaArmadaSetRead, - CreateContext: resourceArmadaArmadaSetCreate, - UpdateContext: resourceArmadaArmadaSetUpdate, - DeleteContext: resourceArmadaArmadaSetDelete, + ReadContext: resourceArmadaSetRead, + CreateContext: resourceArmadaSetCreate, + UpdateContext: resourceArmadaSetUpdate, + DeleteContext: resourceArmadaSetDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -27,7 +27,7 @@ func ResourceArmadaArmadaSet() *schema.Resource { } } -func resourceArmadaArmadaSetRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceArmadaSetRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -57,7 +57,7 @@ func resourceArmadaArmadaSetRead(ctx context.Context, d *schema.ResourceData, m return nil } -func resourceArmadaArmadaSetCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceArmadaSetCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -79,10 +79,10 @@ func resourceArmadaArmadaSetCreate(ctx context.Context, d *schema.ResourceData, } d.SetId(ec.ScopedName(out.Environment, out.Name)) - return resourceArmadaArmadaSetRead(ctx, d, m) + return resourceArmadaSetRead(ctx, d, m) } -func resourceArmadaArmadaSetUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceArmadaSetUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -104,10 +104,10 @@ func resourceArmadaArmadaSetUpdate(ctx context.Context, d *schema.ResourceData, } d.SetId(ec.ScopedName(out.Environment, out.Name)) - return resourceArmadaArmadaSetRead(ctx, d, m) + return resourceArmadaSetRead(ctx, d, m) } -func resourceArmadaArmadaSetDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceArmadaSetDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) diff --git a/ec/armada/resource_armada_armadaset_test.go b/ec/armada/resource_armadaset_test.go similarity index 92% rename from ec/armada/resource_armada_armadaset_test.go rename to ec/armada/resource_armadaset_test.go index 3eb1a43..bbd95fa 100644 --- a/ec/armada/resource_armada_armadaset_test.go +++ b/ec/armada/resource_armadaset_test.go @@ -10,10 +10,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" - "gitlab.com/nitrado/b2b/ec/armada/pkg/apiclient/clientset" + "gitlab.com/nitrado/b2b/ec/core/pkg/apiclient/clientset" ) -func TestArmadaResourceArmadaSets(t *testing.T) { +func TestResourceArmadaSets(t *testing.T) { name := "my-armadaset" env := "dflt" pf, cs := providertest.SetupProviderFactories(t) @@ -21,10 +21,10 @@ func TestArmadaResourceArmadaSets(t *testing.T) { resource.Test(t, resource.TestCase{ IsUnitTest: true, ProviderFactories: pf, - CheckDestroy: testCheckArmadaArmadaSetsDestroy(cs), + CheckDestroy: testCheckArmadaSetsDestroy(cs), Steps: []resource.TestStep{ { - Config: testArmadasResourceArmadaSetsConfigBasic(env, name), + Config: testResourceArmadaSetsConfigBasic(env, name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("ec_armada_armadaset.test", "metadata.0.name", name), resource.TestCheckResourceAttr("ec_armada_armadaset.test", "metadata.0.environment", env), @@ -43,7 +43,7 @@ func TestArmadaResourceArmadaSets(t *testing.T) { ), }, { - Config: testArmadasResourceArmadaSetsConfigBasicWithEnv(env, name), + Config: testResourceArmadaSetsConfigBasicWithEnv(env, name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("ec_armada_armadaset.test", "metadata.0.name", name), resource.TestCheckResourceAttr("ec_armada_armadaset.test", "metadata.0.environment", env), @@ -75,7 +75,7 @@ func TestArmadaResourceArmadaSets(t *testing.T) { }) } -func testArmadasResourceArmadaSetsConfigBasic(env, name string) string { +func testResourceArmadaSetsConfigBasic(env, name string) string { return fmt.Sprintf(`resource "ec_armada_armadaset" "test" { metadata { name = "%s" @@ -111,7 +111,7 @@ func testArmadasResourceArmadaSetsConfigBasic(env, name string) string { }`, name, env) } -func testArmadasResourceArmadaSetsConfigBasicWithEnv(env, name string) string { +func testResourceArmadaSetsConfigBasicWithEnv(env, name string) string { return fmt.Sprintf(`resource "ec_armada_armadaset" "test" { metadata { name = "%s" @@ -159,7 +159,7 @@ func testArmadasResourceArmadaSetsConfigBasicWithEnv(env, name string) string { }`, name, env) } -func testCheckArmadaArmadaSetsDestroy(cs clientset.Interface) func(s *terraform.State) error { +func testCheckArmadaSetsDestroy(cs clientset.Interface) func(s *terraform.State) error { return func(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "ec_armada_armadaset" { diff --git a/ec/container/data_source_container_branch.go b/ec/container/data_source_branch.go similarity index 53% rename from ec/container/data_source_container_branch.go rename to ec/container/data_source_branch.go index 6b21ffd..9b94a36 100644 --- a/ec/container/data_source_container_branch.go +++ b/ec/container/data_source_branch.go @@ -7,18 +7,18 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -// DataSourceContainerBranch returns the data source resource for a Branch. -func DataSourceContainerBranch() *schema.Resource { +// DataSourceBranch returns the data source resource for a Branch. +func DataSourceBranch() *schema.Resource { return &schema.Resource{ Description: "Use this data source to access information about an existing Branch.", - ReadContext: dataSourceContainerBranchRead, + ReadContext: dataSourceBranchRead, Schema: branchSchema(), } } -func dataSourceContainerBranchRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func dataSourceBranchRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { name := d.Get("metadata.0.name").(string) d.SetId(name) - return resourceContainerBranchRead(ctx, d, m) + return resourceBranchRead(ctx, d, m) } diff --git a/ec/container/data_source_container_branch_test.go b/ec/container/data_source_branch_test.go similarity index 79% rename from ec/container/data_source_container_branch_test.go rename to ec/container/data_source_branch_test.go index 95717ee..556c2be 100644 --- a/ec/container/data_source_container_branch_test.go +++ b/ec/container/data_source_branch_test.go @@ -8,7 +8,7 @@ import ( "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" ) -func TestArmadaDataSourceBranches(t *testing.T) { +func TestDataSourceBranches(t *testing.T) { name := "my-branch" pf, _ := providertest.SetupProviderFactories(t) @@ -17,7 +17,7 @@ func TestArmadaDataSourceBranches(t *testing.T) { ProviderFactories: pf, Steps: []resource.TestStep{ { - Config: testContainerDataSourceBranchesConfigBasic(name), + Config: testDataSourceBranchesConfigBasic(name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("ec_container_branch.test", "metadata.0.name", name), resource.TestCheckResourceAttr("ec_container_branch.test", "spec.#", "1"), @@ -25,8 +25,8 @@ func TestArmadaDataSourceBranches(t *testing.T) { ), }, { - Config: testContainerDataSourceBranchesConfigBasic(name) + - testContainerDataSourceBranchConfigRead(), + Config: testDataSourceBranchesConfigBasic(name) + + testDataSourceBranchConfigRead(), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.ec_container_branch.test", "metadata.0.name", name), resource.TestCheckResourceAttr("data.ec_container_branch.test", "spec.#", "1"), @@ -37,7 +37,7 @@ func TestArmadaDataSourceBranches(t *testing.T) { }) } -func testContainerDataSourceBranchesConfigBasic(name string) string { +func testDataSourceBranchesConfigBasic(name string) string { return fmt.Sprintf(`resource "ec_container_branch" "test" { metadata { name = "%s" @@ -49,7 +49,7 @@ func testContainerDataSourceBranchesConfigBasic(name string) string { `, name) } -func testContainerDataSourceBranchConfigRead() string { +func testDataSourceBranchConfigRead() string { return `data "ec_container_branch" "test" { metadata { name = "${ec_container_branch.test.metadata.0.name}" diff --git a/ec/container/resource_container_branch.go b/ec/container/resource_branch.go similarity index 75% rename from ec/container/resource_container_branch.go rename to ec/container/resource_branch.go index 8b336d8..ee74574 100644 --- a/ec/container/resource_container_branch.go +++ b/ec/container/resource_branch.go @@ -9,17 +9,17 @@ import ( "github.com/nitrado/terraform-provider-ec/pkg/resource" "gitlab.com/nitrado/b2b/ec/apicore/api/errors" metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" - containerv1 "gitlab.com/nitrado/b2b/ec/armada/pkg/api/container/v1" + containerv1 "gitlab.com/nitrado/b2b/ec/core/pkg/api/container/v1" ) -// ResourceContainerBranch returns the resource for a Branch. -func ResourceContainerBranch() *schema.Resource { +// ResourceBranch returns the resource for a Branch. +func ResourceBranch() *schema.Resource { return &schema.Resource{ Description: "A Branch groups container Images.", - ReadContext: resourceContainerBranchRead, - CreateContext: resourceContainerBranchCreate, - UpdateContext: resourceContainerBranchUpdate, - DeleteContext: resourceContainerBranchDelete, + ReadContext: resourceBranchRead, + CreateContext: resourceBranchCreate, + UpdateContext: resourceBranchUpdate, + DeleteContext: resourceBranchDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -27,7 +27,7 @@ func ResourceContainerBranch() *schema.Resource { } } -func resourceContainerBranchRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceBranchRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -57,7 +57,7 @@ func resourceContainerBranchRead(ctx context.Context, d *schema.ResourceData, m return nil } -func resourceContainerBranchCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceBranchCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -79,10 +79,10 @@ func resourceContainerBranchCreate(ctx context.Context, d *schema.ResourceData, } d.SetId(out.Name) - return resourceContainerBranchRead(ctx, d, m) + return resourceBranchRead(ctx, d, m) } -func resourceContainerBranchUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceBranchUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -104,10 +104,10 @@ func resourceContainerBranchUpdate(ctx context.Context, d *schema.ResourceData, } d.SetId(out.Name) - return resourceContainerBranchRead(ctx, d, m) + return resourceBranchRead(ctx, d, m) } -func resourceContainerBranchDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceBranchDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) diff --git a/ec/container/resource_container_branch_test.go b/ec/container/resource_branch_test.go similarity index 79% rename from ec/container/resource_container_branch_test.go rename to ec/container/resource_branch_test.go index f56809d..a53a45c 100644 --- a/ec/container/resource_container_branch_test.go +++ b/ec/container/resource_branch_test.go @@ -9,20 +9,20 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" - "gitlab.com/nitrado/b2b/ec/armada/pkg/apiclient/clientset" + "gitlab.com/nitrado/b2b/ec/core/pkg/apiclient/clientset" ) -func TestContainerResourceBranch(t *testing.T) { +func TestResourceBranch(t *testing.T) { name := "my-branch" pf, cs := providertest.SetupProviderFactories(t) resource.Test(t, resource.TestCase{ IsUnitTest: true, ProviderFactories: pf, - CheckDestroy: testCheckContainerBranchDestroy(cs), + CheckDestroy: testCheckBranchDestroy(cs), Steps: []resource.TestStep{ { - Config: testContainerResourceBranchesConfigBasic(name), + Config: testResourceBranchesConfigBasic(name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("ec_container_branch.test", "metadata.0.name", name), resource.TestCheckResourceAttr("ec_container_branch.test", "spec.#", "1"), @@ -38,7 +38,7 @@ func TestContainerResourceBranch(t *testing.T) { }) } -func testContainerResourceBranchesConfigBasic(name string) string { +func testResourceBranchesConfigBasic(name string) string { return fmt.Sprintf(`resource "ec_container_branch" "test" { metadata { name = "%s" @@ -49,7 +49,7 @@ func testContainerResourceBranchesConfigBasic(name string) string { }`, name) } -func testCheckContainerBranchDestroy(cs clientset.Interface) func(s *terraform.State) error { +func testCheckBranchDestroy(cs clientset.Interface) func(s *terraform.State) error { return func(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "ec_container_branch" { diff --git a/ec/core/data_source_core_environment.go b/ec/core/data_source_core_environment.go index 92c709f..9eaf0ab 100644 --- a/ec/core/data_source_core_environment.go +++ b/ec/core/data_source_core_environment.go @@ -7,18 +7,18 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -// DataSourceCoreEnvironment returns the data source resource for an Environment. -func DataSourceCoreEnvironment() *schema.Resource { +// DataSourceEnvironment returns the data source resource for an Environment. +func DataSourceEnvironment() *schema.Resource { return &schema.Resource{ Description: "Use this data source to access information about an existing Environment.", - ReadContext: dataSourceCoreEnvironmentRead, + ReadContext: dataSourceEnvironmentRead, Schema: environmentSchema(), } } -func dataSourceCoreEnvironmentRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func dataSourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { name := d.Get("metadata.0.name").(string) d.SetId(name) - return resourceCoreEnvironmentRead(ctx, d, m) + return resourceEnvironmentRead(ctx, d, m) } diff --git a/ec/core/data_source_core_environment_test.go b/ec/core/data_source_core_environment_test.go index d2b08ec..d624ab8 100644 --- a/ec/core/data_source_core_environment_test.go +++ b/ec/core/data_source_core_environment_test.go @@ -8,7 +8,7 @@ import ( "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" ) -func TestCoreDataSourceEnvironments(t *testing.T) { +func TestDataSourceEnvironments(t *testing.T) { name := "dflt" pf, _ := providertest.SetupProviderFactories(t) @@ -17,7 +17,7 @@ func TestCoreDataSourceEnvironments(t *testing.T) { ProviderFactories: pf, Steps: []resource.TestStep{ { - Config: testCoreRDataSourceEnvironmentConfigBasic(name), + Config: testDataSourceEnvironmentConfigBasic(name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("ec_core_environment.test", "metadata.0.name", name), resource.TestCheckResourceAttr("ec_core_environment.test", "spec.#", "1"), @@ -26,8 +26,8 @@ func TestCoreDataSourceEnvironments(t *testing.T) { ), }, { - Config: testCoreRDataSourceEnvironmentConfigBasic(name) + - testArmadaDataSourceSiteConfigRead(), + Config: testDataSourceEnvironmentConfigBasic(name) + + testDataSourceEnvironmentConfigRead(), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.ec_core_environment.test", "metadata.0.name", name), resource.TestCheckResourceAttr("data.ec_core_environment.test", "spec.#", "1"), @@ -39,7 +39,7 @@ func TestCoreDataSourceEnvironments(t *testing.T) { }) } -func testCoreRDataSourceEnvironmentConfigBasic(name string) string { +func testDataSourceEnvironmentConfigBasic(name string) string { return fmt.Sprintf(`resource "ec_core_environment" "test" { metadata { name = "%s" @@ -52,7 +52,7 @@ func testCoreRDataSourceEnvironmentConfigBasic(name string) string { `, name) } -func testArmadaDataSourceSiteConfigRead() string { +func testDataSourceEnvironmentConfigRead() string { return `data "ec_core_environment" "test" { metadata { name = "${ec_core_environment.test.metadata.0.name}" diff --git a/ec/armada/data_source_armada_region.go b/ec/core/data_source_core_region.go similarity index 51% rename from ec/armada/data_source_armada_region.go rename to ec/core/data_source_core_region.go index a69620a..4deee98 100644 --- a/ec/armada/data_source_armada_region.go +++ b/ec/core/data_source_core_region.go @@ -1,4 +1,4 @@ -package armada +package core import ( "context" @@ -7,18 +7,18 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -// DataSourceArmadaRegion returns the data source resource for a Region. -func DataSourceArmadaRegion() *schema.Resource { +// DataSourceRegion returns the data source resource for a Region. +func DataSourceRegion() *schema.Resource { return &schema.Resource{ Description: "Use this data source to access information about an existing Region.", - ReadContext: dataSourceArmadaRegionRead, + ReadContext: dataSourceRegionRead, Schema: regionSchema(), } } -func dataSourceArmadaRegionRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func dataSourceRegionRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { name := d.Get("metadata.0.name").(string) d.SetId(name) - return resourceArmadaRegionRead(ctx, d, m) + return resourceRegionRead(ctx, d, m) } diff --git a/ec/core/data_source_core_region_test.go b/ec/core/data_source_core_region_test.go new file mode 100644 index 0000000..4497ed6 --- /dev/null +++ b/ec/core/data_source_core_region_test.go @@ -0,0 +1,73 @@ +package core_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" +) + +func TestDataSourceRegions(t *testing.T) { + name := "my-region" + pf, _ := providertest.SetupProviderFactories(t) + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProviderFactories: pf, + Steps: []resource.TestStep{ + { + Config: testDataSourceRegionsConfigBasic(name), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("ec_core_region.test", "metadata.0.name", name), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.#", "1"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.description", "My Region"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.#", "1"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.name", "my-type"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.sites.#", "2"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.sites.0", "test-site-1"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.sites.1", "test-site-2"), + ), + }, + { + Config: testDataSourceRegionsConfigBasic(name) + + testDataSourceRegionConfigRead(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.ec_core_region.test", "metadata.0.name", name), + resource.TestCheckResourceAttr("data.ec_core_region.test", "spec.#", "1"), + resource.TestCheckResourceAttr("data.ec_core_region.test", "spec.0.description", "My Region"), + resource.TestCheckResourceAttr("data.ec_core_region.test", "spec.0.types.#", "1"), + resource.TestCheckResourceAttr("data.ec_core_region.test", "spec.0.types.0.name", "my-type"), + resource.TestCheckResourceAttr("data.ec_core_region.test", "spec.0.types.0.sites.#", "2"), + resource.TestCheckResourceAttr("data.ec_core_region.test", "spec.0.types.0.sites.0", "test-site-1"), + resource.TestCheckResourceAttr("data.ec_core_region.test", "spec.0.types.0.sites.1", "test-site-2"), + ), + }, + }, + }) +} + +func testDataSourceRegionsConfigBasic(name string) string { + return fmt.Sprintf(`resource "ec_core_region" "test" { + metadata { + name = "%s" + } + spec { + description = "My Region" + types { + name = "my-type" + sites = ["test-site-1", "test-site-2"] + } + } +} +`, name) +} + +func testDataSourceRegionConfigRead() string { + return `data "ec_core_region" "test" { + metadata { + name = "${ec_core_region.test.metadata.0.name}" + } +} +` +} diff --git a/ec/armada/data_source_armada_site.go b/ec/core/data_source_core_site.go similarity index 52% rename from ec/armada/data_source_armada_site.go rename to ec/core/data_source_core_site.go index 51066a0..3d6d4b9 100644 --- a/ec/armada/data_source_armada_site.go +++ b/ec/core/data_source_core_site.go @@ -1,4 +1,4 @@ -package armada +package core import ( "context" @@ -7,18 +7,18 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -// DataSourceArmadaSite returns the data source resource for a Site. -func DataSourceArmadaSite() *schema.Resource { +// DataSourceSite returns the data source resource for a Site. +func DataSourceSite() *schema.Resource { return &schema.Resource{ Description: "Use this data source to access information about an existing Site.", - ReadContext: dataSourceArmadaSiteRead, + ReadContext: dataSourceSiteRead, Schema: siteSchema(), } } -func dataSourceArmadaSiteRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func dataSourceSiteRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { name := d.Get("metadata.0.name").(string) d.SetId(name) - return resourceArmadaSiteRead(ctx, d, m) + return resourceSiteRead(ctx, d, m) } diff --git a/ec/core/data_source_core_site_test.go b/ec/core/data_source_core_site_test.go new file mode 100644 index 0000000..02276f1 --- /dev/null +++ b/ec/core/data_source_core_site_test.go @@ -0,0 +1,92 @@ +package core_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" +) + +func TestDataSourceSites(t *testing.T) { + name := "my-site" + pf, _ := providertest.SetupProviderFactories(t) + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProviderFactories: pf, + Steps: []resource.TestStep{ + { + Config: testDataSourceSitesConfigBasic(name), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("ec_core_site.test", "metadata.0.name", name), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.#", "1"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.description", "My Site"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.endpoint", "endpoint"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.certificate", "cert"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.namespace", "ns"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.token", "tok"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.resources.0.cpu", "250m"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.resources.0.memory", "1Gi"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.template.0.image_pull_secrets.0", "test-secret"), + ), + }, + { + Config: testDataSourceSitesConfigBasic(name) + + testDataSourceSiteConfigRead(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.ec_core_site.test", "metadata.0.name", name), + resource.TestCheckResourceAttr("data.ec_core_site.test", "spec.#", "1"), + resource.TestCheckResourceAttr("data.ec_core_site.test", "spec.0.description", "My Site"), + resource.TestCheckResourceAttr("data.ec_core_site.test", "spec.0.credentials.0.endpoint", "endpoint"), + resource.TestCheckResourceAttr("data.ec_core_site.test", "spec.0.credentials.0.certificate", "cert"), + resource.TestCheckResourceAttr("data.ec_core_site.test", "spec.0.credentials.0.namespace", "ns"), + resource.TestCheckResourceAttr("data.ec_core_site.test", "spec.0.credentials.0.token", "tok"), + resource.TestCheckResourceAttr("data.ec_core_site.test", "spec.0.resources.0.cpu", "250m"), + resource.TestCheckResourceAttr("data.ec_core_site.test", "spec.0.resources.0.memory", "1Gi"), + resource.TestCheckResourceAttr("data.ec_core_site.test", "spec.0.template.0.image_pull_secrets.0", "test-secret"), + resource.TestCheckResourceAttr("data.ec_core_site.test", "spec.0.template.0.env.0.name", "foo"), + resource.TestCheckResourceAttr("data.ec_core_site.test", "spec.0.template.0.env.0.value", "bar"), + ), + }, + }, + }) +} + +func testDataSourceSitesConfigBasic(name string) string { + return fmt.Sprintf(`resource "ec_core_site" "test" { + metadata { + name = "%s" + } + spec { + description = "My Site" + credentials { + endpoint = "endpoint" + certificate = "cert" + namespace = "ns" + token = "tok" + } + resources { + cpu = "250m" + memory = "1Gi" + } + template { + env { + name = "foo" + value = "bar" + } + image_pull_secrets = [ "test-secret" ] + } + } +} +`, name) +} + +func testDataSourceSiteConfigRead() string { + return `data "ec_core_site" "test" { + metadata { + name = "${ec_core_site.test.metadata.0.name}" + } +} +` +} diff --git a/ec/core/resource_core_environment.go b/ec/core/resource_core_environment.go index a897d0d..dfd3d27 100644 --- a/ec/core/resource_core_environment.go +++ b/ec/core/resource_core_environment.go @@ -9,17 +9,17 @@ import ( "github.com/nitrado/terraform-provider-ec/pkg/resource" "gitlab.com/nitrado/b2b/ec/apicore/api/errors" metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" - corev1 "gitlab.com/nitrado/b2b/ec/armada/pkg/api/core/v1" + corev1 "gitlab.com/nitrado/b2b/ec/core/pkg/api/core/v1" ) -// ResourceCoreEnvironment returns the resource for an Environment. -func ResourceCoreEnvironment() *schema.Resource { +// ResourceEnvironment returns the resource for an Environment. +func ResourceEnvironment() *schema.Resource { return &schema.Resource{ Description: "An Environment provides a mechanism to isolate groups of resources.", - ReadContext: resourceCoreEnvironmentRead, - CreateContext: resourceCoreEnvironmentCreate, - UpdateContext: resourceCoreEnvironmentUpdate, - DeleteContext: resourceCoreEnvironmentDelete, + ReadContext: resourceEnvironmentRead, + CreateContext: resourceEnvironmentCreate, + UpdateContext: resourceEnvironmentUpdate, + DeleteContext: resourceEnvironmentDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -27,7 +27,7 @@ func ResourceCoreEnvironment() *schema.Resource { } } -func resourceCoreEnvironmentRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -57,7 +57,7 @@ func resourceCoreEnvironmentRead(ctx context.Context, d *schema.ResourceData, m return nil } -func resourceCoreEnvironmentCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceEnvironmentCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -77,10 +77,10 @@ func resourceCoreEnvironmentCreate(ctx context.Context, d *schema.ResourceData, } d.SetId(out.Name) - return resourceCoreEnvironmentRead(ctx, d, m) + return resourceEnvironmentRead(ctx, d, m) } -func resourceCoreEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -100,10 +100,10 @@ func resourceCoreEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, } d.SetId(out.Name) - return resourceCoreEnvironmentRead(ctx, d, m) + return resourceEnvironmentRead(ctx, d, m) } -func resourceCoreEnvironmentDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceEnvironmentDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) diff --git a/ec/core/resource_core_environment_test.go b/ec/core/resource_core_environment_test.go index 4117dbc..7e50591 100644 --- a/ec/core/resource_core_environment_test.go +++ b/ec/core/resource_core_environment_test.go @@ -9,20 +9,20 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" - "gitlab.com/nitrado/b2b/ec/armada/pkg/apiclient/clientset" + "gitlab.com/nitrado/b2b/ec/core/pkg/apiclient/clientset" ) -func TestCoreResourceEnvironments(t *testing.T) { +func TestResourceEnvironments(t *testing.T) { name := "dflt" pf, cs := providertest.SetupProviderFactories(t) resource.Test(t, resource.TestCase{ IsUnitTest: true, ProviderFactories: pf, - CheckDestroy: testCheckCoreEnvironmentDestroy(cs), + CheckDestroy: testCheckEnvironmentDestroy(cs), Steps: []resource.TestStep{ { - Config: testCoreResourceEnvironmentConfigBasic(name), + Config: testResourceEnvironmentConfigBasic(name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("ec_core_environment.test", "metadata.0.name", name), resource.TestCheckResourceAttr("ec_core_environment.test", "spec.#", "1"), @@ -39,7 +39,7 @@ func TestCoreResourceEnvironments(t *testing.T) { }) } -func testCoreResourceEnvironmentConfigBasic(name string) string { +func testResourceEnvironmentConfigBasic(name string) string { return fmt.Sprintf(`resource "ec_core_environment" "test" { metadata { name = "%s" @@ -51,7 +51,7 @@ func testCoreResourceEnvironmentConfigBasic(name string) string { }`, name) } -func testCheckCoreEnvironmentDestroy(cs clientset.Interface) func(s *terraform.State) error { +func testCheckEnvironmentDestroy(cs clientset.Interface) func(s *terraform.State) error { return func(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "ec_core_environment" { diff --git a/ec/armada/resource_armada_region.go b/ec/core/resource_core_region.go similarity index 59% rename from ec/armada/resource_armada_region.go rename to ec/core/resource_core_region.go index b9937de..617d223 100644 --- a/ec/armada/resource_armada_region.go +++ b/ec/core/resource_core_region.go @@ -1,4 +1,4 @@ -package armada +package core import ( "context" @@ -9,17 +9,17 @@ import ( "github.com/nitrado/terraform-provider-ec/pkg/resource" "gitlab.com/nitrado/b2b/ec/apicore/api/errors" metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" - armadav1 "gitlab.com/nitrado/b2b/ec/armada/pkg/api/armada/v1" + corev1 "gitlab.com/nitrado/b2b/ec/core/pkg/api/core/v1" ) -// ResourceArmadaRegion returns the resource for a Region. -func ResourceArmadaRegion() *schema.Resource { +// ResourceRegion returns the resource for a Region. +func ResourceRegion() *schema.Resource { return &schema.Resource{ Description: "A Region determines how Armadas are distributed across Sites.", - ReadContext: resourceArmadaRegionRead, - CreateContext: resourceArmadaRegionCreate, - UpdateContext: resourceArmadaRegionUpdate, - DeleteContext: resourceArmadaRegionDelete, + ReadContext: resourceRegionRead, + CreateContext: resourceRegionCreate, + UpdateContext: resourceRegionUpdate, + DeleteContext: resourceRegionDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -27,7 +27,7 @@ func ResourceArmadaRegion() *schema.Resource { } } -func resourceArmadaRegionRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceRegionRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -35,7 +35,7 @@ func resourceArmadaRegionRead(ctx context.Context, d *schema.ResourceData, m any env, name := ec.SplitName(d.Id()) - obj, err := clientSet.ArmadaV1().Regions(env).Get(ctx, name, metav1.GetOptions{}) + obj, err := clientSet.CoreV1().Regions(env).Get(ctx, name, metav1.GetOptions{}) if err != nil { switch { case errors.IsNotFound(err): @@ -57,14 +57,14 @@ func resourceArmadaRegionRead(ctx context.Context, d *schema.ResourceData, m any return nil } -func resourceArmadaRegionCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceRegionCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) } - obj := &armadav1.Region{ - TypeMeta: metav1.TypeMeta{APIVersion: armadav1.GroupVersion.String(), Kind: "Region"}, + obj := &corev1.Region{ + TypeMeta: metav1.TypeMeta{APIVersion: corev1.GroupVersion.String(), Kind: "Region"}, } if err = ec.Converter().Expand(d.Get("metadata").([]any), &obj.ObjectMeta); err != nil { return diag.FromErr(err) @@ -73,23 +73,23 @@ func resourceArmadaRegionCreate(ctx context.Context, d *schema.ResourceData, m a return diag.FromErr(err) } - out, err := clientSet.ArmadaV1().Regions(obj.Environment).Create(ctx, obj, metav1.CreateOptions{}) + out, err := clientSet.CoreV1().Regions(obj.Environment).Create(ctx, obj, metav1.CreateOptions{}) if err != nil { return diag.FromErr(err) } d.SetId(ec.ScopedName(out.Environment, out.Name)) - return resourceArmadaRegionRead(ctx, d, m) + return resourceRegionRead(ctx, d, m) } -func resourceArmadaRegionUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceRegionUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) } - obj := &armadav1.Region{ - TypeMeta: metav1.TypeMeta{APIVersion: armadav1.GroupVersion.String(), Kind: "Region"}, + obj := &corev1.Region{ + TypeMeta: metav1.TypeMeta{APIVersion: corev1.GroupVersion.String(), Kind: "Region"}, } if err = ec.Converter().Expand(d.Get("metadata").([]any), &obj.ObjectMeta); err != nil { return diag.FromErr(err) @@ -98,16 +98,16 @@ func resourceArmadaRegionUpdate(ctx context.Context, d *schema.ResourceData, m a return diag.FromErr(err) } - out, err := clientSet.ArmadaV1().Regions(obj.Environment).Update(ctx, obj, metav1.UpdateOptions{}) + out, err := clientSet.CoreV1().Regions(obj.Environment).Update(ctx, obj, metav1.UpdateOptions{}) if err != nil { return diag.FromErr(err) } d.SetId(ec.ScopedName(out.Environment, out.Name)) - return resourceArmadaRegionRead(ctx, d, m) + return resourceRegionRead(ctx, d, m) } -func resourceArmadaRegionDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceRegionDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -115,7 +115,7 @@ func resourceArmadaRegionDelete(ctx context.Context, d *schema.ResourceData, m a env, name := ec.SplitName(d.Id()) - if err = clientSet.ArmadaV1().Regions(env).Delete(ctx, name, metav1.DeleteOptions{}); err != nil { + if err = clientSet.CoreV1().Regions(env).Delete(ctx, name, metav1.DeleteOptions{}); err != nil { switch { case errors.IsNotFound(err): // We will consider this a successful delete. diff --git a/ec/core/resource_core_region_test.go b/ec/core/resource_core_region_test.go new file mode 100644 index 0000000..035f8d2 --- /dev/null +++ b/ec/core/resource_core_region_test.go @@ -0,0 +1,131 @@ +package core_test + +import ( + "context" + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" + metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" + "gitlab.com/nitrado/b2b/ec/core/pkg/apiclient/clientset" +) + +func TestResourceRegions(t *testing.T) { + name := "my-region" + env := "dflt" + pf, cs := providertest.SetupProviderFactories(t) + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProviderFactories: pf, + CheckDestroy: testCheckArmadaRegionDestroy(cs), + Steps: []resource.TestStep{ + { + Config: testResourceRegionsConfigBasic(env, name), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("ec_core_region.test", "metadata.0.name", name), + resource.TestCheckResourceAttr("ec_core_region.test", "metadata.0.environment", env), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.#", "1"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.description", "My Region"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.#", "1"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.name", "my-type"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.sites.#", "2"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.sites.0", "test-site-1"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.sites.1", "test-site-2"), + ), + }, + { + Config: testResourceRegionsConfigBasicWithEnv(env, name), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("ec_core_region.test", "metadata.0.name", name), + resource.TestCheckResourceAttr("ec_core_region.test", "metadata.0.environment", env), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.#", "1"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.description", "My Region"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.#", "1"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.name", "my-type"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.sites.#", "2"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.sites.0", "test-site-1"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.sites.1", "test-site-2"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.template.0.env.#", "2"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.template.0.env.0.name", "foo"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.template.0.env.0.value", "bar"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.template.0.env.1.name", "baz"), + resource.TestCheckResourceAttr("ec_core_region.test", "spec.0.types.0.template.0.env.1.value_from.0.config_file_key_ref.0.name", "bat"), + ), + }, + { + ResourceName: "ec_core_region.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testResourceRegionsConfigBasic(env, name string) string { + return fmt.Sprintf(`resource "ec_core_region" "test" { + metadata { + name = "%s" + environment = "%s" + } + spec { + description = "My Region" + types { + name = "my-type" + sites = ["test-site-1", "test-site-2"] + } + } +}`, name, env) +} + +func testResourceRegionsConfigBasicWithEnv(env, name string) string { + return fmt.Sprintf(`resource "ec_core_region" "test" { + metadata { + name = "%s" + environment = "%s" + } + spec { + description = "My Region" + types { + name = "my-type" + sites = ["test-site-1", "test-site-2"] + template { + env { + name = "foo" + value = "bar" + } + env { + name = "baz" + value_from { + config_file_key_ref { + name = "bat" + } + } + } + } + } + } +}`, name, env) +} + +func testCheckArmadaRegionDestroy(cs clientset.Interface) func(s *terraform.State) error { + return func(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "ec_core_region" { + continue + } + + env, name, _ := strings.Cut(rs.Primary.ID, "/") + resp, err := cs.CoreV1().Regions(env).Get(context.Background(), name, metav1.GetOptions{}) + if err == nil { + if resp.Name == rs.Primary.ID { + return fmt.Errorf("region still exists: %s", rs.Primary.ID) + } + } + } + return nil + } +} diff --git a/ec/armada/resource_armada_site.go b/ec/core/resource_core_site.go similarity index 59% rename from ec/armada/resource_armada_site.go rename to ec/core/resource_core_site.go index d7e4b2b..c50d99c 100644 --- a/ec/armada/resource_armada_site.go +++ b/ec/core/resource_core_site.go @@ -1,4 +1,4 @@ -package armada +package core import ( "context" @@ -9,17 +9,17 @@ import ( "github.com/nitrado/terraform-provider-ec/pkg/resource" "gitlab.com/nitrado/b2b/ec/apicore/api/errors" metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" - armadav1 "gitlab.com/nitrado/b2b/ec/armada/pkg/api/armada/v1" + corev1 "gitlab.com/nitrado/b2b/ec/core/pkg/api/core/v1" ) -// ResourceArmadaSite returns the resource for a Site. -func ResourceArmadaSite() *schema.Resource { +// ResourceSite returns the resource for a Site. +func ResourceSite() *schema.Resource { return &schema.Resource{ Description: "A Site provides a connection to deployment capacity.", - ReadContext: resourceArmadaSiteRead, - CreateContext: resourceArmadaSiteCreate, - UpdateContext: resourceArmadaSiteUpdate, - DeleteContext: resourceArmadaSiteDelete, + ReadContext: resourceSiteRead, + CreateContext: resourceSiteCreate, + UpdateContext: resourceSiteUpdate, + DeleteContext: resourceSiteDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -27,7 +27,7 @@ func ResourceArmadaSite() *schema.Resource { } } -func resourceArmadaSiteRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceSiteRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -35,7 +35,7 @@ func resourceArmadaSiteRead(ctx context.Context, d *schema.ResourceData, m any) name := d.Id() - obj, err := clientSet.ArmadaV1().Sites().Get(ctx, name, metav1.GetOptions{}) + obj, err := clientSet.CoreV1().Sites().Get(ctx, name, metav1.GetOptions{}) if err != nil { switch { case errors.IsNotFound(err): @@ -57,14 +57,14 @@ func resourceArmadaSiteRead(ctx context.Context, d *schema.ResourceData, m any) return nil } -func resourceArmadaSiteCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceSiteCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) } - obj := &armadav1.Site{ - TypeMeta: metav1.TypeMeta{APIVersion: armadav1.GroupVersion.String(), Kind: "Site"}, + obj := &corev1.Site{ + TypeMeta: metav1.TypeMeta{APIVersion: corev1.GroupVersion.String(), Kind: "Site"}, } if err = ec.Converter().Expand(d.Get("metadata").([]any), &obj.ObjectMeta); err != nil { return diag.FromErr(err) @@ -73,23 +73,23 @@ func resourceArmadaSiteCreate(ctx context.Context, d *schema.ResourceData, m any return diag.FromErr(err) } - out, err := clientSet.ArmadaV1().Sites().Create(ctx, obj, metav1.CreateOptions{}) + out, err := clientSet.CoreV1().Sites().Create(ctx, obj, metav1.CreateOptions{}) if err != nil { return diag.FromErr(err) } d.SetId(out.Name) - return resourceArmadaSiteRead(ctx, d, m) + return resourceSiteRead(ctx, d, m) } -func resourceArmadaSiteUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceSiteUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) } - obj := &armadav1.Site{ - TypeMeta: metav1.TypeMeta{APIVersion: armadav1.GroupVersion.String(), Kind: "Site"}, + obj := &corev1.Site{ + TypeMeta: metav1.TypeMeta{APIVersion: corev1.GroupVersion.String(), Kind: "Site"}, } if err = ec.Converter().Expand(d.Get("metadata").([]any), &obj.ObjectMeta); err != nil { return diag.FromErr(err) @@ -98,16 +98,16 @@ func resourceArmadaSiteUpdate(ctx context.Context, d *schema.ResourceData, m any return diag.FromErr(err) } - out, err := clientSet.ArmadaV1().Sites().Update(ctx, obj, metav1.UpdateOptions{}) + out, err := clientSet.CoreV1().Sites().Update(ctx, obj, metav1.UpdateOptions{}) if err != nil { return diag.FromErr(err) } d.SetId(out.Name) - return resourceArmadaSiteRead(ctx, d, m) + return resourceSiteRead(ctx, d, m) } -func resourceArmadaSiteDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceSiteDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { clientSet, err := ec.ResolveClientSet(m) if err != nil { return diag.FromErr(err) @@ -115,7 +115,7 @@ func resourceArmadaSiteDelete(ctx context.Context, d *schema.ResourceData, m any name := d.Id() - if err = clientSet.ArmadaV1().Sites().Delete(ctx, name, metav1.DeleteOptions{}); err != nil { + if err = clientSet.CoreV1().Sites().Delete(ctx, name, metav1.DeleteOptions{}); err != nil { switch { case errors.IsNotFound(err): // We will consider this a successful delete. diff --git a/ec/core/resource_core_site_test.go b/ec/core/resource_core_site_test.go new file mode 100644 index 0000000..4494c7c --- /dev/null +++ b/ec/core/resource_core_site_test.go @@ -0,0 +1,185 @@ +package core_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/nitrado/terraform-provider-ec/ec/provider/providertest" + metav1 "gitlab.com/nitrado/b2b/ec/apicore/apis/meta/v1" + "gitlab.com/nitrado/b2b/ec/core/pkg/apiclient/clientset" +) + +func TestResourceSites(t *testing.T) { + name := "my-site" + pf, cs := providertest.SetupProviderFactories(t) + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProviderFactories: pf, + CheckDestroy: testCheckSiteDestroy(cs), + Steps: []resource.TestStep{ + { + Config: testResourceSitesConfigBasic(name), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("ec_core_site.test", "metadata.0.name", name), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.#", "1"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.description", "My Site"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.endpoint", "endpoint"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.certificate", "cert"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.namespace", "ns"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.token", "tok"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.resources.0.cpu", "250m"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.resources.0.memory", "1Gi"), + ), + }, + { + Config: testResourceSitesConfigBasic2(name), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("ec_core_site.test", "metadata.0.name", name), + resource.TestCheckResourceAttr("ec_core_site.test", "metadata.0.labels.foo", "bar"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.#", "1"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.description", "My Other Site"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.endpoint", "endpoint"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.certificate", "cert"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.namespace", "ns"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.token", "tok"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.resources.0.cpu", "250m"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.resources.0.memory", "1Gi"), + ), + }, + { + Config: testResourceSitesConfigBasicWithEnv(name), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("ec_core_site.test", "metadata.0.name", name), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.#", "1"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.description", "My Other Site"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.endpoint", "endpoint"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.certificate", "cert"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.namespace", "ns"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.credentials.0.token", "tok"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.resources.0.cpu", "250m"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.resources.0.memory", "1Gi"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.template.0.env.#", "2"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.template.0.env.0.name", "foo"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.template.0.env.0.value", "bar"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.template.0.env.1.name", "baz"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.template.0.env.1.value_from.0.config_file_key_ref.0.name", "bat"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.template.0.security_context.0.allow_privilege_escalation.#", "1"), + resource.TestCheckResourceAttr("ec_core_site.test", "spec.0.template.0.security_context.0.allow_privilege_escalation.0.value", "false"), + ), + }, + { + ResourceName: "ec_core_site.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testResourceSitesConfigBasic(name string) string { + return fmt.Sprintf(`resource "ec_core_site" "test" { + metadata { + name = "%s" + } + spec { + description = "My Site" + credentials { + endpoint = "endpoint" + certificate = "cert" + namespace = "ns" + token = "tok" + } + resources { + cpu = "250m" + memory = "1Gi" + } + } +}`, name) +} + +func testResourceSitesConfigBasic2(name string) string { + return fmt.Sprintf(`resource "ec_core_site" "test" { + metadata { + name = "%s" + labels = { + "foo" = "bar" + } + } + spec { + description = "My Other Site" + credentials { + endpoint = "endpoint" + certificate = "cert" + namespace = "ns" + token = "tok" + } + resources { + cpu = "250m" + memory = "1Gi" + } + } +}`, name) +} + +func testResourceSitesConfigBasicWithEnv(name string) string { + return fmt.Sprintf(`resource "ec_core_site" "test" { + metadata { + name = "%s" + } + spec { + description = "My Other Site" + credentials { + endpoint = "endpoint" + certificate = "cert" + namespace = "ns" + token = "tok" + } + resources { + cpu = "250m" + memory = "1Gi" + } + template { + env { + name = "foo" + value = "bar" + } + env { + name = "baz" + value_from { + config_file_key_ref { + name = "bat" + } + } + } + security_context { + allow_privilege_escalation { + value = false + } + } + } + } +}`, name) +} + +func testCheckSiteDestroy(cs clientset.Interface) func(s *terraform.State) error { + return func(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "ec_armada_site" { + continue + } + + name := rs.Primary.ID + resp, err := cs.CoreV1().Sites().Get(context.Background(), name, metav1.GetOptions{}) + if err == nil { + if resp.Name == rs.Primary.ID { + return fmt.Errorf("Site still exists: %s", rs.Primary.ID) + } + } + } + return nil + } +} diff --git a/ec/core/schema_env.go b/ec/core/schema_env.go new file mode 100644 index 0000000..55135ee --- /dev/null +++ b/ec/core/schema_env.go @@ -0,0 +1,63 @@ +package core + +// Code generated by schema-gen. DO NOT EDIT. + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func envSchema() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Description: "Name is the name of the environment variable.", + Required: true, + }, + "value": { + Type: schema.TypeString, + Description: "Value is the value of the environment variable.", + Optional: true, + }, + "value_from": { + Type: schema.TypeList, + Description: "ValueFrom is the source for the environment variable's value.", + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "config_file_key_ref": { + Type: schema.TypeList, + Description: "ConfigFileKeyRef select the configuration file.", + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Description: "Name is the name of the configuration file.", + Required: true, + }, + }, + }, + }, + "field_ref": { + Type: schema.TypeList, + Description: "FieldRef selects the field of the pod. Supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, metadata.armadaName, metadata.regionName, metadata.regionTypeName, metadata.siteName, metadata.imageBranch, metadata.imageName, metadata.imageTag, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs.", + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "api_version": { + Type: schema.TypeString, + Optional: true, + }, + "field_path": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + }, + }, + }, + } +} diff --git a/ec/armada/schema_region.go b/ec/core/schema_region.go similarity index 99% rename from ec/armada/schema_region.go rename to ec/core/schema_region.go index 8511283..990d026 100644 --- a/ec/armada/schema_region.go +++ b/ec/core/schema_region.go @@ -1,4 +1,4 @@ -package armada +package core // Code generated by schema-gen. DO NOT EDIT. diff --git a/ec/armada/schema_resources.go b/ec/core/schema_resources.go similarity index 96% rename from ec/armada/schema_resources.go rename to ec/core/schema_resources.go index 7781086..7c6d116 100644 --- a/ec/armada/schema_resources.go +++ b/ec/core/schema_resources.go @@ -1,4 +1,4 @@ -package armada +package core // Code generated by schema-gen. DO NOT EDIT. diff --git a/ec/armada/schema_site.go b/ec/core/schema_site.go similarity index 99% rename from ec/armada/schema_site.go rename to ec/core/schema_site.go index e426414..5431efd 100644 --- a/ec/armada/schema_site.go +++ b/ec/core/schema_site.go @@ -1,4 +1,4 @@ -package armada +package core // Code generated by schema-gen. DO NOT EDIT. diff --git a/ec/ec.go b/ec/ec.go index 339420c..5133566 100644 --- a/ec/ec.go +++ b/ec/ec.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/nitrado/tfconv" - "gitlab.com/nitrado/b2b/ec/armada/pkg/apiclient/clientset" + "gitlab.com/nitrado/b2b/ec/core/pkg/apiclient/clientset" "k8s.io/apimachinery/pkg/api/resource" ) diff --git a/ec/provider/provider.go b/ec/provider/provider.go index eb49bda..343dc43 100644 --- a/ec/provider/provider.go +++ b/ec/provider/provider.go @@ -10,8 +10,8 @@ import ( "github.com/nitrado/terraform-provider-ec/ec/armada" "github.com/nitrado/terraform-provider-ec/ec/container" "github.com/nitrado/terraform-provider-ec/ec/core" - "gitlab.com/nitrado/b2b/ec/armada/pkg/apiclient/clientset" - "gitlab.com/nitrado/b2b/ec/armada/pkg/apiclient/rest" + "gitlab.com/nitrado/b2b/ec/core/pkg/apiclient/clientset" + "gitlab.com/nitrado/b2b/ec/core/pkg/apiclient/rest" "golang.org/x/oauth2" "golang.org/x/oauth2/clientcredentials" ) @@ -58,32 +58,32 @@ func Provider() *schema.Provider { }, }, DataSourcesMap: map[string]*schema.Resource{ - "ec_armada_site": armada.DataSourceArmadaSite(), - "ec_armada_site_v1": armada.DataSourceArmadaSite(), - "ec_armada_region": armada.DataSourceArmadaRegion(), - "ec_armada_region_v1": armada.DataSourceArmadaRegion(), - "ec_armada_armada": armada.DataSourceArmadaArmada(), - "ec_armada_armada_v1": armada.DataSourceArmadaArmada(), - "ec_armada_armadaset": armada.DataSourceArmadaArmadaSet(), - "ec_armada_armadaset_v1": armada.DataSourceArmadaArmadaSet(), - "ec_container_branch": container.DataSourceContainerBranch(), - "ec_container_branch_v1": container.DataSourceContainerBranch(), - "ec_core_environment": core.DataSourceCoreEnvironment(), - "ec_core_environment_v1": core.DataSourceCoreEnvironment(), + "ec_armada_armada": armada.DataSourceArmada(), + "ec_armada_armada_v1": armada.DataSourceArmada(), + "ec_armada_armadaset": armada.DataSourceArmadaSet(), + "ec_armada_armadaset_v1": armada.DataSourceArmadaSet(), + "ec_container_branch": container.DataSourceBranch(), + "ec_container_branch_v1": container.DataSourceBranch(), + "ec_core_environment": core.DataSourceEnvironment(), + "ec_core_environment_v1": core.DataSourceEnvironment(), + "ec_core_site": core.DataSourceSite(), + "ec_core_site_v1": core.DataSourceSite(), + "ec_core_region": core.DataSourceRegion(), + "ec_core_region_v1": core.DataSourceRegion(), }, ResourcesMap: map[string]*schema.Resource{ - "ec_armada_site": armada.ResourceArmadaSite(), - "ec_armada_site_v1": armada.ResourceArmadaSite(), - "ec_armada_region": armada.ResourceArmadaRegion(), - "ec_armada_region_v1": armada.ResourceArmadaRegion(), - "ec_armada_armada": armada.ResourceArmadaArmada(), - "ec_armada_armada_v1": armada.ResourceArmadaArmada(), - "ec_armada_armadaset": armada.ResourceArmadaArmadaSet(), - "ec_armada_armadaset_v1": armada.ResourceArmadaArmadaSet(), - "ec_container_branch": container.ResourceContainerBranch(), - "ec_container_branch_v1": container.ResourceContainerBranch(), - "ec_core_environment": core.ResourceCoreEnvironment(), - "ec_core_environment_v1": core.ResourceCoreEnvironment(), + "ec_armada_armada": armada.ResourceArmada(), + "ec_armada_armada_v1": armada.ResourceArmada(), + "ec_armada_armadaset": armada.ResourceArmadaSet(), + "ec_armada_armadaset_v1": armada.ResourceArmadaSet(), + "ec_container_branch": container.ResourceBranch(), + "ec_container_branch_v1": container.ResourceBranch(), + "ec_core_environment": core.ResourceEnvironment(), + "ec_core_environment_v1": core.ResourceEnvironment(), + "ec_core_site": core.ResourceSite(), + "ec_core_site_v1": core.ResourceSite(), + "ec_core_region": core.ResourceRegion(), + "ec_core_region_v1": core.ResourceRegion(), }, } diff --git a/ec/provider/providertest/provider.go b/ec/provider/providertest/provider.go index df10a40..99abcac 100644 --- a/ec/provider/providertest/provider.go +++ b/ec/provider/providertest/provider.go @@ -9,8 +9,8 @@ import ( "github.com/nitrado/terraform-provider-ec/ec/provider" "github.com/stretchr/testify/require" "gitlab.com/nitrado/b2b/ec/apicore/runtime" - "gitlab.com/nitrado/b2b/ec/armada/pkg/apiclient/clientset" - "gitlab.com/nitrado/b2b/ec/armada/pkg/apiclient/fake" + "gitlab.com/nitrado/b2b/ec/core/pkg/apiclient/clientset" + "gitlab.com/nitrado/b2b/ec/core/pkg/apiclient/fake" ) // SetupProviderFactories returns a configured test terraform provider. diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 5c5f82e..72efdf6 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -12,7 +12,7 @@ provider "ec" { host = "" } -resource "ec_armada_site" "test" { +resource "ec_core_site" "test" { metadata { name = "test" } diff --git a/examples/resources/ec_armada_site/resource.tf b/examples/resources/ec_core_site/resource.tf similarity index 87% rename from examples/resources/ec_armada_site/resource.tf rename to examples/resources/ec_core_site/resource.tf index f109c99..c09c3d4 100644 --- a/examples/resources/ec_armada_site/resource.tf +++ b/examples/resources/ec_core_site/resource.tf @@ -1,4 +1,4 @@ -resource "ec_armada_site" "test" { +resource "ec_core_site" "test" { metadata { name = "test" } diff --git a/examples/resources/ec_armada_site_v1/resource.tf b/examples/resources/ec_core_site_v1/resource.tf similarity index 86% rename from examples/resources/ec_armada_site_v1/resource.tf rename to examples/resources/ec_core_site_v1/resource.tf index d04c311..c09c3d4 100644 --- a/examples/resources/ec_armada_site_v1/resource.tf +++ b/examples/resources/ec_core_site_v1/resource.tf @@ -1,4 +1,4 @@ -resource "ec_armada_site_v1" "test" { +resource "ec_core_site" "test" { metadata { name = "test" } diff --git a/go.mod b/go.mod index c76d398..75a0582 100644 --- a/go.mod +++ b/go.mod @@ -8,8 +8,8 @@ require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0 github.com/nitrado/tfconv v1.0.0 github.com/stretchr/testify v1.8.4 - gitlab.com/nitrado/b2b/ec/apicore v1.1.1-0.20231111140503-06bb4562d8df - gitlab.com/nitrado/b2b/ec/armada v0.2.0 + gitlab.com/nitrado/b2b/ec/apicore v1.1.1-0.20240109095055-4a251dfe8b18 + gitlab.com/nitrado/b2b/ec/core v0.3.0-rc1 golang.org/x/oauth2 v0.14.0 k8s.io/apimachinery v0.28.4 ) diff --git a/go.sum b/go.sum index f0c97e7..9f43431 100644 --- a/go.sum +++ b/go.sum @@ -394,10 +394,10 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zclconf/go-cty v1.14.1 h1:t9fyA35fwjjUMcmL5hLER+e/rEPqrbCK1/OSE4SI9KA= github.com/zclconf/go-cty v1.14.1/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= -gitlab.com/nitrado/b2b/ec/apicore v1.1.1-0.20231111140503-06bb4562d8df h1:HYxVX/txUwuAeNhKZyqK/9SQ+2bDlXGev6oGUdEWRSM= -gitlab.com/nitrado/b2b/ec/apicore v1.1.1-0.20231111140503-06bb4562d8df/go.mod h1:V0HMIH6/0eiT10nAaM+8NoL9W43Ne6S0SmaK+KV5qAg= -gitlab.com/nitrado/b2b/ec/armada v0.2.0 h1:8OKVIj6/HyJYu6ZbHer9xHKRssEYfhQgfGTMiHhCZMQ= -gitlab.com/nitrado/b2b/ec/armada v0.2.0/go.mod h1:pK/1F4yXSWxh2jszMHAOX027Yk8jMIMsZVoiDpSdc0M= +gitlab.com/nitrado/b2b/ec/apicore v1.1.1-0.20240109095055-4a251dfe8b18 h1:H8UJxTuLTQWMvCQjCHJrbaasKABBeED54FjLKMvQoMg= +gitlab.com/nitrado/b2b/ec/apicore v1.1.1-0.20240109095055-4a251dfe8b18/go.mod h1:V0HMIH6/0eiT10nAaM+8NoL9W43Ne6S0SmaK+KV5qAg= +gitlab.com/nitrado/b2b/ec/core v0.3.0-rc1 h1:/Ba9r/zFwGAQRJU0Q1OPgSw8Rk1HlD5cHQBhTpKyJ5k= +gitlab.com/nitrado/b2b/ec/core v0.3.0-rc1/go.mod h1:+29x7pqcvs83cTWZ28ZB1ocCWC6XUfpFvNri1U3fzxM= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= diff --git a/internal/cmd/schema-gen/main.go b/internal/cmd/schema-gen/main.go index 1e31170..439bca4 100644 --- a/internal/cmd/schema-gen/main.go +++ b/internal/cmd/schema-gen/main.go @@ -5,9 +5,9 @@ import ( "io" "os" - armadav1 "gitlab.com/nitrado/b2b/ec/armada/pkg/api/armada/v1" - containerv1 "gitlab.com/nitrado/b2b/ec/armada/pkg/api/container/v1" - corev1 "gitlab.com/nitrado/b2b/ec/armada/pkg/api/core/v1" + armadav1 "gitlab.com/nitrado/b2b/ec/core/pkg/api/armada/v1" + containerv1 "gitlab.com/nitrado/b2b/ec/core/pkg/api/container/v1" + corev1 "gitlab.com/nitrado/b2b/ec/core/pkg/api/core/v1" ) type objInfo struct { @@ -20,28 +20,10 @@ type objInfo struct { var objs = []objInfo{ { Pkg: "armada", - Obj: armadav1.Resources{}, - Filename: "ec/armada/schema_resources.go", - FuncName: "resourcesSchema", - }, - { - Pkg: "armada", - Obj: armadav1.EnvVar{}, + Obj: corev1.EnvVar{}, Filename: "ec/armada/schema_env.go", FuncName: "envSchema", }, - { - Pkg: "armada", - Obj: &armadav1.Site{}, - Filename: "ec/armada/schema_site.go", - FuncName: "siteSchema", - }, - { - Pkg: "armada", - Obj: &armadav1.Region{}, - Filename: "ec/armada/schema_region.go", - FuncName: "regionSchema", - }, { Pkg: "armada", Obj: &armadav1.Armada{}, @@ -60,12 +42,36 @@ var objs = []objInfo{ Filename: "ec/container/schema_branch.go", FuncName: "branchSchema", }, + { + Pkg: "core", + Obj: corev1.Resources{}, + Filename: "ec/core/schema_resources.go", + FuncName: "resourcesSchema", + }, + { + Pkg: "core", + Obj: corev1.EnvVar{}, + Filename: "ec/core/schema_env.go", + FuncName: "envSchema", + }, { Pkg: "core", Obj: &corev1.Environment{}, Filename: "ec/core/schema_environment.go", FuncName: "environmentSchema", }, + { + Pkg: "core", + Obj: &corev1.Region{}, + Filename: "ec/core/schema_region.go", + FuncName: "regionSchema", + }, + { + Pkg: "core", + Obj: &corev1.Site{}, + Filename: "ec/core/schema_site.go", + FuncName: "siteSchema", + }, } func main() {