Skip to content

Commit 39477f1

Browse files
linting changes (#15213)
1 parent c814bf3 commit 39477f1

6 files changed

+121
-40
lines changed

mmv1/third_party/terraform/services/backupdr/data_source_backup_dr_backup_plan_association.go

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,53 @@ func DataSourceGoogleCloudBackupDRBackupPlanAssociations() *schema.Resource {
9090
Type: schema.TypeString,
9191
Computed: true,
9292
},
93+
"data_source": {
94+
Type: schema.TypeString,
95+
Computed: true,
96+
},
97+
"rules_config_info": {
98+
Type: schema.TypeList,
99+
Computed: true,
100+
Description: "Message for rules config info",
101+
Elem: &schema.Resource{
102+
Schema: map[string]*schema.Schema{
103+
"rule_id": {
104+
Type: schema.TypeString,
105+
Computed: true,
106+
Description: "Backup Rule id fetched from backup plan.",
107+
},
108+
"last_backup_state": {
109+
Type: schema.TypeString,
110+
Computed: true,
111+
Description: "State of last backup taken.",
112+
},
113+
"last_backup_error": {
114+
Type: schema.TypeList,
115+
Computed: true,
116+
Description: "google.rpc.Status object to store the last backup error",
117+
Elem: &schema.Resource{
118+
Schema: map[string]*schema.Schema{
119+
"code": {
120+
Type: schema.TypeInt,
121+
Computed: true,
122+
Description: "The status code, which should be an enum value of [google.rpc.Code]",
123+
},
124+
"message": {
125+
Type: schema.TypeString,
126+
Computed: true,
127+
Description: "A developer-facing error message, which should be in English.",
128+
},
129+
},
130+
},
131+
},
132+
"last_successful_backup_consistency_time": {
133+
Type: schema.TypeString,
134+
Computed: true,
135+
Description: "The point in time when the last successful backup was captured from the source",
136+
},
137+
},
138+
},
139+
},
93140
},
94141
},
95142
},
@@ -139,7 +186,10 @@ func dataSourceGoogleCloudBackupDRBackupPlanAssociationsRead(d *schema.ResourceD
139186
"name": association["name"],
140187
"resource": association["resource"],
141188
"backup_plan": association["backupPlan"],
142-
"create_time": association["createTime"],
189+
"data_source": association["dataSource"],
190+
}
191+
if rules, ok := association["rulesConfigInfo"].([]interface{}); ok {
192+
flattened["rules_config_info"] = flattenRulesConfigInfo(rules)
143193
}
144194
associations = append(associations, flattened)
145195
}
@@ -152,3 +202,29 @@ func dataSourceGoogleCloudBackupDRBackupPlanAssociationsRead(d *schema.ResourceD
152202

153203
return nil
154204
}
205+
206+
func flattenRulesConfigInfo(rules []interface{}) []map[string]interface{} {
207+
result := make([]map[string]interface{}, 0, len(rules))
208+
for _, rule := range rules {
209+
ruleMap := rule.(map[string]interface{})
210+
flatRule := map[string]interface{}{
211+
"rule_id": ruleMap["ruleId"],
212+
"last_backup_state": ruleMap["lastBackupState"],
213+
}
214+
215+
if consistencyTime, ok := ruleMap["lastSuccessfulBackupConsistencyTime"].(string); ok {
216+
flatRule["last_successful_backup_consistency_time"] = consistencyTime
217+
}
218+
219+
if errInfo, ok := ruleMap["lastBackupError"].(map[string]interface{}); ok {
220+
flatRule["last_backup_error"] = []map[string]interface{}{
221+
{
222+
"code": errInfo["code"],
223+
"message": errInfo["message"],
224+
},
225+
}
226+
}
227+
result = append(result, flatRule)
228+
}
229+
return result
230+
}

