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 oracledatabase_autonomous_database datasource (GoogleCloudPl…
…atform#12016) Co-authored-by: Riley Karson <[email protected]>
- Loading branch information
1 parent
826ca25
commit 3a87e2a
Showing
4 changed files
with
119 additions
and
0 deletions.
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
41 changes: 41 additions & 0 deletions
41
...arty/terraform/services/oracledatabase/data_source_oracle_database_autonomous_database.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,41 @@ | ||
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 | ||
} |
40 changes: 40 additions & 0 deletions
40
...terraform/services/oracledatabase/data_source_oracle_database_autonomous_database_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,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" | ||
} | ||
`) | ||
} |
37 changes: 37 additions & 0 deletions
37
...arty/terraform/website/docs/d/oracle_database_autonomous_database.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,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. |