From bb40d754c0dae9d957c8d44108ed03702c7cb423 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 16 Oct 2024 17:34:44 +0000 Subject: [PATCH] Feat: Add google_oracle_database_cloud_exadata_infrastructures datasource (#12000) [upstream:a38017ee8c8a0815ee4c03ea6460b22df48ac36e] Signed-off-by: Modular Magician --- .changelog/12000.txt | 3 + google/provider/provider_mmv1_resources.go | 3 +- ..._database_cloud_exadata_infrastructures.go | 111 ++++++++++++++++++ ...base_cloud_exadata_infrastructures_test.go | 45 +++++++ ...loud_exadata_infrastructures.html.markdown | 38 ++++++ 5 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 .changelog/12000.txt create mode 100644 google/services/oracledatabase/data_source_oracle_database_cloud_exadata_infrastructures.go create mode 100644 google/services/oracledatabase/data_source_oracle_database_cloud_exadata_infrastructures_test.go create mode 100644 website/docs/d/oracle_database_cloud_exadata_infrastructures.html.markdown diff --git a/.changelog/12000.txt b/.changelog/12000.txt new file mode 100644 index 00000000000..6556ca598f6 --- /dev/null +++ b/.changelog/12000.txt @@ -0,0 +1,3 @@ +```release-note:new-datasource +`google_oracle_database_cloud_exadata_infrastructures` +``` \ No newline at end of file diff --git a/google/provider/provider_mmv1_resources.go b/google/provider/provider_mmv1_resources.go index 8b225b093fd..5b5b4652253 100644 --- a/google/provider/provider_mmv1_resources.go +++ b/google/provider/provider_mmv1_resources.go @@ -266,8 +266,9 @@ var handwrittenDatasources = map[string]*schema.Resource{ "google_netblock_ip_ranges": resourcemanager.DataSourceGoogleNetblockIpRanges(), "google_oracle_database_db_nodes": oracledatabase.DataSourceOracleDatabaseDbNodes(), "google_oracle_database_db_servers": oracledatabase.DataSourceOracleDatabaseDbServers(), - "google_oracle_database_cloud_vm_cluster": oracledatabase.DataSourceOracleDatabaseCloudVmCluster(), + "google_oracle_database_cloud_exadata_infrastructures": oracledatabase.DataSourceOracleDatabaseCloudExadataInfrastructures(), "google_oracle_database_cloud_exadata_infrastructure": oracledatabase.DataSourceOracleDatabaseCloudExadataInfrastructure(), + "google_oracle_database_cloud_vm_cluster": oracledatabase.DataSourceOracleDatabaseCloudVmCluster(), "google_organization": resourcemanager.DataSourceGoogleOrganization(), "google_privateca_certificate_authority": privateca.DataSourcePrivatecaCertificateAuthority(), "google_privileged_access_manager_entitlement": privilegedaccessmanager.DataSourceGooglePrivilegedAccessManagerEntitlement(), diff --git a/google/services/oracledatabase/data_source_oracle_database_cloud_exadata_infrastructures.go b/google/services/oracledatabase/data_source_oracle_database_cloud_exadata_infrastructures.go new file mode 100644 index 00000000000..4c6739823de --- /dev/null +++ b/google/services/oracledatabase/data_source_oracle_database_cloud_exadata_infrastructures.go @@ -0,0 +1,111 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 +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 DataSourceOracleDatabaseCloudExadataInfrastructures() *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_exadata_infrastructures": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: tpgresource.DatasourceSchemaFromResourceSchema(ResourceOracleDatabaseCloudExadataInfrastructure().Schema), + }, + }, + } + return &schema.Resource{ + Read: dataSourceOracleDatabaseCloudExadataInfrastructuresRead, + Schema: dsSchema, + } + +} + +func dataSourceOracleDatabaseCloudExadataInfrastructuresRead(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}}/cloudExadataInfrastructures") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + + billingProject := "" + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for cloudExadataInfrastructures: %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 cloudExadataInfrastructures: %s", err) + } + + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error setting cloudExadataInfrastructures project: %s", err) + } + + if err := d.Set("cloud_exadata_infrastructures", flattenOracleDatabaseCloudExadataInfrastructures(res["cloudExadataInfrastructures"], d, config)); err != nil { + return fmt.Errorf("Error setting cloudExadataInfrastructures: %s", err) + } + + id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/cloudExadataInfrastructures") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + return nil +} + +func flattenOracleDatabaseCloudExadataInfrastructures(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": flattenOracleDatabaseCloudExadataInfrastructureName(original["name"], d, config), + "display_name": flattenOracleDatabaseCloudExadataInfrastructureDisplayName(original["displayName"], d, config), + "gcp_oracle_zone": flattenOracleDatabaseCloudExadataInfrastructureGcpOracleZone(original["gcpOracleZone"], d, config), + "entitlement_id": flattenOracleDatabaseCloudExadataInfrastructureEntitlementId(original["entitlementId"], d, config), + "properties": flattenOracleDatabaseCloudExadataInfrastructureProperties(original["properties"], d, config), + "labels": flattenOracleDatabaseCloudExadataInfrastructureLabels(original["labels"], d, config), + "create_time": flattenOracleDatabaseCloudExadataInfrastructureCreateTime(original["createTime"], d, config), + "terraform_labels": flattenOracleDatabaseCloudExadataInfrastructureTerraformLabels(original["labels"], d, config), + "effective_labels": flattenOracleDatabaseCloudExadataInfrastructureEffectiveLabels(original["labels"], d, config), + }) + } + return transformed +} diff --git a/google/services/oracledatabase/data_source_oracle_database_cloud_exadata_infrastructures_test.go b/google/services/oracledatabase/data_source_oracle_database_cloud_exadata_infrastructures_test.go new file mode 100644 index 00000000000..3f3edf0f54b --- /dev/null +++ b/google/services/oracledatabase/data_source_oracle_database_cloud_exadata_infrastructures_test.go @@ -0,0 +1,45 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 +package oracledatabase_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-google/google/acctest" +) + +func TestAccOracleDatabaseCloudExadataInfrastructures_basic(t *testing.T) { + t.Parallel() + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccOracleDatabaseCloudExadataInfrastructures_basic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.google_oracle_database_cloud_exadata_infrastructures.my_cloud_exadatas", "cloud_exadata_infrastructures.#"), + resource.TestCheckResourceAttrSet("data.google_oracle_database_cloud_exadata_infrastructures.my_cloud_exadatas", "cloud_exadata_infrastructures.0.display_name"), + resource.TestCheckResourceAttrSet("data.google_oracle_database_cloud_exadata_infrastructures.my_cloud_exadatas", "cloud_exadata_infrastructures.0.gcp_oracle_zone"), + resource.TestCheckResourceAttrSet("data.google_oracle_database_cloud_exadata_infrastructures.my_cloud_exadatas", "cloud_exadata_infrastructures.0.name"), + resource.TestCheckResourceAttrSet("data.google_oracle_database_cloud_exadata_infrastructures.my_cloud_exadatas", "cloud_exadata_infrastructures.0.properties.#"), + resource.TestCheckResourceAttrSet("data.google_oracle_database_cloud_exadata_infrastructures.my_cloud_exadatas", "cloud_exadata_infrastructures.0.properties.0.cpu_count"), + resource.TestCheckResourceAttrSet("data.google_oracle_database_cloud_exadata_infrastructures.my_cloud_exadatas", "cloud_exadata_infrastructures.0.properties.0.compute_count"), + resource.TestCheckResourceAttrSet("data.google_oracle_database_cloud_exadata_infrastructures.my_cloud_exadatas", "cloud_exadata_infrastructures.0.properties.0.max_cpu_count"), + resource.TestCheckResourceAttr("data.google_oracle_database_cloud_exadata_infrastructures.my_cloud_exadatas", "cloud_exadata_infrastructures.0.properties.0.state", "AVAILABLE"), + resource.TestCheckResourceAttr("data.google_oracle_database_cloud_exadata_infrastructures.my_cloud_exadatas", "cloud_exadata_infrastructures.0.properties.0.max_cpu_count", "252"), + ), + }, + }, + }) +} + +func testAccOracleDatabaseCloudExadataInfrastructures_basic() string { + return fmt.Sprintf(` +data "google_oracle_database_cloud_exadata_infrastructures" "my_cloud_exadatas"{ + location = "us-east4" + project = "oci-terraform-testing" +} +`) +} diff --git a/website/docs/d/oracle_database_cloud_exadata_infrastructures.html.markdown b/website/docs/d/oracle_database_cloud_exadata_infrastructures.html.markdown new file mode 100644 index 00000000000..95852a8389e --- /dev/null +++ b/website/docs/d/oracle_database_cloud_exadata_infrastructures.html.markdown @@ -0,0 +1,38 @@ +--- +subcategory: "Oracle Database" +description: |- + List all ExadataInfrastructures. +--- + +# google_oracle_database_cloud_exadata_infrastructures + +List all ExadataInfrastructures. + +For more information see the +[API](https://cloud.google.com/oracle/database/docs/reference/rest/v1/projects.locations.cloudExadataInfrastructures). + +## Example Usage + +```hcl +data "google_oracle_database_cloud_exadata_infrastructures" "my_exadatas"{ + 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: + +* `CloudExadataInfrastructures` - A list of ExadataInfrastructures. + +See [google_oracle_database_cloud_exadata_infrastructure](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_oracle_database_cloud_exadata_infrastructure#argument-reference) resource for details of the available attributes.