mmv1/third_party/terraform/services/backupdr/data_source_backup_dr_backup_plan_association_test.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ func testAccCheckBackupPlanAssociationInList(dataSourceName, instanceName, backu
176176
projectID := project.Primary.Attributes["project_id"]
177177
projectNumber := project.Primary.Attributes["number"]
178178

179-
fmt.Printf("\n--- Performing Direct Association Check ---\n")
180-
181179
// 1. Reconstruct the 'resource' string using the project NUMBER and instance ID
182180
// to match the format returned by the BackupDR API.
183181
instanceID := instance.Primary.Attributes["instance_id"]
@@ -191,21 +189,32 @@ func testAccCheckBackupPlanAssociationInList(dataSourceName, instanceName, backu
191189

192190
associationsCount, _ := strconv.Atoi(ds.Primary.Attributes["associations.#"])
193191
fmt.Printf("Total associations found by data source: %d\n", associationsCount)
192+
found := false
194193

195194
for i := 0; i < associationsCount; i++ {
196195
resourceAttr := ds.Primary.Attributes[fmt.Sprintf("associations.%d.resource", i)]
197196
backupPlanAttr := ds.Primary.Attributes[fmt.Sprintf("associations.%d.backup_plan", i)]
198197

199-
fmt.Printf("Found Association #%d: Resource='%s', BackupPlan='%s'\n", i, resourceAttr, backupPlanAttr)
200-
201198
if resourceAttr == expectedResource && backupPlanAttr == expectedBackupPlan {
202-
fmt.Println("--- Match found! Test successful. ---")
203-
return nil
199+
prefix := fmt.Sprintf("associations.%d.", i)
200+
checks := []resource.TestCheckFunc{
201+
resource.TestCheckResourceAttrSet(dataSourceName, prefix+"name"),
202+
resource.TestCheckResourceAttrSet(dataSourceName, prefix+"data_source"),
203+
204+
resource.TestCheckResourceAttrSet(dataSourceName, prefix+"rules_config_info.0.rule_id"),
205+
resource.TestCheckResourceAttrSet(dataSourceName, prefix+"rules_config_info.0.last_backup_state"),
206+
}
207+
if err := resource.ComposeTestCheckFunc(checks...)(s); err != nil {
208+
return fmt.Errorf("error checking new fields for association %d: %v", i, err)
209+
}
210+
found = true
211+
break
204212
}
205213
}
206-
207-
fmt.Println("--- No match found after checking all associations. ---")
208-
return fmt.Errorf("no matching backup plan association found in data source '%s' for resource '%s'", dataSourceName, expectedResource)
214+
if !found {
215+
return fmt.Errorf("no matching backup plan association found in data source '%s' for resource '%s'", dataSourceName, expectedResource)
216+
}
217+
return nil
209218
}
210219
}
211220

mmv1/third_party/terraform/website/docs/d/backup_dr_backup_plan_association.html.markdown

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ description: |-
88

99
A Backup and DR BackupPlanAssociation.
1010

11-
~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
12-
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.
13-
1411
## Example Usage
1512

