Skip to content

Commit de049fb

Browse files
committed
Added documentation and refactor
1 parent 3aba97d commit de049fb

File tree

4 files changed

+50
-32
lines changed

4 files changed

+50
-32
lines changed

mmv1/third_party/terraform/provider/provider_mmv1_resources.go.tmpl

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var handwrittenDatasources = map[string]*schema.Resource{
2222
"google_access_approval_project_service_account": accessapproval.DataSourceAccessApprovalProjectServiceAccount(),
2323
"google_access_context_manager_access_policy": accesscontextmanager.DataSourceAccessContextManagerAccessPolicy(),
2424
"google_active_folder": resourcemanager.DataSourceGoogleActiveFolder(),
25+
"google_alloydb_cluster": alloydb.DataSourceAlloydbDatabaseCluster(),
2526
"google_alloydb_locations": alloydb.DataSourceAlloydbLocations(),
2627
"google_alloydb_supported_database_flags": alloydb.DataSourceAlloydbSupportedDatabaseFlags(),
2728
"google_artifact_registry_docker_image": artifactregistry.DataSourceArtifactRegistryDockerImage(),
@@ -190,11 +191,9 @@ var handwrittenDatasources = map[string]*schema.Resource{
190191
"google_parameter_manager_parameter": parametermanager.DataSourceParameterManagerParameter(),
191192
"google_parameter_manager_parameters": parametermanager.DataSourceParameterManagerParameters(),
192193
"google_parameter_manager_parameter_version": parametermanager.DataSourceParameterManagerParameterVersion(),
193-
"google_parameter_manager_parameter_version_render":parametermanager.DataSourceParameterManagerParameterVersionRender(),
194194
"google_parameter_manager_regional_parameter": parametermanagerregional.DataSourceParameterManagerRegionalRegionalParameter(),
195195
"google_parameter_manager_regional_parameters": parametermanagerregional.DataSourceParameterManagerRegionalRegionalParameters(),
196196
"google_parameter_manager_regional_parameter_version": parametermanagerregional.DataSourceParameterManagerRegionalRegionalParameterVersion(),
197-
"google_parameter_manager_regional_parameter_version_render":parametermanagerregional.DataSourceParameterManagerRegionalRegionalParameterVersionRender(),
198197
{{- end }}
199198
"google_privateca_certificate_authority": privateca.DataSourcePrivatecaCertificateAuthority(),
200199
"google_privileged_access_manager_entitlement": privilegedaccessmanager.DataSourceGooglePrivilegedAccessManagerEntitlement(),

mmv1/third_party/terraform/services/alloydb/data_soruce_alloydb_cluster.go

+9-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
31
package alloydb
42

53
import (
@@ -13,54 +11,37 @@ import (
1311
func DataSourceAlloydbDatabaseCluster() *schema.Resource {
1412
// Generate datasource schema from resource
1513
dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceAlloydbCluster().Schema)
16-
// Set custom fields
17-
dsScema_cluster_id := map[string]*schema.Schema{
18-
"project": {
19-
Type: schema.TypeString,
20-
Optional: true,
21-
Description: `Project ID of the project.`,
22-
},
23-
"location": {
24-
Type: schema.TypeString,
25-
Optional: true,
26-
Description: `The canonical ID for the location. For example: "us-east1".`,
27-
},
28-
}
29-
tpgresource.AddRequiredFieldsToSchema(dsSchema, "cluster_id")
3014

3115
// Set 'Required' schema elements
16+
tpgresource.AddRequiredFieldsToSchema(dsSchema, "cluster_id")
3217

33-
dsSchema_m := tpgresource.MergeSchemas(dsScema_cluster_id, dsSchema)
18+
// Set 'Optional' schema elements
19+
tpgresource.AddOptionalFieldsToSchema(dsSchema, "location", "project")
3420

3521
return &schema.Resource{
36-
Read: dataSourceAlloydbDatabaseInstanceRead,
37-
Schema: dsSchema_m,
22+
Read: dataSourceAlloydbDatabaseClusterRead,
23+
Schema: dsSchema,
3824
}
3925
}
4026

4127
func dataSourceAlloydbDatabaseClusterRead(d *schema.ResourceData, meta interface{}) error {
4228
config := meta.(*transport_tpg.Config)
4329

44-
// Get feilds for ID for setting cluster filed in resource
45-
cluster_id := d.Get("cluster_id").(string)
46-
30+
// Get location for setting location field in resource
4731
location, err := tpgresource.GetLocation(d, config)
4832
if err != nil {
4933
return err
5034
}
51-
project, err := tpgresource.GetProject(d, config)
52-
if err != nil {
53-
return err
54-
}
35+
5536
// Store the ID now
5637
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/clusters/{{cluster_id}}")
5738
if err != nil {
5839
return fmt.Errorf("Error constructing id: %s", err)
5940
}
6041
d.SetId(id)
6142

62-
// Setting cluster field
63-
d.Set("cluster", fmt.Sprintf("projects/%s/locations/%s/clusters/%s", project, location, cluster_id))
43+
// Setting location field as this is set as a required field in cluster resource
44+
d.Set("location", location)
6445

6546
err = resourceAlloydbClusterRead(d, meta)
6647
if err != nil {

mmv1/third_party/terraform/services/alloydb/data_soruce_alloydb_cluster_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/hashicorp/terraform-provider-google/google/acctest"
88
)
99

10-
func TestAccAlloydbDatabaseInstanceDatasourceConfig(t *testing.T) {
10+
func TestAccAlloydbDatabaseClusterDatasourceConfig(t *testing.T) {
1111
t.Parallel()
1212

1313
context := map[string]interface{}{
@@ -27,7 +27,7 @@ func TestAccAlloydbDatabaseInstanceDatasourceConfig(t *testing.T) {
2727
})
2828
}
2929

30-
func testAccAlloydbDatabaseInstanceDatasourceConfig(context map[string]interface{}) string {
30+
func testAccAlloydbDatabaseClusterDatasourceConfig(context map[string]interface{}) string {
3131
return acctest.Nprintf(`
3232
resource "google_alloydb_instance" "default" {
3333
cluster = google_alloydb_cluster.default.name
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
subcategory: "AlloyDB"
3+
description: |-
4+
Fetches the details of available cluster.
5+
---
6+
7+
# google_alloydb_cluster
8+
9+
Use this data source to get information about the available cluster. For more details refer the [API docs](https://cloud.google.com/alloydb/docs/reference/rest/v1/projects.locations.clusters).
10+
11+
## Example Usage
12+
13+
14+
```hcl
15+
data "google_alloydb_cluster" "qa" {
16+
}
17+
```
18+
19+
## Argument Reference
20+
21+
The following arguments are supported:
22+
23+
* `cluster_id` -
24+
(Required)
25+
The ID of the alloydb cluster that the instance belongs to.
26+
'alloydb_cluster_id'
27+
28+
* `project` -
29+
(optional)
30+
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
31+
32+
* `location` -
33+
(optional)
34+
The canonical id of the location.If it is not provided, the provider project is used. For example: us-east1.
35+
36+
## Attributes Reference
37+
38+
See [google_alloydb_cluster](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/alloydb_cluster) resource for details of all the available attributes.

0 commit comments

Comments
 (0)