mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 09:06:44 +00:00
46 lines
1021 B
Go
46 lines
1021 B
Go
![]() |
package google
|
||
|
|
||
|
import (
|
||
|
"github.com/hashicorp/terraform/helper/schema"
|
||
|
)
|
||
|
|
||
|
func dataSourceGoogleCloudFunctionsFunction() *schema.Resource {
|
||
|
// Generate datasource schema from resource
|
||
|
dsSchema := datasourceSchemaFromResourceSchema(resourceCloudFunctionsFunction().Schema)
|
||
|
|
||
|
// Set 'Required' schema elements
|
||
|
addRequiredFieldsToSchema(dsSchema, "name")
|
||
|
|
||
|
// Set 'Optional' schema elements
|
||
|
addOptionalFieldsToSchema(dsSchema, "project", "region")
|
||
|
|
||
|
return &schema.Resource{
|
||
|
Read: dataSourceGoogleCloudFunctionsFunctionRead,
|
||
|
Schema: dsSchema,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func dataSourceGoogleCloudFunctionsFunctionRead(d *schema.ResourceData, meta interface{}) error {
|
||
|
config := meta.(*Config)
|
||
|
|
||
|
project, err := getProject(d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
region, err := getRegion(d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
cloudFuncId := &cloudFunctionId{
|
||
|
Project: project,
|
||
|
Region: region,
|
||
|
Name: d.Get("name").(string),
|
||
|
}
|
||
|
|
||
|
d.SetId(cloudFuncId.terraformId())
|
||
|
|
||
|
return resourceCloudFunctionsRead(d, meta)
|
||
|
}
|