mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-01 07:42:40 +00:00
Add google_project_services data source (#1822)
This commit is contained in:
parent
3db96c9073
commit
60dc8bccad
30
google/data_source_google_project_services.go
Normal file
30
google/data_source_google_project_services.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package google
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func dataSourceGoogleProjectServices() *schema.Resource {
|
||||||
|
// Generate datasource schema from resource
|
||||||
|
dsSchema := datasourceSchemaFromResourceSchema(resourceGoogleProjectServices().Schema)
|
||||||
|
|
||||||
|
// Set 'Optional' schema elements
|
||||||
|
addOptionalFieldsToSchema(dsSchema, "project")
|
||||||
|
|
||||||
|
return &schema.Resource{
|
||||||
|
Read: dataSourceGoogleProjectServicesRead,
|
||||||
|
Schema: dsSchema,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceGoogleProjectServicesRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
config := meta.(*Config)
|
||||||
|
|
||||||
|
project, err := getProject(d, config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.SetId(project)
|
||||||
|
|
||||||
|
return resourceGoogleProjectServicesRead(d, meta)
|
||||||
|
}
|
82
google/data_source_google_project_services_test.go
Normal file
82
google/data_source_google_project_services_test.go
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
package google
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAccDataSourceGoogleProjectServices_basic(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
org := getTestOrgFromEnv(t)
|
||||||
|
project := "terraform-" + acctest.RandString(10)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccCheckGoogleProjectServicesConfig(project, org),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccDataSourceGoogleProjectServicesCheck("data.google_project_services.project_services", "google_project_services.project_services"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccDataSourceGoogleProjectServicesCheck(dataSourceName string, resourceName string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
ds, ok := s.RootModule().Resources[dataSourceName]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("root module has no resource called %s", dataSourceName)
|
||||||
|
}
|
||||||
|
|
||||||
|
rs, ok := s.RootModule().Resources[resourceName]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("can't find %s in state", resourceName)
|
||||||
|
}
|
||||||
|
|
||||||
|
dsAttr := ds.Primary.Attributes
|
||||||
|
rsAttr := rs.Primary.Attributes
|
||||||
|
|
||||||
|
projectAttrToCheck := []string{
|
||||||
|
"project",
|
||||||
|
"services",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, attr := range projectAttrToCheck {
|
||||||
|
if dsAttr[attr] != rsAttr[attr] {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"%s is %s; want %s",
|
||||||
|
attr,
|
||||||
|
dsAttr[attr],
|
||||||
|
rsAttr[attr],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccCheckGoogleProjectServicesConfig(project, org string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "google_project" "project" {
|
||||||
|
project_id = "%s"
|
||||||
|
name = "%s"
|
||||||
|
org_id = "%s"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_project_services" "project_services" {
|
||||||
|
project = "${google_project.project.id}"
|
||||||
|
services = ["admin.googleapis.com"]
|
||||||
|
}
|
||||||
|
|
||||||
|
data "google_project_services" "project_services" {
|
||||||
|
project = "${google_project.project.id}"
|
||||||
|
}`, project, project, org)
|
||||||
|
}
|
|
@ -73,6 +73,7 @@ func Provider() terraform.ResourceProvider {
|
||||||
"google_compute_lb_ip_ranges": dataSourceGoogleComputeLbIpRanges(),
|
"google_compute_lb_ip_ranges": dataSourceGoogleComputeLbIpRanges(),
|
||||||
"google_compute_network": dataSourceGoogleComputeNetwork(),
|
"google_compute_network": dataSourceGoogleComputeNetwork(),
|
||||||
"google_project": dataSourceGoogleProject(),
|
"google_project": dataSourceGoogleProject(),
|
||||||
|
"google_project_services": dataSourceGoogleProjectServices(),
|
||||||
"google_compute_subnetwork": dataSourceGoogleComputeSubnetwork(),
|
"google_compute_subnetwork": dataSourceGoogleComputeSubnetwork(),
|
||||||
"google_compute_zones": dataSourceGoogleComputeZones(),
|
"google_compute_zones": dataSourceGoogleComputeZones(),
|
||||||
"google_compute_instance_group": dataSourceGoogleComputeInstanceGroup(),
|
"google_compute_instance_group": dataSourceGoogleComputeInstanceGroup(),
|
||||||
|
|
39
website/docs/d/google_project_services.html.markdown
Normal file
39
website/docs/d/google_project_services.html.markdown
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
---
|
||||||
|
layout: "google"
|
||||||
|
page_title: "Google: google_project_services"
|
||||||
|
sidebar_current: "docs-google-datasource-project-services"
|
||||||
|
description: |-
|
||||||
|
Retrieve enabled of API services for a Google Cloud Platform project
|
||||||
|
---
|
||||||
|
|
||||||
|
# google\_project\_services
|
||||||
|
|
||||||
|
Use this data source to get details on the enabled project services.
|
||||||
|
|
||||||
|
For a list of services available, visit the
|
||||||
|
[API library page](https://console.cloud.google.com/apis/library) or run `gcloud services list`.
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
data "google_project_services" "project" {
|
||||||
|
project = "your-project-id"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "project_services" {
|
||||||
|
value = "${join(",", data.google_project_services.project.services)}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Argument Reference
|
||||||
|
|
||||||
|
The following arguments are supported:
|
||||||
|
|
||||||
|
* `project` - (Required) The project ID.
|
||||||
|
|
||||||
|
|
||||||
|
## Attributes Reference
|
||||||
|
|
||||||
|
The following attributes are exported:
|
||||||
|
|
||||||
|
See [google_project_services](https://www.terraform.io/docs/providers/google/r/google_project_services.html) resource for details of the available attributes.
|
|
@ -55,6 +55,9 @@
|
||||||
<li<%= sidebar_current("docs-google-datasource-compute-region-instance-group") %>>
|
<li<%= sidebar_current("docs-google-datasource-compute-region-instance-group") %>>
|
||||||
<a href="/docs/providers/google/d/datasource_compute_region_instance_group.html">google_compute_region_instance_group</a>
|
<a href="/docs/providers/google/d/datasource_compute_region_instance_group.html">google_compute_region_instance_group</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li<%= sidebar_current("docs-google-datasource-project-services") %>>
|
||||||
|
<a href="/docs/providers/google/d/google_project_services.html">google_project_services</a>
|
||||||
|
</li>
|
||||||
<li<%= sidebar_current("docs-google-datasource-compute-regions") %>>
|
<li<%= sidebar_current("docs-google-datasource-compute-regions") %>>
|
||||||
<a href="/docs/providers/google/d/google_compute_regions.html">google_compute_regions</a>
|
<a href="/docs/providers/google/d/google_compute_regions.html">google_compute_regions</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user