Skip to content

Commit

Permalink
OAS-5111 | fix resource details
Browse files Browse the repository at this point in the history
  • Loading branch information
lakhansamani committed Sep 15, 2022
1 parent 6d86255 commit 9a3a179
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 47 deletions.
2 changes: 1 addition & 1 deletion docs/guides/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ resource "oasis_deployment" "my_oneshard_deployment" {
}
version {
db_version = "3.8.7"
db_version = "3.8.6"
}
configuration {
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ resource "oasis_deployment" "my_oneshard_deployment" {
}
version {
db_version = "3.8.7"
db_version = "3.8.6"
}
configuration {
Expand Down
28 changes: 14 additions & 14 deletions docs/resources/multi_region_backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -18,7 +18,7 @@ terraform {
required_providers {
oasis = {
source = "arangodb-managed/oasis"
version = ">=2.1.0"
version = ">2.1.4"
}
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
```
Expand All @@ -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


4 changes: 2 additions & 2 deletions docs/resources/private_endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ resource "oasis_deployment" "my_aks_oneshard_deployment" {
}
version {
db_version = "3.8.7"
db_version = "3.8.6"
}
configuration {
Expand Down Expand Up @@ -82,7 +82,7 @@ resource "oasis_deployment" "my_aws_oneshard_deployment" {
}
version {
db_version = "3.8.7"
db_version = "3.8.6"
}
configuration {
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/oasis_backup/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/oasis_deployment/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ resource "oasis_deployment" "my_oneshard_deployment" {
}

version {
db_version = "3.8.7"
db_version = "3.8.6"
}

configuration {
Expand Down
6 changes: 3 additions & 3 deletions examples/resources/oasis_multi_region_backup/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
oasis = {
source = "arangodb-managed/oasis"
version = ">=2.1.0"
version = ">2.1.4"
}
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions examples/resources/oasis_private_endpoint/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ resource "oasis_deployment" "my_aks_oneshard_deployment" {
}

version {
db_version = "3.8.7"
db_version = "3.8.6"
}

configuration {
Expand Down Expand Up @@ -67,7 +67,7 @@ resource "oasis_deployment" "my_aws_oneshard_deployment" {
}

version {
db_version = "3.8.7"
db_version = "3.8.6"
}

configuration {
Expand Down
1 change: 1 addition & 0 deletions internal/resource_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions internal/resource_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions internal/resource_multi_region_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,59 +40,59 @@ 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,
DeleteContext: resourceBackupDelete,
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",
},
},
}
Expand Down
35 changes: 29 additions & 6 deletions internal/resource_multi_region_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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"),
Expand All @@ -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
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion templates/guides/getting-started.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ resource "oasis_deployment" "my_oneshard_deployment" {
}

version {
db_version = "3.8.7"
db_version = "3.8.6"
}

configuration {
Expand Down

0 comments on commit 9a3a179

Please sign in to comment.