Skip to content

Commit 9dee572

Browse files
Bp tf resource (#12158) (#8603)
[upstream:b685f478f17cabae12a3ba27670fdd903f3bba12] Signed-off-by: Modular Magician <[email protected]>
1 parent 23c08b7 commit 9dee572

9 files changed

+1585
-2
lines changed

.changelog/12158.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:new-resource
2+
`google_backup_dr_backup_plan`
3+
```
4+
```release-note:new-datasource
5+
`google_backup_dr_backup_plan`
6+
```

google-beta/provider/provider_mmv1_resources.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ var handwrittenDatasources = map[string]*schema.Resource{
170170
"google_apphub_application": apphub.DataSourceGoogleApphubApplication(),
171171
"google_apphub_discovered_service": apphub.DataSourceApphubDiscoveredService(),
172172
"google_backup_dr_management_server": backupdr.DataSourceGoogleCloudBackupDRService(),
173+
"google_backup_dr_backup_plan": backupdr.DataSourceGoogleCloudBackupDRBackupPlan(),
173174
"google_beyondcorp_app_connection": beyondcorp.DataSourceGoogleBeyondcorpAppConnection(),
174175
"google_beyondcorp_app_connector": beyondcorp.DataSourceGoogleBeyondcorpAppConnector(),
175176
"google_beyondcorp_app_gateway": beyondcorp.DataSourceGoogleBeyondcorpAppGateway(),
@@ -500,9 +501,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
500501
}
501502

502503
// Resources
503-
// Generated resources: 547
504+
// Generated resources: 548
504505
// Generated IAM resources: 291
505-
// Total generated resources: 838
506+
// Total generated resources: 839
506507
var generatedResources = map[string]*schema.Resource{
507508
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
508509
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
@@ -582,6 +583,7 @@ var generatedResources = map[string]*schema.Resource{
582583
"google_artifact_registry_repository_iam_member": tpgiamresource.ResourceIamMember(artifactregistry.ArtifactRegistryRepositoryIamSchema, artifactregistry.ArtifactRegistryRepositoryIamUpdaterProducer, artifactregistry.ArtifactRegistryRepositoryIdParseFunc),
583584
"google_artifact_registry_repository_iam_policy": tpgiamresource.ResourceIamPolicy(artifactregistry.ArtifactRegistryRepositoryIamSchema, artifactregistry.ArtifactRegistryRepositoryIamUpdaterProducer, artifactregistry.ArtifactRegistryRepositoryIdParseFunc),
584585
"google_artifact_registry_vpcsc_config": artifactregistry.ResourceArtifactRegistryVPCSCConfig(),
586+
"google_backup_dr_backup_plan": backupdr.ResourceBackupDRBackupPlan(),
585587
"google_backup_dr_backup_vault": backupdr.ResourceBackupDRBackupVault(),
586588
"google_backup_dr_management_server": backupdr.ResourceBackupDRManagementServer(),
587589
"google_beyondcorp_app_connection": beyondcorp.ResourceBeyondcorpAppConnection(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
package backupdr
4+
5+
import (
6+
"fmt"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
9+
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
10+
)
11+
12+
func DataSourceGoogleCloudBackupDRBackupPlan() *schema.Resource {
13+
14+
dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceBackupDRBackupPlan().Schema)
15+
// Set 'Required' schema elements
16+
tpgresource.AddRequiredFieldsToSchema(dsSchema, "backup_plan_id", "location")
17+
18+
// Set 'Optional' schema elements
19+
tpgresource.AddOptionalFieldsToSchema(dsSchema, "project")
20+
return &schema.Resource{
21+
Read: dataSourceGoogleCloudBackupDRBackupPlanRead,
22+
Schema: dsSchema,
23+
}
24+
}
25+
26+
func dataSourceGoogleCloudBackupDRBackupPlanRead(d *schema.ResourceData, meta interface{}) error {
27+
config := meta.(*transport_tpg.Config)
28+
29+
project, err := tpgresource.GetProject(d, config)
30+
if err != nil {
31+
return err
32+
}
33+
34+
location, err := tpgresource.GetLocation(d, config)
35+
if err != nil {
36+
return err
37+
}
38+
39+
backup_plan_id := d.Get("backup_plan_id").(string)
40+
41+
id := fmt.Sprintf("projects/%s/locations/%s/backupPlans/%s", project, location, backup_plan_id)
42+
d.SetId(id)
43+
err = resourceBackupDRBackupPlanRead(d, meta)
44+
if err != nil {
45+
return err
46+
}
47+
48+
if d.Id() == "" {
49+
return fmt.Errorf("%s not found", id)
50+
}
51+
52+
return nil
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
package backupdr_test
4+
5+
import (
6+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
7+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
8+
"testing"
9+
)
10+
11+
func TestAccDataSourceGoogleBackupDRBackupPlan_basic(t *testing.T) {
12+
t.Parallel()
13+
context := map[string]interface{}{
14+
"random_suffix": acctest.RandString(t, 10),
15+
}
16+
acctest.VcrTest(t, resource.TestCase{
17+
PreCheck: func() { acctest.AccTestPreCheck(t) },
18+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
19+
CheckDestroy: testAccCheckBackupDRBackupPlanDestroyProducer(t),
20+
Steps: []resource.TestStep{
21+
{
22+
Config: testAccDataSourceGoogleBackupDRBackupPlan_basic(context),
23+
Check: resource.ComposeTestCheckFunc(
24+
acctest.CheckDataSourceStateMatchesResourceState("data.google_backup_dr_backup_plan.fetch-bp", "google_backup_dr_backup_plan.test"),
25+
),
26+
},
27+
},
28+
})
29+
}
30+
31+
func testAccDataSourceGoogleBackupDRBackupPlan_basic(context map[string]interface{}) string {
32+
return acctest.Nprintf(`
33+
resource "google_backup_dr_backup_vault" "my-backup-vault-1" {
34+
location ="us-central1"
35+
backup_vault_id = "bv-%{random_suffix}"
36+
description = "This is a second backup vault built by Terraform."
37+
backup_minimum_enforced_retention_duration = "100000s"
38+
labels = {
39+
foo = "bar1"
40+
bar = "baz1"
41+
}
42+
annotations = {
43+
annotations1 = "bar1"
44+
annotations2 = "baz1"
45+
}
46+
force_update = "true"
47+
force_delete = "true"
48+
allow_missing = "true"
49+
}
50+
51+
52+
resource "google_backup_dr_backup_plan" "test" {
53+
location = "us-central1"
54+
backup_plan_id = "bp-test-%{random_suffix}"
55+
resource_type= "compute.googleapis.com/Instance"
56+
backup_vault = google_backup_dr_backup_vault.my-backup-vault-1.name
57+
depends_on=[ google_backup_dr_backup_vault.my-backup-vault-1 ]
58+
lifecycle {
59+
ignore_changes = [backup_vault]
60+
}
61+
backup_rules {
62+
rule_id = "rule-1"
63+
backup_retention_days = 5
64+
standard_schedule {
65+
recurrence_type = "HOURLY"
66+
hourly_frequency = 6
67+
time_zone = "UTC"
68+
backup_window{
69+
start_hour_of_day = 0
70+
end_hour_of_day = 24
71+
}
72+
}
73+
}
74+
}
75+
76+
data "google_backup_dr_backup_plan" "fetch-bp" {
77+
location = "us-central1"
78+
backup_plan_id="bp-test-%{random_suffix}"
79+
depends_on= [ google_backup_dr_backup_plan.test ]
80+
}
81+
`, context)
82+
}

0 commit comments

Comments
 (0)