From c548a98945ed8fdfdf9101d15b7ea39c96418a23 Mon Sep 17 00:00:00 2001 From: Aakriti Tulika Date: Wed, 16 Oct 2024 09:08:47 +0000 Subject: [PATCH 1/4] Feat add oracledatabase_autonomous_database datasource --- .../provider/provider_mmv1_resources.go.tmpl | 1 + ...rce_oracle_database_autonomous_database.go | 37 +++++++++++++++++ ...racle_database_autonomous_database_test.go | 40 +++++++++++++++++++ ...database_autonomous_database.html.markdown | 37 +++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go create mode 100644 mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go create mode 100644 mmv1/third_party/terraform/website/docs/d/oracle_database_autonomous_database.html.markdown diff --git a/mmv1/third_party/terraform/provider/provider_mmv1_resources.go.tmpl b/mmv1/third_party/terraform/provider/provider_mmv1_resources.go.tmpl index 8db763e20b34..af8efdee7763 100644 --- a/mmv1/third_party/terraform/provider/provider_mmv1_resources.go.tmpl +++ b/mmv1/third_party/terraform/provider/provider_mmv1_resources.go.tmpl @@ -168,6 +168,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_db_nodes": oracledatabase.DataSourceOracleDatabaseDbNodes(), "google_oracle_database_db_servers": oracledatabase.DataSourceOracleDatabaseDbServers(), "google_oracle_database_cloud_vm_cluster": oracledatabase.DataSourceOracleDatabaseCloudVmCluster(), diff --git a/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go new file mode 100644 index 000000000000..572195f0d3f9 --- /dev/null +++ b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go @@ -0,0 +1,37 @@ +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) + } + err = resourceOracleDatabaseAutonomousDatabaseRead(d,meta) + if err !=nil { + return err + } + d.SetId(id) + + return nil +} diff --git a/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go new file mode 100644 index 000000000000..cb07ceb90bf5 --- /dev/null +++ b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go @@ -0,0 +1,40 @@ +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/mmv1/third_party/terraform/website/docs/d/oracle_database_autonomous_database.html.markdown b/mmv1/third_party/terraform/website/docs/d/oracle_database_autonomous_database.html.markdown new file mode 100644 index 000000000000..6c043fea5ffc --- /dev/null +++ b/mmv1/third_party/terraform/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 From e4ac761511c3eadbcd203a8effe8449f099d1c56 Mon Sep 17 00:00:00 2001 From: Aakriti Tulika Date: Wed, 16 Oct 2024 09:30:55 +0000 Subject: [PATCH 2/4] Fix formatting in data_source_oracle_database_autonomous_database files --- .../data_source_oracle_database_autonomous_database.go | 5 ++--- .../data_source_oracle_database_autonomous_database_test.go | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go index 572195f0d3f9..8ba4ad595208 100644 --- a/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go +++ b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go @@ -1,7 +1,6 @@ package oracledatabase import ( - "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -12,7 +11,7 @@ import ( func DataSourceOracleDatabaseAutonomousDatabase() *schema.Resource { dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceOracleDatabaseAutonomousDatabase().Schema) tpgresource.AddRequiredFieldsToSchema(dsSchema, "location", "autonomous_database_id") - tpgresource.AddOptionalFieldsToSchema(dsSchema,"project") + tpgresource.AddOptionalFieldsToSchema(dsSchema, "project") return &schema.Resource{ Read: dataSourceOracleDatabaseAutonomousDatabaseRead, Schema: dsSchema, @@ -27,7 +26,7 @@ func dataSourceOracleDatabaseAutonomousDatabaseRead(d *schema.ResourceData, meta if err != nil { return fmt.Errorf("Error constructing id: %s", err) } - err = resourceOracleDatabaseAutonomousDatabaseRead(d,meta) + err = resourceOracleDatabaseAutonomousDatabaseRead(d, meta) if err !=nil { return err } diff --git a/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go index cb07ceb90bf5..dd35b42307ab 100644 --- a/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go +++ b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go @@ -1,10 +1,10 @@ package oracledatabase_test import ( - "fmt" + "fmt" - "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "testing" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-google/google/acctest" ) From e38bce019e1d8b9b1e25d1f8f6ed44f42cce8072 Mon Sep 17 00:00:00 2001 From: Aakriti Tulika Date: Wed, 16 Oct 2024 09:50:24 +0000 Subject: [PATCH 3/4] Fix formatting in data_source_oracle_database_autonomous_database files --- .../data_source_oracle_database_autonomous_database.go | 6 +++--- .../data_source_oracle_database_autonomous_database_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go index 8ba4ad595208..2e440f53b133 100644 --- a/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go +++ b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go @@ -13,7 +13,7 @@ func DataSourceOracleDatabaseAutonomousDatabase() *schema.Resource { tpgresource.AddRequiredFieldsToSchema(dsSchema, "location", "autonomous_database_id") tpgresource.AddOptionalFieldsToSchema(dsSchema, "project") return &schema.Resource{ - Read: dataSourceOracleDatabaseAutonomousDatabaseRead, + Read: dataSourceOracleDatabaseAutonomousDatabaseRead, Schema: dsSchema, } @@ -27,10 +27,10 @@ func dataSourceOracleDatabaseAutonomousDatabaseRead(d *schema.ResourceData, meta return fmt.Errorf("Error constructing id: %s", err) } err = resourceOracleDatabaseAutonomousDatabaseRead(d, meta) - if err !=nil { + if err != nil { return err } d.SetId(id) - + return nil } diff --git a/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go index dd35b42307ab..fce8fe50cf32 100644 --- a/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go +++ b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_test.go @@ -2,8 +2,8 @@ package oracledatabase_test import ( "fmt" - "testing" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-google/google/acctest" ) From 582ae54a2ff3bfc431bb0198ebffdf77e9d55012 Mon Sep 17 00:00:00 2001 From: Aakriti Tulika Date: Thu, 17 Oct 2024 05:29:02 +0000 Subject: [PATCH 4/4] Fix err logs for data_source_oracle_database_autonomous_database --- .../data_source_oracle_database_autonomous_database.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go index 2e440f53b133..30e49b7e1c2f 100644 --- a/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go +++ b/mmv1/third_party/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.go @@ -26,11 +26,16 @@ func dataSourceOracleDatabaseAutonomousDatabaseRead(d *schema.ResourceData, meta if err != nil { return fmt.Errorf("Error constructing id: %s", err) } + + d.SetId(id) + err = resourceOracleDatabaseAutonomousDatabaseRead(d, meta) if err != nil { return err } - d.SetId(id) + if d.Id() == "" { + return fmt.Errorf("%s not found", id) + } return nil }