-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[upstream:1a5e7d4d7a56f9af4d3cd8ffd25dbd82cc7201eb] Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
a0dec11
commit 3618f5b
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-datasource | ||
`google_backup_dr_backup_vault` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
google/services/backupdr/data_source_backup_dr_backup_vault.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
package backupdr | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-google/google/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" | ||
) | ||
|
||
func DataSourceGoogleCloudBackupDRBackupVault() *schema.Resource { | ||
|
||
dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceBackupDRBackupVault().Schema) | ||
|
||
tpgresource.AddRequiredFieldsToSchema(dsSchema, "backup_vault_id", "location") | ||
|
||
tpgresource.AddOptionalFieldsToSchema(dsSchema, "project") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceGoogleCloudBackupDRBackupVaultRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceGoogleCloudBackupDRBackupVaultRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*transport_tpg.Config) | ||
project, err := tpgresource.GetProject(d, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
location, err := tpgresource.GetLocation(d, config) | ||
if err != nil { | ||
return err | ||
} | ||
backup_vault_id := d.Get("backup_vault_id").(string) | ||
id := fmt.Sprintf("projects/%s/locations/%s/backupVaults/%s", project, location, backup_vault_id) | ||
d.SetId(id) | ||
err = resourceBackupDRBackupVaultRead(d, meta) | ||
if err != nil { | ||
return err | ||
} | ||
if d.Id() == "" { | ||
return fmt.Errorf("%s not found", id) | ||
} | ||
|
||
return nil | ||
} |
53 changes: 53 additions & 0 deletions
53
google/services/backupdr/data_source_backup_dr_backup_vault_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
package backupdr_test | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
"testing" | ||
) | ||
|
||
func TestAccDataSourceGoogleBackupDRBackupVault_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
random_suffix := acctest.RandString(t, 10) | ||
context := map[string]interface{}{ | ||
"random_suffix": random_suffix, | ||
} | ||
id := "tf-test-bv-" + random_suffix | ||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckBackupDRBackupVaultDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleBackupDRBackupVault_basic(context), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.google_backup_dr_backup_vault.fetch-bv", "backup_vault_id", id), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceGoogleBackupDRBackupVault_basic(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
resource "google_backup_dr_backup_vault" "test-bv" { | ||
location = "us-central1" | ||
backup_vault_id = "tf-test-bv-%{random_suffix}" | ||
description = "This is a a backup vault built by Terraform." | ||
backup_minimum_enforced_retention_duration = "100000s" | ||
force_update = "true" | ||
force_delete = "true" | ||
allow_missing = "true" | ||
ignore_backup_plan_references = "false" | ||
ignore_inactive_datasources = "false" | ||
} | ||
data "google_backup_dr_backup_vault" "fetch-bv" { | ||
location = "us-central1" | ||
backup_vault_id = google_backup_dr_backup_vault.test-bv.backup_vault_id | ||
} | ||
`, context) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
subcategory: "Backup and DR BackupVault" | ||
description: |- | ||
Get information about a Backupdr BackupVault. | ||
--- | ||
|
||
# google_backup_dr_backup_vault | ||
|
||
A Backup and DRBackupVault. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "google_backup_dr_backup_vault" "my-backup-vault" { | ||
location = "us-central1" | ||
backup_vault_id="bv-1" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `location` - (Required) The location in which the Backup Vault resource belongs. | ||
* `backup_vault_id` - (Required) The id of Backup Vault resource. | ||
|
||
- - - | ||
|
||
* `project` - (Optional) The project in which the resource belongs. If it | ||
is not provided, the provider project is used. | ||
|
||
## Attributes Reference | ||
|
||
See [google_backup_dr_backup_vault](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/backup_dr_backup_vault) resource for details of the available attributes. |