mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 17:16:44 +00:00
![Manuel Correa](/assets/img/avatar_default.png)
Add `google_iam_role` data source to be able to fetch and query for GCP IAM roles permissions.
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
)
|
|
|
|
func dataSourceGoogleIamRole() *schema.Resource {
|
|
return &schema.Resource{
|
|
Read: dataSourceGoogleIamRoleRead,
|
|
Schema: map[string]*schema.Schema{
|
|
"name": &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
},
|
|
"title": {
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
},
|
|
"included_permissions": {
|
|
Type: schema.TypeList,
|
|
Computed: true,
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
},
|
|
"stage": {
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func dataSourceGoogleIamRoleRead(d *schema.ResourceData, meta interface{}) error {
|
|
config := meta.(*Config)
|
|
roleName := d.Get("name").(string)
|
|
role, err := config.clientIAM.Roles.Get(roleName).Do()
|
|
if err != nil {
|
|
return handleNotFoundError(err, d, fmt.Sprintf("Error reading IAM Role %s: %s", roleName, err))
|
|
}
|
|
|
|
d.SetId(role.Name)
|
|
d.Set("title", role.Title)
|
|
d.Set("stage", role.Stage)
|
|
d.Set("included_permissions", role.IncludedPermissions)
|
|
|
|
return nil
|
|
}
|