|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | +// ---------------------------------------------------------------------------- |
| 4 | +// |
| 5 | +// *** AUTO GENERATED CODE *** Type: Handwritten *** |
| 6 | +// |
| 7 | +// ---------------------------------------------------------------------------- |
| 8 | +// |
| 9 | +// This code is generated by Magic Modules using the following: |
| 10 | +// |
| 11 | +// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/redis/data_source_redis_cluster.go |
| 12 | +// |
| 13 | +// DO NOT EDIT this file directly. Any changes made to this file will be |
| 14 | +// overwritten during the next generation cycle. |
| 15 | +// |
| 16 | +// ---------------------------------------------------------------------------- |
| 17 | +// Copyright (c) HashiCorp, Inc. |
| 18 | +// SPDX-License-Identifier: MPL-2.0 |
| 19 | +package redis |
| 20 | + |
| 21 | +import ( |
| 22 | + "fmt" |
| 23 | + |
| 24 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 25 | + "github.com/hashicorp/terraform-provider-google/google/tpgresource" |
| 26 | + transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" |
| 27 | +) |
| 28 | + |
| 29 | +func DataSourceRedisCluster() *schema.Resource { |
| 30 | + // Generate datasource schema from resource |
| 31 | + dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceRedisCluster().Schema) |
| 32 | + |
| 33 | + // Set 'Required' schema elements |
| 34 | + tpgresource.AddRequiredFieldsToSchema(dsSchema, "name") |
| 35 | + // Set 'Optional' schema elements |
| 36 | + tpgresource.AddOptionalFieldsToSchema(dsSchema, "project", "region") |
| 37 | + |
| 38 | + return &schema.Resource{ |
| 39 | + Read: dataSourceRedisClusterRead, |
| 40 | + Schema: dsSchema, |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +func dataSourceRedisClusterRead(d *schema.ResourceData, meta interface{}) error { |
| 45 | + id, err := tpgresource.ReplaceVars(d, meta.(*transport_tpg.Config), "projects/{{project}}/locations/{{region}}/clusters/{{name}}") |
| 46 | + if err != nil { |
| 47 | + return fmt.Errorf("Error constructing id: %s", err) |
| 48 | + } |
| 49 | + d.SetId(id) |
| 50 | + |
| 51 | + err = resourceRedisClusterRead(d, meta) |
| 52 | + if err != nil { |
| 53 | + return err |
| 54 | + } |
| 55 | + |
| 56 | + if err := tpgresource.SetDataSourceLabels(d); err != nil { |
| 57 | + return err |
| 58 | + } |
| 59 | + |
| 60 | + if d.Id() == "" { |
| 61 | + return fmt.Errorf("%s not found", id) |
| 62 | + } |
| 63 | + return nil |
| 64 | +} |
0 commit comments