Skip to content

Commit

Permalink
PLT-1422:Added tenant context for back up storage location (#523)
Browse files Browse the repository at this point in the history
* PLT-1422:Added tenanat context for back up storage location

* fix reviewble

* removed context in data sourrce
  • Loading branch information
SivaanandM authored Oct 18, 2024
1 parent fe86180 commit 72dc10d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
2 changes: 2 additions & 0 deletions docs/resources/backup_storage_location.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ description: |-
```terraform
resource "spectrocloud_backup_storage_location" "bsl1" {
name = "dev-backup-s3"
context = "tenant"
is_default = false
region = "us-east-2"
bucket_name = "dev-backup"
Expand Down Expand Up @@ -59,6 +60,7 @@ resource "spectrocloud_backup_storage_location" "bsl2" {
### Optional

- `ca_cert` (String) An optional CA certificate used for SSL connections to ensure secure communication with the storage provider.
- `context` (String) The context of the backup storage location. Allowed values are `project` or `tenant`. Default value is `project`. If the `project` context is specified, the project name will sourced from the provider configuration parameter [`project_name`](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs#schema).
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

### Read-Only
Expand Down
43 changes: 22 additions & 21 deletions examples/resources/spectrocloud_backup_storage_location/resource.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
resource "spectrocloud_backup_storage_location" "bsl1" {
name = "dev-backup-s3"
name = "aaa-project-dev-1"
context = "project"
is_default = false
region = "us-east-2"
bucket_name = "dev-backup"
region = "us-east-1"
bucket_name = "project-backup-2"
s3 {
credential_type = var.credential_type
access_key = var.aws_access_key
secret_key = var.aws_secret_key
credential_type = "secret"
access_key = "access_key"
secret_key = "secret_key"
s3_force_path_style = false

#s3_url = "http://10.90.78.23"
s3_url = "http://10.90.78.23"
}
}

resource "spectrocloud_backup_storage_location" "bsl2" {
name = "prod-backup-s3"
is_default = false
region = "us-east-2"
bucket_name = "prod-backup"
s3 {
credential_type = var.credential_type
arn = var.arn
external_id = var.external_id
s3_force_path_style = false
#s3_url = "http://10.90.78.23"
}
}
#resource "spectrocloud_backup_storage_location" "bsl2" {
# name = "tenant-dev-1"
# context = "tenant"
# is_default = false
# region = "us-east-2"
# bucket_name = "tenant-backup-2"
# s3 {
# credential_type = "sts"
# arn = "arn_role"
# external_id = "external_id"
# s3_force_path_style = false
# #s3_url = "http://10.90.78.23"
# }
#}
2 changes: 1 addition & 1 deletion spectrocloud/data_source_backup_storage_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func dataSourceBackupStorageLocation() *schema.Resource {
}

func dataSourceBackupStorageLocationRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := getV1ClientWithResourceContext(m, "")
c := getV1ClientWithResourceContext(m, "project")

// Warning or errors can be collected in a slice type
var diags diag.Diagnostics
Expand Down
21 changes: 17 additions & 4 deletions spectrocloud/resource_backup_storage_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ func resourceBackupStorageLocation() *schema.Resource {
ForceNew: true,
Description: "The name of the backup storage location. This is a unique identifier for the backup location.",
},
"context": {
Type: schema.TypeString,
Optional: true,
Default: "project",
ValidateFunc: validation.StringInSlice([]string{"project", "tenant"}, false),
Description: "The context of the backup storage location. Allowed values are `project` or `tenant`. " +
"Default value is `project`. " + PROJECT_NAME_NUANCE,
},
"is_default": {
Type: schema.TypeBool,
Required: true,
Expand Down Expand Up @@ -103,10 +111,12 @@ func resourceBackupStorageLocation() *schema.Resource {
}

func resourceBackupStorageLocationCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := getV1ClientWithResourceContext(m, "")
assetContext := d.Get("context").(string)
c := getV1ClientWithResourceContext(m, assetContext)
var diags diag.Diagnostics

bsl := toBackupStorageLocation(d)

uid, err := c.CreateS3BackupStorageLocation(bsl)
if err != nil {
return diag.FromErr(err)
Expand All @@ -117,7 +127,8 @@ func resourceBackupStorageLocationCreate(ctx context.Context, d *schema.Resource
}

func resourceBackupStorageLocationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := getV1ClientWithResourceContext(m, "")
assetContext := d.Get("context").(string)
c := getV1ClientWithResourceContext(m, assetContext)
var diags diag.Diagnostics

bsl, err := c.GetBackupStorageLocation(d.Id())
Expand Down Expand Up @@ -186,7 +197,8 @@ func resourceBackupStorageLocationRead(ctx context.Context, d *schema.ResourceDa
}

func resourceBackupStorageLocationUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := getV1ClientWithResourceContext(m, "")
assetContext := d.Get("context").(string)
c := getV1ClientWithResourceContext(m, assetContext)
var diags diag.Diagnostics

bsl := toBackupStorageLocation(d)
Expand All @@ -199,7 +211,8 @@ func resourceBackupStorageLocationUpdate(ctx context.Context, d *schema.Resource
}

func resourceBackupStorageLocationDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := getV1ClientWithResourceContext(m, "")
assetContext := d.Get("context").(string)
c := getV1ClientWithResourceContext(m, assetContext)
var diags diag.Diagnostics
err := c.DeleteS3BackupStorageLocation(d.Id())
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions templates/resources/backup_storage_location.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ description: |-
```terraform
resource "spectrocloud_backup_storage_location" "bsl1" {
name = "dev-backup-s3"
context = "tenant"
is_default = false
region = "us-east-2"
bucket_name = "dev-backup"
Expand Down

0 comments on commit 72dc10d

Please sign in to comment.