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.
metastore dataproc service data source (GoogleCloudPlatform#5763)
* metastore dataproc service data source * provider * docs * test name * location optional * revert location and make required * docs * docs * tf test
- Loading branch information
1 parent
f1e0d0b
commit 3733b93
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
mmv1/third_party/terraform/data_sources/data_source_dataproc_metastore_service.go.erb
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,34 @@ | ||
<% autogen_exception -%> | ||
package google | ||
|
||
<% unless version == 'ga' -%> | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceDataprocMetastoreService() *schema.Resource { | ||
|
||
dsSchema := datasourceSchemaFromResourceSchema(resourceDataprocMetastoreService().Schema) | ||
addRequiredFieldsToSchema(dsSchema, "service_id") | ||
addRequiredFieldsToSchema(dsSchema, "location") | ||
addOptionalFieldsToSchema(dsSchema, "project") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceDataprocMetastoreServiceRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceDataprocMetastoreServiceRead(d *schema.ResourceData, meta interface{}) error { | ||
id, err := replaceVars(d, meta.(*Config), "projects/{{project}}/locations/{{location}}/services/{{service_id}}") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
return resourceDataprocMetastoreServiceRead(d, meta) | ||
} | ||
|
||
<% end -%> |
51 changes: 51 additions & 0 deletions
51
mmv1/third_party/terraform/tests/data_source_dataproc_metastore_service_test.go.erb
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,51 @@ | ||
<% autogen_exception -%> | ||
package google | ||
<% unless version == 'ga' -%> | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataprocMetastoreServiceDatasource_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
name := "tf-test-" + randString(t, 10) | ||
|
||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataprocMetastoreServiceDatasource_basic(name, "DEVELOPER"), | ||
Check: resource.ComposeTestCheckFunc( | ||
checkDataSourceStateMatchesResourceState("data.google_dataproc_metastore_service.my_metastore", "google_dataproc_metastore_service.my_metastore"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataprocMetastoreServiceDatasource_basic(name, tier string) string { | ||
return fmt.Sprintf(` | ||
resource "google_dataproc_metastore_service" "my_metastore" { | ||
service_id = "%s" | ||
location = "us-central1" | ||
tier = "%s" | ||
|
||
hive_metastore_config { | ||
version = "2.3.6" | ||
} | ||
} | ||
|
||
data "google_dataproc_metastore_service" "my_metastore" { | ||
service_id = google_dataproc_metastore_service.my_metastore.service_id | ||
location = google_dataproc_metastore_service.my_metastore.location | ||
} | ||
`, name, tier) | ||
} | ||
<% else %> | ||
// Magic Modules doesn't let us remove files - blank out beta-only common-compile files for now. | ||
<% end -%> |
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
40 changes: 40 additions & 0 deletions
40
..._party/terraform/website/docs/d/data_source_dataproc_metastore_service.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,40 @@ | ||
--- | ||
subcategory: "Dataproc" | ||
layout: "google" | ||
page_title: "Google: google_dataproc_metastore_service" | ||
sidebar_current: "docs-google-datasource-dataproc-metastore-service" | ||
description: |- | ||
Get a Dataproc Metastore Service from Google Cloud | ||
--- | ||
|
||
# google\_dataproc\_metastore\_service | ||
|
||
Get a Dataproc Metastore service from Google Cloud by its id and location. | ||
|
||
~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider. | ||
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources. | ||
|
||
## Example Usage | ||
|
||
```tf | ||
data "google_dataproc_metastore_service" "foo" { | ||
service_id = "foo-bar" | ||
location = "global" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `service_id` - (Required) The ID of the metastore service. | ||
* `location` - (Required) The location where the metastore service resides. | ||
|
||
- - - | ||
|
||
* `project` - (Optional) The project in which the resource belongs. If it | ||
is not provided, the provider project is used. | ||
|
||
## Attributes Reference | ||
|
||
See [google_dataproc_metastore_service](https://www.terraform.io/docs/providers/google/r/dataproc_metastore_service.html) resource for details of all the available attributes. |