From 437b0449d3d6c42b2cbb5e7ac601fae02cd62208 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Thu, 17 Oct 2024 19:31:01 +0000 Subject: [PATCH] Feat add oracledatabase_autonomous_database datasource (#12016) Co-authored-by: Riley Karson [upstream:5987428dc5b26332366696a66d58e35db26400e5] Signed-off-by: Modular Magician --- .changelog/12016.txt | 3 ++ google/provider/provider_mmv1_resources.go | 1 + ...rce_oracle_database_autonomous_database.go | 43 +++++++++++++++++++ ...racle_database_autonomous_database_test.go | 42 ++++++++++++++++++ ...database_autonomous_database.html.markdown | 37 ++++++++++++++++ 5 files changed, 126 insertions(+) create mode 100644 .changelog/12016.txt create mode 100644 google/services/oracledatabase/data_source_oracle_database_autonomous_database.go create mode 100644 google/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go create mode 100644 website/docs/d/oracle_database_autonomous_database.html.markdown diff --git a/.changelog/12016.txt b/.changelog/12016.txt new file mode 100644 index 00000000000..9abd80f90b7 --- /dev/null +++ b/.changelog/12016.txt @@ -0,0 +1,3 @@ +```release-note:new-datasource +`google_oracle_database_autonomous_database` +``` \ No newline at end of file diff --git a/google/provider/provider_mmv1_resources.go b/google/provider/provider_mmv1_resources.go index bc075608951..94203fd3f56 100644 --- a/google/provider/provider_mmv1_resources.go +++ b/google/provider/provider_mmv1_resources.go @@ -264,6 +264,7 @@ var handwrittenDatasources = map[string]*schema.Resource{ "google_monitoring_app_engine_service": monitoring.DataSourceMonitoringServiceAppEngine(), "google_monitoring_uptime_check_ips": monitoring.DataSourceGoogleMonitoringUptimeCheckIps(), "google_netblock_ip_ranges": resourcemanager.DataSourceGoogleNetblockIpRanges(), + "google_oracle_database_autonomous_database": oracledatabase.DataSourceOracleDatabaseAutonomousDatabase(), "google_oracle_database_autonomous_databases": oracledatabase.DataSourceOracleDatabaseAutonomousDatabases(), "google_oracle_database_db_nodes": oracledatabase.DataSourceOracleDatabaseDbNodes(), "google_oracle_database_db_servers": oracledatabase.DataSourceOracleDatabaseDbServers(), diff --git a/google/services/oracledatabase/data_source_oracle_database_autonomous_database.go b/google/services/oracledatabase/data_source_oracle_database_autonomous_database.go new file mode 100644 index 00000000000..399bb07c2b1 --- /dev/null +++ b/google/services/oracledatabase/data_source_oracle_database_autonomous_database.go @@ -0,0 +1,43 @@ +// 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 DataSourceOracleDatabaseAutonomousDatabase() *schema.Resource { + dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceOracleDatabaseAutonomousDatabase().Schema) + tpgresource.AddRequiredFieldsToSchema(dsSchema, "location", "autonomous_database_id") + tpgresource.AddOptionalFieldsToSchema(dsSchema, "project") + return &schema.Resource{ + Read: dataSourceOracleDatabaseAutonomousDatabaseRead, + Schema: dsSchema, + } + +} + +func dataSourceOracleDatabaseAutonomousDatabaseRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + + id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/autonomousDatabases/{{autonomous_database_id}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + + d.SetId(id) + + err = resourceOracleDatabaseAutonomousDatabaseRead(d, meta) + if err != nil { + return err + } + + if d.Id() == "" { + return fmt.Errorf("%s not found", id) + } + return nil +} diff --git a/google/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go b/google/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go new file mode 100644 index 00000000000..1b979d529ba --- /dev/null +++ b/google/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go @@ -0,0 +1,42 @@ +// 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 TestAccOracleDatabaseAutonomousDatabase_basic(t *testing.T) { + t.Parallel() + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccOracleDatabaseAutonomousDatabase_basic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.google_oracle_database_autonomous_database.my-adb", "display_name"), + resource.TestCheckResourceAttrSet("data.google_oracle_database_autonomous_database.my-adb", "database"), + resource.TestCheckResourceAttrSet("data.google_oracle_database_autonomous_database.my-adb", "cidr"), + resource.TestCheckResourceAttrSet("data.google_oracle_database_autonomous_database.my-adb", "network"), + resource.TestCheckResourceAttrSet("data.google_oracle_database_autonomous_database.my-adb", "properties.#"), + resource.TestCheckResourceAttrSet("data.google_oracle_database_autonomous_database.my-adb", "properties.0.character_set"), + ), + }, + }, + }) +} + +func testAccOracleDatabaseAutonomousDatabase_basic() string { + return fmt.Sprintf(` +data "google_oracle_database_autonomous_database" "my-adb"{ + autonomous_database_id = "do-not-delete-tf-adb" + location = "us-east4" + project = "oci-terraform-testing" +} +`) +} diff --git a/website/docs/d/oracle_database_autonomous_database.html.markdown b/website/docs/d/oracle_database_autonomous_database.html.markdown new file mode 100644 index 00000000000..6c043fea5ff --- /dev/null +++ b/website/docs/d/oracle_database_autonomous_database.html.markdown @@ -0,0 +1,37 @@ +--- +subcategory: "Oracle Database" +description: |- + Get information about an AutonomousDatabase. +--- + +# google_oracle_database_autonomous_database + +Get information about an AutonomousDatabase. + +For more information see the +[API](https://cloud.google.com/oracle/database/docs/reference/rest/v1/projects.locations.autonomousDatabases). + +## Example Usage + +```hcl +data "google_oracle_database_autonomous_database" "my-instance"{ + location = "us-east4" + autonomous_database_id = "autonomous_database_id" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `autonomous_database_id` - (Required) The ID of the AutonomousDatabase. + +* `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 + +See [google_oracle_database_autonomous_database](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_oracle_database_autonomous_database#argument-reference) resource for details of the available attributes. \ No newline at end of file