1613
```hcl

mmv1/third_party/terraform/website/docs/d/backup_dr_backup_plan_associations.html.markdown

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ description: |-
88

99
Provides a list of Backup and DR BackupPlanAssociations for a specific resource type.
1010

11-
~> **Warning:** This datasource is in beta, and should be used with the terraform-provider-google-beta provider.
12-
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta datasources.
13-
1411
## Example Usage
1512

1613
```hcl
1714
data "google_backup_dr_backup_plan_associations" "compute_instance_associations" {
1815
location = "us-central1"
1916
resource_type = "compute.googleapis.com/Instance"
2017
}
18+
```
2119

2220
## Argument Reference
2321

@@ -43,6 +41,13 @@ Each entry in the `associations` list contains the following fields:
4341
* `name` - The full name of the backup plan association resource.
4442
* `resource` - The resource to which the backup plan is applied.
4543
* `backup_plan` - The backup plan to which the resource is attached.
46-
* `create_time` - The time when the association was created.
44+
* `data_source` - The resource name of data source which will be used as storage location for backups taken.
45+
* `rules_config_info` - A list containing information about the backup rules. Each object in the list contains:
46+
* `rule_id` - Backup Rule id fetched from backup plan.
47+
* `last_backup_state` - State of last backup taken.
48+
* `last_successful_backup_consistency_time` - The point in time when the last successful backup was captured from the source.
49+
* `last_backup_error` - A block containing details of the last backup error, if any.
50+
* `code` - The status code, which should be an enum value of [google.rpc.Code].
51+
* `message` - A developer-facing error message.
4752

4853
See [google_backup_dr_backup_plan_associations](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/backup_dr_backup_plan_associations) resource for details of the available attributes.

mmv1/third_party/terraform/website/docs/d/backup_dr_data_source_reference.html.markdown

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,23 @@ description: |-
88

99
Get information about a specific Backup and DR data source reference.
1010

11-
~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
12-
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.
13-
1411
## Example Usage
1512

1613
This example shows how to get the details of a specific data source reference by its ID. The ID is often obtained from the `google_backup_dr_data_source_references` data source.
1714

1815
```hcl
19-
data "google_backup_dr_data_source_references" "all_sql_references" {
16+
data "google_backup_dr_data_source_references" "all_csql_references" {
2017
location = "us-central1"
2118
resource_type = "sqladmin.googleapis.com/Instance"
2219
}
2320
2421
data "google_backup_dr_data_source_reference" "my_reference" {
2522
location = "us-central1"
26-
data_source_reference_id = element(split("/", data.google_backup_dr_data_source_references.all_sql_references.data_source_references[0].name), 5)
23+
data_source_reference_id = element(split("/", data.google_backup_dr_data_source_references.all_csql_references.data_source_references[0].name), 5)
2724
}
2825
29-
output "specific_reference_gcp_resource_name" {
30-
value = data.google_backup_dr_data_source_reference.my_reference.gcp_resource_name
26+
output "my_data_source_reference" {
27+
value = data.google_backup_dr_data_source_reference.my_reference
3128
}
3229
```
3330

mmv1/third_party/terraform/website/docs/d/backup_dr_data_source_references.html.markdown

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@ description: |-
88

99
A list of Backup and DR data source references.
1010

11-
~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
12-
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.
13-
1411
## Example Usage
1512

1613
```hcl
17-
data "google_backup_dr_data_source_references" "my_sql_references" {
14+
data "google_backup_dr_data_source_references" "csql_data_source_reference" {
1815
location = "us-central1"
1916
resource_type = "sqladmin.googleapis.com/Instance"
2017
}
2118
22-
output "first_sql_reference_name" {
23-
name = data.google_backup_dr_data_source_references.my_sql_references.data_source_references[0].name
19+
output "all_csql_data_source_references" {
20+
allReferences = data.google_backup_dr_data_source_references.my_sql_references.data_source_references
2421
}
2522
```
2623

@@ -30,7 +27,7 @@ The following arguments are supported:
3027

3128
* `location `- (Required) The location of the data source references.
3229

33-
* `resource_type` - (Required) The resource type to get the data source references for. Examples include, "sqladmin.googleapis.com/Instance" , "compute.googleapis.com/Instance" (right now this service not available for compute Instances , it will be added soon )
30+
* `resource_type` - (Required) The resource type to get the data source references for. Examples include, "sqladmin.googleapis.com/Instance" , "compute.googleapis.com/Instance" (**right now this service not available for compute Instances and disk , it will be added soon**)
3431

3532
* `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
3633

@@ -39,22 +36,22 @@ The following arguments are supported:
3936

4037
In addition to the arguments listed above, the following attributes are exported:
4138

42-
* data\_source\_references - A list of the data source references found. Each element of this list has the following attributes:
39+
* data\_source\_references - A list of the data source references found. Each element of this list has the following attributes:
4340

44-
1. `name`- The full name of the data source reference.
41+
1. `name`- The full name of the data source reference.
4542

46-
2. `data_source`- The underlying data source resource.
43+
2. `data_source`- The underlying data source resource.
4744

48-
3. `backup_config_state`- The state of the backup config for the data source.
45+
3. `backup_config_state`- The state of the backup config for the data source.
4946

50-
4. `backup_count`- The number of backups for the data source.
47+
4. `backup_count`- The number of backups for the data source.
5148

52-
5. `last_backup_state`- The state of the last backup.
49+
5. `last_backup_state`- The state of the last backup.
5350

54-
6. `last_successful_backup_time`- The last time a successful backup was made.
51+
6. `last_successful_backup_time`- The last time a successful backup was made.
5552

56-
7. `gcp_resource_name`- The GCP resource name for the data source.
53+
7. `gcp_resource_name`- The GCP resource name for the data source.
5754

58-
8. `resource_type`- The type of the referenced resource.
55+
8. `resource_type`- The type of the referenced resource.
5956

6057
See [google_backup_dr_data_source_references](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/backup_dr_data_source_references) resource for details of the available attributes.

0 commit comments

Comments
 (0)