forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add datasource for oracle_database_cloud_vm_clusters (GoogleClo…
- Loading branch information
1 parent
af3639d
commit addc90c
Showing
4 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
..._party/terraform/services/oracledatabase/data_source_oracle_database_cloud_vm_clusters.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package oracledatabase | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-google/google/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" | ||
) | ||
|
||
func DataSourceOracleDatabaseCloudVmClusters() *schema.Resource { | ||
dsSchema := map[string]*schema.Schema{ | ||
"project": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "The ID of the project in which the dataset is located. If it is not provided, the provider project is used.", | ||
}, | ||
"location": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "location", | ||
}, | ||
"cloud_vm_clusters": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: tpgresource.DatasourceSchemaFromResourceSchema(ResourceOracleDatabaseCloudVmCluster().Schema), | ||
}, | ||
}, | ||
} | ||
return &schema.Resource{ | ||
Read: dataSourceOracleDatabaseCloudVmClustersRead, | ||
Schema: dsSchema, | ||
} | ||
|
||
} | ||
|
||
func dataSourceOracleDatabaseCloudVmClustersRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*transport_tpg.Config) | ||
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
url, err := tpgresource.ReplaceVars(d, config, "{{OracleDatabaseBasePath}}projects/{{project}}/locations/{{location}}/cloudVmClusters") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
|
||
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/cloudVmClusters") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
billingProject := "" | ||
project, err := tpgresource.GetProject(d, config) | ||
if err != nil { | ||
return fmt.Errorf("Error fetching project for cloudVmClusters: %s", err) | ||
} | ||
billingProject = project | ||
// err == nil indicates that the billing_project value was found | ||
if bp, err := tpgresource.GetBillingProject(d, config); err == nil { | ||
billingProject = bp | ||
} | ||
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
Config: config, | ||
Method: "GET", | ||
Project: billingProject, | ||
RawURL: url, | ||
UserAgent: userAgent, | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error reading cloudVmClusters: %s", err) | ||
} | ||
|
||
if err := d.Set("project", project); err != nil { | ||
return fmt.Errorf("Error setting cloudVmClusters project: %s", err) | ||
} | ||
|
||
if err := d.Set("cloud_vm_clusters", flattenOracleDatabaseCloudVmClusters(res["cloudVmClusters"], d, config)); err != nil { | ||
return fmt.Errorf("Error setting cloudVmClusters: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func flattenOracleDatabaseCloudVmClusters(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) []map[string]interface{} { | ||
if v == nil { | ||
return nil | ||
} | ||
l := v.([]interface{}) | ||
transformed := make([]map[string]interface{}, 0) | ||
for _, raw := range l { | ||
original := raw.(map[string]interface{}) | ||
transformed = append(transformed, map[string]interface{}{ | ||
"name": flattenOracleDatabaseCloudVmClusterName(original["name"], d, config), | ||
"exadata_infrastructure": flattenOracleDatabaseCloudVmClusterExadataInfrastructure(original["exadataInfrastructure"], d, config), | ||
"display_name": flattenOracleDatabaseCloudVmClusterDisplayName(original["displayName"], d, config), | ||
"gcp_oracle_zone": flattenOracleDatabaseCloudVmClusterGcpOracleZone(original["gcpOracleZone"], d, config), | ||
"properties": flattenOracleDatabaseCloudVmClusterProperties(original["properties"], d, config), | ||
"labels": flattenOracleDatabaseCloudVmClusterLabels(original["labels"], d, config), | ||
"create_time": flattenOracleDatabaseCloudVmClusterCreateTime(original["createTime"], d, config), | ||
"cidr": flattenOracleDatabaseCloudVmClusterCidr(original["cidr"], d, config), | ||
"backup_subnet_cidr": flattenOracleDatabaseCloudVmClusterBackupSubnetCidr(original["backupSubnetCidr"], d, config), | ||
"network": flattenOracleDatabaseCloudVmClusterNetwork(original["network"], d, config), | ||
"terraform_labels": flattenOracleDatabaseCloudVmClusterTerraformLabels(original["labels"], d, config), | ||
"effective_labels": flattenOracleDatabaseCloudVmClusterEffectiveLabels(original["labels"], d, config), | ||
}) | ||
} | ||
return transformed | ||
} |
36 changes: 36 additions & 0 deletions
36
...y/terraform/services/oracledatabase/data_source_oracle_database_cloud_vm_clusters_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package oracledatabase_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
) | ||
|
||
func TestAccOracleDatabaseCloudVmClusters_basic(t *testing.T) { | ||
t.Parallel() | ||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccOracleDatabaseCloudVmClusters_basic(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("data.google_oracle_database_cloud_vm_clusters.my_vmclusters", "cloud_vm_clusters.#"), | ||
resource.TestCheckResourceAttrSet("data.google_oracle_database_cloud_vm_clusters.my_vmclusters", "cloud_vm_clusters.0.display_name"), | ||
resource.TestCheckResourceAttrSet("data.google_oracle_database_cloud_vm_clusters.my_vmclusters", "cloud_vm_clusters.0.properties.#"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccOracleDatabaseCloudVmClusters_basic() string { | ||
return fmt.Sprintf(` | ||
data "google_oracle_database_cloud_vm_clusters" "my_vmclusters"{ | ||
location = "us-east4" | ||
project = "oci-terraform-testing" | ||
} | ||
`) | ||
} |
38 changes: 38 additions & 0 deletions
38
..._party/terraform/website/docs/d/oracle_database_cloud_vm_clusters.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
subcategory: "Oracle Database" | ||
description: |- | ||
List all CloudVmClusters. | ||
--- | ||
|
||
# google_oracle_database_cloud_vm_clusters | ||
|
||
List all CloudVmClusters. | ||
|
||
For more information see the | ||
[API](https://cloud.google.com/oracle/database/docs/reference/rest/v1/projects.locations.cloudVmClusters). | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "google_oracle_database_cloud_vm_clusters" "my_vmclusters"{ | ||
location = "us-east4" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `location` - (Required) The location of the resource. | ||
|
||
- - - | ||
* `project` - (Optional) The project to which the resource belongs. If it | ||
is not provided, the provider project is used. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `CloudVmClusters` - A list of CloudVmClusters. | ||
|
||
See [google_oracle_database_cloud_vm_cluster](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_oracle_database_cloud_vm_cluster#argument-reference) resource for details of the available attributes. |