github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/iam/getRoles.go (about) 1 // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT. 2 // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! *** 3 4 package iam 5 6 import ( 7 "context" 8 "reflect" 9 10 "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal" 11 "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 12 ) 13 14 // Use this data source to get the ARNs and Names of IAM Roles. 15 // 16 // ## Example Usage 17 // 18 // ### All roles in an account 19 // 20 // <!--Start PulumiCodeChooser --> 21 // ```go 22 // package main 23 // 24 // import ( 25 // 26 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam" 27 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 28 // 29 // ) 30 // 31 // func main() { 32 // pulumi.Run(func(ctx *pulumi.Context) error { 33 // _, err := iam.GetRoles(ctx, nil, nil) 34 // if err != nil { 35 // return err 36 // } 37 // return nil 38 // }) 39 // } 40 // 41 // ``` 42 // <!--End PulumiCodeChooser --> 43 // 44 // ### Roles filtered by name regex 45 // 46 // Roles whose role-name contains `project` 47 // 48 // <!--Start PulumiCodeChooser --> 49 // ```go 50 // package main 51 // 52 // import ( 53 // 54 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam" 55 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 56 // 57 // ) 58 // 59 // func main() { 60 // pulumi.Run(func(ctx *pulumi.Context) error { 61 // _, err := iam.GetRoles(ctx, &iam.GetRolesArgs{ 62 // NameRegex: pulumi.StringRef(".*project.*"), 63 // }, nil) 64 // if err != nil { 65 // return err 66 // } 67 // return nil 68 // }) 69 // } 70 // 71 // ``` 72 // <!--End PulumiCodeChooser --> 73 // 74 // ### Roles filtered by path prefix 75 // 76 // <!--Start PulumiCodeChooser --> 77 // ```go 78 // package main 79 // 80 // import ( 81 // 82 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam" 83 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 84 // 85 // ) 86 // 87 // func main() { 88 // pulumi.Run(func(ctx *pulumi.Context) error { 89 // _, err := iam.GetRoles(ctx, &iam.GetRolesArgs{ 90 // PathPrefix: pulumi.StringRef("/custom-path"), 91 // }, nil) 92 // if err != nil { 93 // return err 94 // } 95 // return nil 96 // }) 97 // } 98 // 99 // ``` 100 // <!--End PulumiCodeChooser --> 101 // 102 // ### Roles provisioned by AWS SSO 103 // 104 // # Roles in the account filtered by path prefix 105 // 106 // <!--Start PulumiCodeChooser --> 107 // ```go 108 // package main 109 // 110 // import ( 111 // 112 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam" 113 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 114 // 115 // ) 116 // 117 // func main() { 118 // pulumi.Run(func(ctx *pulumi.Context) error { 119 // _, err := iam.GetRoles(ctx, &iam.GetRolesArgs{ 120 // PathPrefix: pulumi.StringRef("/aws-reserved/sso.amazonaws.com/"), 121 // }, nil) 122 // if err != nil { 123 // return err 124 // } 125 // return nil 126 // }) 127 // } 128 // 129 // ``` 130 // <!--End PulumiCodeChooser --> 131 // 132 // # Specific role in the account filtered by name regex and path prefix 133 // 134 // <!--Start PulumiCodeChooser --> 135 // ```go 136 // package main 137 // 138 // import ( 139 // 140 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam" 141 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 142 // 143 // ) 144 // 145 // func main() { 146 // pulumi.Run(func(ctx *pulumi.Context) error { 147 // _, err := iam.GetRoles(ctx, &iam.GetRolesArgs{ 148 // NameRegex: pulumi.StringRef("AWSReservedSSO_permission_set_name_.*"), 149 // PathPrefix: pulumi.StringRef("/aws-reserved/sso.amazonaws.com/"), 150 // }, nil) 151 // if err != nil { 152 // return err 153 // } 154 // return nil 155 // }) 156 // } 157 // 158 // ``` 159 // <!--End PulumiCodeChooser --> 160 func GetRoles(ctx *pulumi.Context, args *GetRolesArgs, opts ...pulumi.InvokeOption) (*GetRolesResult, error) { 161 opts = internal.PkgInvokeDefaultOpts(opts) 162 var rv GetRolesResult 163 err := ctx.Invoke("aws:iam/getRoles:getRoles", args, &rv, opts...) 164 if err != nil { 165 return nil, err 166 } 167 return &rv, nil 168 } 169 170 // A collection of arguments for invoking getRoles. 171 type GetRolesArgs struct { 172 // Regex string to apply to the IAM roles list returned by AWS. This allows more advanced filtering not supported from the AWS API. This filtering is done locally on what AWS returns, and could have a performance impact if the result is large. Combine this with other options to narrow down the list AWS returns. 173 NameRegex *string `pulumi:"nameRegex"` 174 // Path prefix for filtering the results. For example, the prefix `/application_abc/component_xyz/` gets all roles whose path starts with `/application_abc/component_xyz/`. If it is not included, it defaults to a slash (`/`), listing all roles. For more details, check out [list-roles in the AWS CLI reference][1]. 175 PathPrefix *string `pulumi:"pathPrefix"` 176 } 177 178 // A collection of values returned by getRoles. 179 type GetRolesResult struct { 180 // Set of ARNs of the matched IAM roles. 181 Arns []string `pulumi:"arns"` 182 // The provider-assigned unique ID for this managed resource. 183 Id string `pulumi:"id"` 184 NameRegex *string `pulumi:"nameRegex"` 185 // Set of Names of the matched IAM roles. 186 Names []string `pulumi:"names"` 187 PathPrefix *string `pulumi:"pathPrefix"` 188 } 189 190 func GetRolesOutput(ctx *pulumi.Context, args GetRolesOutputArgs, opts ...pulumi.InvokeOption) GetRolesResultOutput { 191 return pulumi.ToOutputWithContext(context.Background(), args). 192 ApplyT(func(v interface{}) (GetRolesResult, error) { 193 args := v.(GetRolesArgs) 194 r, err := GetRoles(ctx, &args, opts...) 195 var s GetRolesResult 196 if r != nil { 197 s = *r 198 } 199 return s, err 200 }).(GetRolesResultOutput) 201 } 202 203 // A collection of arguments for invoking getRoles. 204 type GetRolesOutputArgs struct { 205 // Regex string to apply to the IAM roles list returned by AWS. This allows more advanced filtering not supported from the AWS API. This filtering is done locally on what AWS returns, and could have a performance impact if the result is large. Combine this with other options to narrow down the list AWS returns. 206 NameRegex pulumi.StringPtrInput `pulumi:"nameRegex"` 207 // Path prefix for filtering the results. For example, the prefix `/application_abc/component_xyz/` gets all roles whose path starts with `/application_abc/component_xyz/`. If it is not included, it defaults to a slash (`/`), listing all roles. For more details, check out [list-roles in the AWS CLI reference][1]. 208 PathPrefix pulumi.StringPtrInput `pulumi:"pathPrefix"` 209 } 210 211 func (GetRolesOutputArgs) ElementType() reflect.Type { 212 return reflect.TypeOf((*GetRolesArgs)(nil)).Elem() 213 } 214 215 // A collection of values returned by getRoles. 216 type GetRolesResultOutput struct{ *pulumi.OutputState } 217 218 func (GetRolesResultOutput) ElementType() reflect.Type { 219 return reflect.TypeOf((*GetRolesResult)(nil)).Elem() 220 } 221 222 func (o GetRolesResultOutput) ToGetRolesResultOutput() GetRolesResultOutput { 223 return o 224 } 225 226 func (o GetRolesResultOutput) ToGetRolesResultOutputWithContext(ctx context.Context) GetRolesResultOutput { 227 return o 228 } 229 230 // Set of ARNs of the matched IAM roles. 231 func (o GetRolesResultOutput) Arns() pulumi.StringArrayOutput { 232 return o.ApplyT(func(v GetRolesResult) []string { return v.Arns }).(pulumi.StringArrayOutput) 233 } 234 235 // The provider-assigned unique ID for this managed resource. 236 func (o GetRolesResultOutput) Id() pulumi.StringOutput { 237 return o.ApplyT(func(v GetRolesResult) string { return v.Id }).(pulumi.StringOutput) 238 } 239 240 func (o GetRolesResultOutput) NameRegex() pulumi.StringPtrOutput { 241 return o.ApplyT(func(v GetRolesResult) *string { return v.NameRegex }).(pulumi.StringPtrOutput) 242 } 243 244 // Set of Names of the matched IAM roles. 245 func (o GetRolesResultOutput) Names() pulumi.StringArrayOutput { 246 return o.ApplyT(func(v GetRolesResult) []string { return v.Names }).(pulumi.StringArrayOutput) 247 } 248 249 func (o GetRolesResultOutput) PathPrefix() pulumi.StringPtrOutput { 250 return o.ApplyT(func(v GetRolesResult) *string { return v.PathPrefix }).(pulumi.StringPtrOutput) 251 } 252 253 func init() { 254 pulumi.RegisterOutputType(GetRolesResultOutput{}) 255 }