github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/elb/getServiceAccount.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 elb
     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 Account ID of the [AWS Elastic Load Balancing Service Account](http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-access-logs.html#attach-bucket-policy)
    15  // in a given region for the purpose of permitting in S3 bucket policy.
    16  //
    17  // > **Note:** For AWS Regions opened since Jakarta (`ap-southeast-3`) in December 2021, AWS [documents that](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-access-logs.html#attach-bucket-policy) a [service principal name](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html#principal-services) should be used instead of an AWS account ID in any relevant IAM policy.
    18  //
    19  // ## Example Usage
    20  //
    21  // <!--Start PulumiCodeChooser -->
    22  // ```go
    23  // package main
    24  //
    25  // import (
    26  //
    27  //	"fmt"
    28  //
    29  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/elb"
    30  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    31  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/s3"
    32  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    33  //
    34  // )
    35  // func main() {
    36  // pulumi.Run(func(ctx *pulumi.Context) error {
    37  // main, err := elb.GetServiceAccount(ctx, nil, nil);
    38  // if err != nil {
    39  // return err
    40  // }
    41  // elbLogs, err := s3.NewBucketV2(ctx, "elb_logs", &s3.BucketV2Args{
    42  // Bucket: pulumi.String("my-elb-tf-test-bucket"),
    43  // })
    44  // if err != nil {
    45  // return err
    46  // }
    47  // _, err = s3.NewBucketAclV2(ctx, "elb_logs_acl", &s3.BucketAclV2Args{
    48  // Bucket: elbLogs.ID(),
    49  // Acl: pulumi.String("private"),
    50  // })
    51  // if err != nil {
    52  // return err
    53  // }
    54  // allowElbLogging := elbLogs.Arn.ApplyT(func(arn string) (iam.GetPolicyDocumentResult, error) {
    55  // return iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
    56  // Statements: []iam.GetPolicyDocumentStatement{
    57  // {
    58  // Effect: "Allow",
    59  // Principals: []iam.GetPolicyDocumentStatementPrincipal{
    60  // {
    61  // Type: "AWS",
    62  // Identifiers: interface{}{
    63  // main.Arn,
    64  // },
    65  // },
    66  // },
    67  // Actions: []string{
    68  // "s3:PutObject",
    69  // },
    70  // Resources: []string{
    71  // fmt.Sprintf("%v/AWSLogs/*", arn),
    72  // },
    73  // },
    74  // },
    75  // }, nil), nil
    76  // }).(iam.GetPolicyDocumentResultOutput)
    77  // _, err = s3.NewBucketPolicy(ctx, "allow_elb_logging", &s3.BucketPolicyArgs{
    78  // Bucket: elbLogs.ID(),
    79  // Policy: allowElbLogging.ApplyT(func(allowElbLogging iam.GetPolicyDocumentResult) (*string, error) {
    80  // return &allowElbLogging.Json, nil
    81  // }).(pulumi.StringPtrOutput),
    82  // })
    83  // if err != nil {
    84  // return err
    85  // }
    86  // _, err = elb.NewLoadBalancer(ctx, "bar", &elb.LoadBalancerArgs{
    87  // Name: pulumi.String("my-foobar-elb"),
    88  // AvailabilityZones: pulumi.StringArray{
    89  // pulumi.String("us-west-2a"),
    90  // },
    91  // AccessLogs: &elb.LoadBalancerAccessLogsArgs{
    92  // Bucket: elbLogs.ID(),
    93  // Interval: pulumi.Int(5),
    94  // },
    95  // Listeners: elb.LoadBalancerListenerArray{
    96  // &elb.LoadBalancerListenerArgs{
    97  // InstancePort: pulumi.Int(8000),
    98  // InstanceProtocol: pulumi.String("http"),
    99  // LbPort: pulumi.Int(80),
   100  // LbProtocol: pulumi.String("http"),
   101  // },
   102  // },
   103  // })
   104  // if err != nil {
   105  // return err
   106  // }
   107  // return nil
   108  // })
   109  // }
   110  // ```
   111  // <!--End PulumiCodeChooser -->
   112  func GetServiceAccount(ctx *pulumi.Context, args *GetServiceAccountArgs, opts ...pulumi.InvokeOption) (*GetServiceAccountResult, error) {
   113  	opts = internal.PkgInvokeDefaultOpts(opts)
   114  	var rv GetServiceAccountResult
   115  	err := ctx.Invoke("aws:elb/getServiceAccount:getServiceAccount", args, &rv, opts...)
   116  	if err != nil {
   117  		return nil, err
   118  	}
   119  	return &rv, nil
   120  }
   121  
   122  // A collection of arguments for invoking getServiceAccount.
   123  type GetServiceAccountArgs struct {
   124  	// Name of the region whose AWS ELB account ID is desired.
   125  	// Defaults to the region from the AWS provider configuration.
   126  	Region *string `pulumi:"region"`
   127  }
   128  
   129  // A collection of values returned by getServiceAccount.
   130  type GetServiceAccountResult struct {
   131  	// ARN of the AWS ELB service account in the selected region.
   132  	Arn string `pulumi:"arn"`
   133  	// The provider-assigned unique ID for this managed resource.
   134  	Id     string  `pulumi:"id"`
   135  	Region *string `pulumi:"region"`
   136  }
   137  
   138  func GetServiceAccountOutput(ctx *pulumi.Context, args GetServiceAccountOutputArgs, opts ...pulumi.InvokeOption) GetServiceAccountResultOutput {
   139  	return pulumi.ToOutputWithContext(context.Background(), args).
   140  		ApplyT(func(v interface{}) (GetServiceAccountResult, error) {
   141  			args := v.(GetServiceAccountArgs)
   142  			r, err := GetServiceAccount(ctx, &args, opts...)
   143  			var s GetServiceAccountResult
   144  			if r != nil {
   145  				s = *r
   146  			}
   147  			return s, err
   148  		}).(GetServiceAccountResultOutput)
   149  }
   150  
   151  // A collection of arguments for invoking getServiceAccount.
   152  type GetServiceAccountOutputArgs struct {
   153  	// Name of the region whose AWS ELB account ID is desired.
   154  	// Defaults to the region from the AWS provider configuration.
   155  	Region pulumi.StringPtrInput `pulumi:"region"`
   156  }
   157  
   158  func (GetServiceAccountOutputArgs) ElementType() reflect.Type {
   159  	return reflect.TypeOf((*GetServiceAccountArgs)(nil)).Elem()
   160  }
   161  
   162  // A collection of values returned by getServiceAccount.
   163  type GetServiceAccountResultOutput struct{ *pulumi.OutputState }
   164  
   165  func (GetServiceAccountResultOutput) ElementType() reflect.Type {
   166  	return reflect.TypeOf((*GetServiceAccountResult)(nil)).Elem()
   167  }
   168  
   169  func (o GetServiceAccountResultOutput) ToGetServiceAccountResultOutput() GetServiceAccountResultOutput {
   170  	return o
   171  }
   172  
   173  func (o GetServiceAccountResultOutput) ToGetServiceAccountResultOutputWithContext(ctx context.Context) GetServiceAccountResultOutput {
   174  	return o
   175  }
   176  
   177  // ARN of the AWS ELB service account in the selected region.
   178  func (o GetServiceAccountResultOutput) Arn() pulumi.StringOutput {
   179  	return o.ApplyT(func(v GetServiceAccountResult) string { return v.Arn }).(pulumi.StringOutput)
   180  }
   181  
   182  // The provider-assigned unique ID for this managed resource.
   183  func (o GetServiceAccountResultOutput) Id() pulumi.StringOutput {
   184  	return o.ApplyT(func(v GetServiceAccountResult) string { return v.Id }).(pulumi.StringOutput)
   185  }
   186  
   187  func (o GetServiceAccountResultOutput) Region() pulumi.StringPtrOutput {
   188  	return o.ApplyT(func(v GetServiceAccountResult) *string { return v.Region }).(pulumi.StringPtrOutput)
   189  }
   190  
   191  func init() {
   192  	pulumi.RegisterOutputType(GetServiceAccountResultOutput{})
   193  }