diff --git a/docs/resources/backup_storage_location.md b/docs/resources/backup_storage_location.md index eb3e6a28..e9e1a77a 100644 --- a/docs/resources/backup_storage_location.md +++ b/docs/resources/backup_storage_location.md @@ -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" @@ -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 diff --git a/examples/resources/spectrocloud_backup_storage_location/resource.tf b/examples/resources/spectrocloud_backup_storage_location/resource.tf index 3acad8b1..2598ae95 100644 --- a/examples/resources/spectrocloud_backup_storage_location/resource.tf +++ b/examples/resources/spectrocloud_backup_storage_location/resource.tf @@ -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" - } -} \ No newline at end of file +#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" +# } +#} \ No newline at end of file diff --git a/spectrocloud/data_source_backup_storage_location.go b/spectrocloud/data_source_backup_storage_location.go index b5f809d5..ac775256 100644 --- a/spectrocloud/data_source_backup_storage_location.go +++ b/spectrocloud/data_source_backup_storage_location.go @@ -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 diff --git a/spectrocloud/resource_backup_storage_location.go b/spectrocloud/resource_backup_storage_location.go index 287127cb..d78c2813 100644 --- a/spectrocloud/resource_backup_storage_location.go +++ b/spectrocloud/resource_backup_storage_location.go @@ -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, @@ -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) @@ -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()) @@ -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) @@ -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 { diff --git a/templates/resources/backup_storage_location.md.tmpl b/templates/resources/backup_storage_location.md.tmpl index e67314bd..002141ac 100644 --- a/templates/resources/backup_storage_location.md.tmpl +++ b/templates/resources/backup_storage_location.md.tmpl @@ -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"