Skip to content

Add google_backup_dr_backup_vault datasource #8775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/12377.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-datasource
`google_backup_dr_backup_vault`
```
1 change: 1 addition & 0 deletions google-beta/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ var handwrittenDatasources = map[string]*schema.Resource{
"google_backup_dr_backup_plan_association": backupdr.DataSourceGoogleCloudBackupDRBackupPlanAssociation(),
"google_backup_dr_backup_plan": backupdr.DataSourceGoogleCloudBackupDRBackupPlan(),
"google_backup_dr_data_source": backupdr.DataSourceGoogleCloudBackupDRDataSource(),
"google_backup_dr_backup_vault": backupdr.DataSourceGoogleCloudBackupDRBackupVault(),
"google_beyondcorp_app_connection": beyondcorp.DataSourceGoogleBeyondcorpAppConnection(),
"google_beyondcorp_app_connector": beyondcorp.DataSourceGoogleBeyondcorpAppConnector(),
"google_beyondcorp_app_gateway": beyondcorp.DataSourceGoogleBeyondcorpAppGateway(),
Expand Down
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-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/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
}
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-beta/google-beta/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)
}
34 changes: 34 additions & 0 deletions website/docs/d/backup_dr_backup_vault.html.markdown
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.