From 9a3a17950a817279a92ab2e621950b70fd87704b Mon Sep 17 00:00:00 2001 From: Lakhan Samani Date: Thu, 15 Sep 2022 12:57:56 +0530 Subject: [PATCH] OAS-5111 | fix resource details --- docs/guides/getting-started.md | 2 +- docs/resources/backup.md | 2 +- docs/resources/deployment.md | 2 +- docs/resources/multi_region_backup.md | 28 +++++++-------- docs/resources/private_endpoint.md | 4 +-- examples/resources/oasis_backup/resource.tf | 2 +- .../resources/oasis_deployment/resource.tf | 2 +- .../oasis_multi_region_backup/resource.tf | 6 ++-- .../oasis_private_endpoint/resource.tf | 4 +-- internal/resource_backup.go | 1 + internal/resource_backup_test.go | 8 ++--- internal/resource_multi_region_backup.go | 20 +++++------ internal/resource_multi_region_backup_test.go | 35 +++++++++++++++---- templates/guides/getting-started.md.tmpl | 2 +- 14 files changed, 71 insertions(+), 47 deletions(-) diff --git a/docs/guides/getting-started.md b/docs/guides/getting-started.md index 2bc02db2..3ccd0b60 100644 --- a/docs/guides/getting-started.md +++ b/docs/guides/getting-started.md @@ -62,7 +62,7 @@ resource "oasis_deployment" "my_oneshard_deployment" { } version { - db_version = "3.8.7" + db_version = "3.8.6" } configuration { diff --git a/docs/resources/backup.md b/docs/resources/backup.md index 506e624f..a0e80653 100644 --- a/docs/resources/backup.md +++ b/docs/resources/backup.md @@ -44,7 +44,7 @@ resource "oasis_deployment" "my_oneshard_deployment" { region = "gcp-europe-west4" } version { - db_version = "3.8.7" + db_version = "3.8.6" } configuration { model = "oneshard" diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md index a3371836..6a30af1c 100644 --- a/docs/resources/deployment.md +++ b/docs/resources/deployment.md @@ -46,7 +46,7 @@ resource "oasis_deployment" "my_oneshard_deployment" { } version { - db_version = "3.8.7" + db_version = "3.8.6" } configuration { diff --git a/docs/resources/multi_region_backup.md b/docs/resources/multi_region_backup.md index 0dc9db4a..15ca860b 100644 --- a/docs/resources/multi_region_backup.md +++ b/docs/resources/multi_region_backup.md @@ -3,12 +3,12 @@ page_title: "oasis_multi_region_backup Resource - terraform-provider-oasis" subcategory: "" description: |- - Oasis Backup Resource + Oasis Multi Region Backup Resource --- # oasis_multi_region_backup (Resource) -Oasis Backup Resource +Oasis Multi Region Backup Resource ## Example Usage @@ -18,7 +18,7 @@ terraform { required_providers { oasis = { source = "arangodb-managed/oasis" - version = ">=2.1.0" + version = ">2.1.4" } } } @@ -44,7 +44,7 @@ resource "oasis_deployment" "my_oneshard_deployment" { region = "gcp-europe-west4" } version { - db_version = "3.8.7" + db_version = "3.8.6" } security { disable_foxx_authentication = false @@ -74,7 +74,7 @@ resource "oasis_backup" "backup" { // Create Multi Region Backup resource "oasis_multi_region_backup" "backup" { - source_backup_id = oasis_backup.backup.id // Existing backup ID that is already uploaded + source_backup_id = oasis_backup.backup.id // Existing backup ID region_id = "gcp-us-central1" // Oasis region identifier, which is other than the deployment region } ``` @@ -84,18 +84,18 @@ resource "oasis_multi_region_backup" "backup" { ### Optional -- `region_id` (String) Oasis Backup Resource Region Identifier -- `source_backup_id` (String) Oasis Backup Resource Region Identifier +- `region_id` (String) Oasis Multi Region Backup Resource Region Identifier +- `source_backup_id` (String) Oasis Multi Region Backup Resource Region Identifier ### Read-Only -- `auto_deleted_at` (Number) Oasis Backup Resource Backup Auto Delete At field, generated based on source backup -- `backup_policy_id` (String) Oasis Backup Resource Backup Policy ID field, generated based on source backup -- `deployment_id` (String) Oasis Backup Resource Backup Deployment ID field, generated based on source backup -- `description` (String) Oasis Backup Resource Backup Description field, generated based on source backup +- `auto_deleted_at` (Number) Oasis Multi Region Backup Resource Backup Auto Delete At field, generated based on source backup +- `backup_policy_id` (String) Oasis Multi Region Backup Resource Backup Policy ID field, generated based on source backup +- `deployment_id` (String) Oasis Multi Region Backup Resource Backup Deployment ID field, generated based on source backup +- `description` (String) Oasis Multi Region Backup Resource Backup Description field, generated based on source backup - `id` (String) The ID of this resource. -- `name` (String) Oasis Backup Resource Backup Name field, generated based on source backup -- `upload` (Boolean) Oasis Backup Resource Backup Upload field, generated based on source backup -- `url` (String) Oasis Backup Resource Backup URL field, generated based on source backup +- `name` (String) Oasis Multi Region Backup Resource Backup Name field, generated based on source backup +- `upload` (Boolean) Oasis Multi Region Backup Resource Backup Upload field, generated based on source backup +- `url` (String) Oasis Multi Region Backup Resource Backup URL field, generated based on source backup diff --git a/docs/resources/private_endpoint.md b/docs/resources/private_endpoint.md index 8207b64c..c437fdb6 100644 --- a/docs/resources/private_endpoint.md +++ b/docs/resources/private_endpoint.md @@ -46,7 +46,7 @@ resource "oasis_deployment" "my_aks_oneshard_deployment" { } version { - db_version = "3.8.7" + db_version = "3.8.6" } configuration { @@ -82,7 +82,7 @@ resource "oasis_deployment" "my_aws_oneshard_deployment" { } version { - db_version = "3.8.7" + db_version = "3.8.6" } configuration { diff --git a/examples/resources/oasis_backup/resource.tf b/examples/resources/oasis_backup/resource.tf index b7eb2026..0fd37df6 100644 --- a/examples/resources/oasis_backup/resource.tf +++ b/examples/resources/oasis_backup/resource.tf @@ -29,7 +29,7 @@ resource "oasis_deployment" "my_oneshard_deployment" { region = "gcp-europe-west4" } version { - db_version = "3.8.7" + db_version = "3.8.6" } configuration { model = "oneshard" diff --git a/examples/resources/oasis_deployment/resource.tf b/examples/resources/oasis_deployment/resource.tf index 21d566ea..06b42408 100644 --- a/examples/resources/oasis_deployment/resource.tf +++ b/examples/resources/oasis_deployment/resource.tf @@ -31,7 +31,7 @@ resource "oasis_deployment" "my_oneshard_deployment" { } version { - db_version = "3.8.7" + db_version = "3.8.6" } configuration { diff --git a/examples/resources/oasis_multi_region_backup/resource.tf b/examples/resources/oasis_multi_region_backup/resource.tf index 9f40f0c4..c5464707 100644 --- a/examples/resources/oasis_multi_region_backup/resource.tf +++ b/examples/resources/oasis_multi_region_backup/resource.tf @@ -3,7 +3,7 @@ terraform { required_providers { oasis = { source = "arangodb-managed/oasis" - version = ">=2.1.0" + version = ">2.1.4" } } } @@ -29,7 +29,7 @@ resource "oasis_deployment" "my_oneshard_deployment" { region = "gcp-europe-west4" } version { - db_version = "3.8.7" + db_version = "3.8.6" } security { disable_foxx_authentication = false @@ -59,6 +59,6 @@ resource "oasis_backup" "backup" { // Create Multi Region Backup resource "oasis_multi_region_backup" "backup" { - source_backup_id = oasis_backup.backup.id // Existing backup ID that is already uploaded + source_backup_id = oasis_backup.backup.id // Existing backup ID region_id = "gcp-us-central1" // Oasis region identifier, which is other than the deployment region } \ No newline at end of file diff --git a/examples/resources/oasis_private_endpoint/resource.tf b/examples/resources/oasis_private_endpoint/resource.tf index 7fcfee16..af66b9fd 100644 --- a/examples/resources/oasis_private_endpoint/resource.tf +++ b/examples/resources/oasis_private_endpoint/resource.tf @@ -31,7 +31,7 @@ resource "oasis_deployment" "my_aks_oneshard_deployment" { } version { - db_version = "3.8.7" + db_version = "3.8.6" } configuration { @@ -67,7 +67,7 @@ resource "oasis_deployment" "my_aws_oneshard_deployment" { } version { - db_version = "3.8.7" + db_version = "3.8.6" } configuration { diff --git a/internal/resource_backup.go b/internal/resource_backup.go index e5eb301e..ce1626c9 100644 --- a/internal/resource_backup.go +++ b/internal/resource_backup.go @@ -90,6 +90,7 @@ func resourceBackup() *schema.Resource { Type: schema.TypeString, Description: "Oasis Backup Resource Region Identifier", Optional: true, + Computed: true, }, backupAutoDeleteAtFieldName: { Type: schema.TypeInt, diff --git a/internal/resource_backup_test.go b/internal/resource_backup_test.go index e134901b..a984513a 100644 --- a/internal/resource_backup_test.go +++ b/internal/resource_backup_test.go @@ -88,13 +88,13 @@ func TestAccResourceBackup(t *testing.T) { func testBackupConfig(project, res, name string) string { return fmt.Sprintf(`resource "oasis_deployment" "my_oneshard_deployment" { terms_and_conditions_accepted = "true" - project = "%s" + project = "%s" name = "oasis_test_dep_tf" location { region = "gcp-europe-west4" } version { - db_version = "3.8.7" + db_version = "3.8.6" } security { disable_foxx_authentication = false @@ -127,13 +127,13 @@ resource "oasis_backup" "%s" { func testBackupConfigIncomplete(project, res, name string) string { return fmt.Sprintf(`resource "oasis_deployment" "my_oneshard_deployment" { terms_and_conditions_accepted = "true" - project = "%s" + project = "%s" name = "oasis_test_dep_tf" location { region = "gcp-europe-west4" } version { - db_version = "3.8.7" + db_version = "3.8.6" } security { disable_foxx_authentication = false diff --git a/internal/resource_multi_region_backup.go b/internal/resource_multi_region_backup.go index 67c46ac9..f0bbbd8a 100644 --- a/internal/resource_multi_region_backup.go +++ b/internal/resource_multi_region_backup.go @@ -40,7 +40,7 @@ const ( // resourceMultiRegionBackup defines a Multi Region Backup Oasis resource. func resourceMultiRegionBackup() *schema.Resource { return &schema.Resource{ - Description: "Oasis Backup Resource", + Description: "Oasis Multi Region Backup Resource", CreateContext: resourceMultiRegionBackupCreate, ReadContext: resourceBackupRead, UpdateContext: resourceBackupUpdate, @@ -48,51 +48,51 @@ func resourceMultiRegionBackup() *schema.Resource { Schema: map[string]*schema.Schema{ backupSourceBackupIDFieldName: { Type: schema.TypeString, - Description: "Oasis Backup Resource Region Identifier", + Description: "Oasis Multi Region Backup Resource Region Identifier", Optional: true, }, backupRegionIDFieldName: { Type: schema.TypeString, - Description: "Oasis Backup Resource Region Identifier", + Description: "Oasis Multi Region Backup Resource Region Identifier", Optional: true, }, // backup fields used to return the backup information backupNameFieldName: { Type: schema.TypeString, - Description: "Oasis Backup Resource Backup Name field, generated based on source backup", + Description: "Oasis Multi Region Backup Resource Backup Name field, generated based on source backup", Computed: true, }, backupDescriptionFieldName: { Type: schema.TypeString, - Description: "Oasis Backup Resource Backup Description field, generated based on source backup", + Description: "Oasis Multi Region Backup Resource Backup Description field, generated based on source backup", Computed: true, }, backupUploadFieldName: { Type: schema.TypeBool, - Description: "Oasis Backup Resource Backup Upload field, generated based on source backup", + Description: "Oasis Multi Region Backup Resource Backup Upload field, generated based on source backup", Computed: true, }, backupDeploymentIDFieldName: { Type: schema.TypeString, - Description: "Oasis Backup Resource Backup Deployment ID field, generated based on source backup", + Description: "Oasis Multi Region Backup Resource Backup Deployment ID field, generated based on source backup", Computed: true, }, backupURLFieldName: { Type: schema.TypeString, - Description: "Oasis Backup Resource Backup URL field, generated based on source backup", + Description: "Oasis Multi Region Backup Resource Backup URL field, generated based on source backup", Computed: true, }, backupPolicyIDFieldName: { Type: schema.TypeString, - Description: "Oasis Backup Resource Backup Policy ID field, generated based on source backup", + Description: "Oasis Multi Region Backup Resource Backup Policy ID field, generated based on source backup", Computed: true, }, backupAutoDeleteAtFieldName: { Type: schema.TypeInt, Computed: true, - Description: "Oasis Backup Resource Backup Auto Delete At field, generated based on source backup", + Description: "Oasis Multi Region Backup Resource Backup Auto Delete At field, generated based on source backup", }, }, } diff --git a/internal/resource_multi_region_backup_test.go b/internal/resource_multi_region_backup_test.go index df16d8b7..6d007de5 100644 --- a/internal/resource_multi_region_backup_test.go +++ b/internal/resource_multi_region_backup_test.go @@ -27,8 +27,11 @@ import ( "regexp" "testing" + backup "github.com/arangodb-managed/apis/backup/v1" + common "github.com/arangodb-managed/apis/common/v1" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/stretchr/testify/require" ) @@ -50,16 +53,14 @@ func TestAccResourceMultiRegionBackup(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProviderFactories: testProviderFactories, - CheckDestroy: testAccCheckDestroyBackup, + CheckDestroy: testAccCheckDestroyMultiRegionBackup, Steps: []resource.TestStep{ { Config: testMultiRegionBackupConfig(projectID, resourceName, ""), ExpectError: regexp.MustCompile("Region identifier required"), }, { - ImportState: true, - ImportStateVerify: true, - Config: testMultiRegionBackupConfig(projectID, resourceName, regionID), + Config: testMultiRegionBackupConfig(projectID, resourceName, regionID), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("oasis_deployment.my_oneshard_deployment", deplNameFieldName, "oasis_multi_region_deployment"), resource.TestCheckResourceAttr("oasis_backup.backup", backupNameFieldName, "oasis_backup"), @@ -75,13 +76,13 @@ func testMultiRegionBackupConfig(project, backupResource, regionID string) strin return fmt.Sprintf(` resource "oasis_deployment" "my_oneshard_deployment" { terms_and_conditions_accepted = "true" - project = "%s" + project = "%s" name = "oasis_multi_region_deployment" location { region = "gcp-europe-west4" } version { - db_version = "3.8.7" + db_version = "3.8.6" } security { disable_foxx_authentication = false @@ -115,3 +116,25 @@ func testMultiRegionBackupConfig(project, backupResource, regionID string) strin } `, project, backupResource, regionID) } + +// testAccCheckDestroyMultiRegionBackup verifies the Terraform oasis_multi_region_backup resource cleanup. +func testAccCheckDestroyMultiRegionBackup(s *terraform.State) error { + client := testAccProvider.Meta().(*Client) + if err := client.Connect(); err != nil { + client.log.Error().Err(err).Msg("Failed to connect to api") + return err + } + backupc := backup.NewBackupServiceClient(client.conn) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "oasis_backup" && rs.Type != "oasis_multi_region_backup" { + continue + } + + if _, err := backupc.GetBackup(client.ctxWithToken, &common.IDOptions{Id: rs.Primary.ID}); !common.IsNotFound(err) { + return fmt.Errorf("backup still present") + } + } + + return nil +} diff --git a/templates/guides/getting-started.md.tmpl b/templates/guides/getting-started.md.tmpl index 2bc02db2..3ccd0b60 100644 --- a/templates/guides/getting-started.md.tmpl +++ b/templates/guides/getting-started.md.tmpl @@ -62,7 +62,7 @@ resource "oasis_deployment" "my_oneshard_deployment" { } version { - db_version = "3.8.7" + db_version = "3.8.6" } configuration {