github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/eks/podIdentityAssociation.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 eks
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	"errors"
    11  	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
    12  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    13  )
    14  
    15  // Resource for managing an AWS EKS (Elastic Kubernetes) Pod Identity Association.
    16  //
    17  // Creates an EKS Pod Identity association between a service account in an Amazon EKS cluster and an IAM role with EKS Pod Identity. Use EKS Pod Identity to give temporary IAM credentials to pods and the credentials are rotated automatically.
    18  //
    19  // Amazon EKS Pod Identity associations provide the ability to manage credentials for your applications, similar to the way that EC2 instance profiles provide credentials to Amazon EC2 instances.
    20  //
    21  // If a pod uses a service account that has an association, Amazon EKS sets environment variables in the containers of the pod. The environment variables configure the Amazon Web Services SDKs, including the Command Line Interface, to use the EKS Pod Identity credentials.
    22  //
    23  // Pod Identity is a simpler method than IAM roles for service accounts, as this method doesn’t use OIDC identity providers. Additionally, you can configure a role for Pod Identity once, and reuse it across clusters.
    24  //
    25  // ## Example Usage
    26  //
    27  // ### Basic Usage
    28  //
    29  // <!--Start PulumiCodeChooser -->
    30  // ```go
    31  // package main
    32  //
    33  // import (
    34  //
    35  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/eks"
    36  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    37  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    38  //
    39  // )
    40  //
    41  //	func main() {
    42  //		pulumi.Run(func(ctx *pulumi.Context) error {
    43  //			assumeRole, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
    44  //				Statements: []iam.GetPolicyDocumentStatement{
    45  //					{
    46  //						Effect: pulumi.StringRef("Allow"),
    47  //						Principals: []iam.GetPolicyDocumentStatementPrincipal{
    48  //							{
    49  //								Type: "Service",
    50  //								Identifiers: []string{
    51  //									"pods.eks.amazonaws.com",
    52  //								},
    53  //							},
    54  //						},
    55  //						Actions: []string{
    56  //							"sts:AssumeRole",
    57  //							"sts:TagSession",
    58  //						},
    59  //					},
    60  //				},
    61  //			}, nil)
    62  //			if err != nil {
    63  //				return err
    64  //			}
    65  //			example, err := iam.NewRole(ctx, "example", &iam.RoleArgs{
    66  //				Name:             pulumi.String("eks-pod-identity-example"),
    67  //				AssumeRolePolicy: pulumi.String(assumeRole.Json),
    68  //			})
    69  //			if err != nil {
    70  //				return err
    71  //			}
    72  //			_, err = iam.NewRolePolicyAttachment(ctx, "example_s3", &iam.RolePolicyAttachmentArgs{
    73  //				PolicyArn: pulumi.String("arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"),
    74  //				Role:      example.Name,
    75  //			})
    76  //			if err != nil {
    77  //				return err
    78  //			}
    79  //			_, err = eks.NewPodIdentityAssociation(ctx, "example", &eks.PodIdentityAssociationArgs{
    80  //				ClusterName:    pulumi.Any(exampleAwsEksCluster.Name),
    81  //				Namespace:      pulumi.String("example"),
    82  //				ServiceAccount: pulumi.String("example-sa"),
    83  //				RoleArn:        example.Arn,
    84  //			})
    85  //			if err != nil {
    86  //				return err
    87  //			}
    88  //			return nil
    89  //		})
    90  //	}
    91  //
    92  // ```
    93  // <!--End PulumiCodeChooser -->
    94  //
    95  // ## Import
    96  //
    97  // Using `pulumi import`, import EKS (Elastic Kubernetes) Pod Identity Association using the `cluster_name` and `association_id` separated by a comma (`,`). For example:
    98  //
    99  // ```sh
   100  // $ pulumi import aws:eks/podIdentityAssociation:PodIdentityAssociation example example,a-12345678
   101  // ```
   102  type PodIdentityAssociation struct {
   103  	pulumi.CustomResourceState
   104  
   105  	// The Amazon Resource Name (ARN) of the association.
   106  	AssociationArn pulumi.StringOutput `pulumi:"associationArn"`
   107  	// The ID of the association.
   108  	AssociationId pulumi.StringOutput `pulumi:"associationId"`
   109  	// The name of the cluster to create the association in.
   110  	ClusterName pulumi.StringOutput `pulumi:"clusterName"`
   111  	// The name of the Kubernetes namespace inside the cluster to create the association in. The service account and the pods that use the service account must be in this namespace.
   112  	Namespace pulumi.StringOutput `pulumi:"namespace"`
   113  	// The Amazon Resource Name (ARN) of the IAM role to associate with the service account. The EKS Pod Identity agent manages credentials to assume this role for applications in the containers in the pods that use this service account.
   114  	RoleArn pulumi.StringOutput `pulumi:"roleArn"`
   115  	// The name of the Kubernetes service account inside the cluster to associate the IAM credentials with.
   116  	//
   117  	// The following arguments are optional:
   118  	ServiceAccount pulumi.StringOutput `pulumi:"serviceAccount"`
   119  	// Key-value map of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   120  	Tags pulumi.StringMapOutput `pulumi:"tags"`
   121  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   122  	//
   123  	// Deprecated: Please use `tags` instead.
   124  	TagsAll pulumi.StringMapOutput `pulumi:"tagsAll"`
   125  }
   126  
   127  // NewPodIdentityAssociation registers a new resource with the given unique name, arguments, and options.
   128  func NewPodIdentityAssociation(ctx *pulumi.Context,
   129  	name string, args *PodIdentityAssociationArgs, opts ...pulumi.ResourceOption) (*PodIdentityAssociation, error) {
   130  	if args == nil {
   131  		return nil, errors.New("missing one or more required arguments")
   132  	}
   133  
   134  	if args.ClusterName == nil {
   135  		return nil, errors.New("invalid value for required argument 'ClusterName'")
   136  	}
   137  	if args.Namespace == nil {
   138  		return nil, errors.New("invalid value for required argument 'Namespace'")
   139  	}
   140  	if args.RoleArn == nil {
   141  		return nil, errors.New("invalid value for required argument 'RoleArn'")
   142  	}
   143  	if args.ServiceAccount == nil {
   144  		return nil, errors.New("invalid value for required argument 'ServiceAccount'")
   145  	}
   146  	opts = internal.PkgResourceDefaultOpts(opts)
   147  	var resource PodIdentityAssociation
   148  	err := ctx.RegisterResource("aws:eks/podIdentityAssociation:PodIdentityAssociation", name, args, &resource, opts...)
   149  	if err != nil {
   150  		return nil, err
   151  	}
   152  	return &resource, nil
   153  }
   154  
   155  // GetPodIdentityAssociation gets an existing PodIdentityAssociation resource's state with the given name, ID, and optional
   156  // state properties that are used to uniquely qualify the lookup (nil if not required).
   157  func GetPodIdentityAssociation(ctx *pulumi.Context,
   158  	name string, id pulumi.IDInput, state *PodIdentityAssociationState, opts ...pulumi.ResourceOption) (*PodIdentityAssociation, error) {
   159  	var resource PodIdentityAssociation
   160  	err := ctx.ReadResource("aws:eks/podIdentityAssociation:PodIdentityAssociation", name, id, state, &resource, opts...)
   161  	if err != nil {
   162  		return nil, err
   163  	}
   164  	return &resource, nil
   165  }
   166  
   167  // Input properties used for looking up and filtering PodIdentityAssociation resources.
   168  type podIdentityAssociationState struct {
   169  	// The Amazon Resource Name (ARN) of the association.
   170  	AssociationArn *string `pulumi:"associationArn"`
   171  	// The ID of the association.
   172  	AssociationId *string `pulumi:"associationId"`
   173  	// The name of the cluster to create the association in.
   174  	ClusterName *string `pulumi:"clusterName"`
   175  	// The name of the Kubernetes namespace inside the cluster to create the association in. The service account and the pods that use the service account must be in this namespace.
   176  	Namespace *string `pulumi:"namespace"`
   177  	// The Amazon Resource Name (ARN) of the IAM role to associate with the service account. The EKS Pod Identity agent manages credentials to assume this role for applications in the containers in the pods that use this service account.
   178  	RoleArn *string `pulumi:"roleArn"`
   179  	// The name of the Kubernetes service account inside the cluster to associate the IAM credentials with.
   180  	//
   181  	// The following arguments are optional:
   182  	ServiceAccount *string `pulumi:"serviceAccount"`
   183  	// Key-value map of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   184  	Tags map[string]string `pulumi:"tags"`
   185  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   186  	//
   187  	// Deprecated: Please use `tags` instead.
   188  	TagsAll map[string]string `pulumi:"tagsAll"`
   189  }
   190  
   191  type PodIdentityAssociationState struct {
   192  	// The Amazon Resource Name (ARN) of the association.
   193  	AssociationArn pulumi.StringPtrInput
   194  	// The ID of the association.
   195  	AssociationId pulumi.StringPtrInput
   196  	// The name of the cluster to create the association in.
   197  	ClusterName pulumi.StringPtrInput
   198  	// The name of the Kubernetes namespace inside the cluster to create the association in. The service account and the pods that use the service account must be in this namespace.
   199  	Namespace pulumi.StringPtrInput
   200  	// The Amazon Resource Name (ARN) of the IAM role to associate with the service account. The EKS Pod Identity agent manages credentials to assume this role for applications in the containers in the pods that use this service account.
   201  	RoleArn pulumi.StringPtrInput
   202  	// The name of the Kubernetes service account inside the cluster to associate the IAM credentials with.
   203  	//
   204  	// The following arguments are optional:
   205  	ServiceAccount pulumi.StringPtrInput
   206  	// Key-value map of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   207  	Tags pulumi.StringMapInput
   208  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   209  	//
   210  	// Deprecated: Please use `tags` instead.
   211  	TagsAll pulumi.StringMapInput
   212  }
   213  
   214  func (PodIdentityAssociationState) ElementType() reflect.Type {
   215  	return reflect.TypeOf((*podIdentityAssociationState)(nil)).Elem()
   216  }
   217  
   218  type podIdentityAssociationArgs struct {
   219  	// The name of the cluster to create the association in.
   220  	ClusterName string `pulumi:"clusterName"`
   221  	// The name of the Kubernetes namespace inside the cluster to create the association in. The service account and the pods that use the service account must be in this namespace.
   222  	Namespace string `pulumi:"namespace"`
   223  	// The Amazon Resource Name (ARN) of the IAM role to associate with the service account. The EKS Pod Identity agent manages credentials to assume this role for applications in the containers in the pods that use this service account.
   224  	RoleArn string `pulumi:"roleArn"`
   225  	// The name of the Kubernetes service account inside the cluster to associate the IAM credentials with.
   226  	//
   227  	// The following arguments are optional:
   228  	ServiceAccount string `pulumi:"serviceAccount"`
   229  	// Key-value map of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   230  	Tags map[string]string `pulumi:"tags"`
   231  }
   232  
   233  // The set of arguments for constructing a PodIdentityAssociation resource.
   234  type PodIdentityAssociationArgs struct {
   235  	// The name of the cluster to create the association in.
   236  	ClusterName pulumi.StringInput
   237  	// The name of the Kubernetes namespace inside the cluster to create the association in. The service account and the pods that use the service account must be in this namespace.
   238  	Namespace pulumi.StringInput
   239  	// The Amazon Resource Name (ARN) of the IAM role to associate with the service account. The EKS Pod Identity agent manages credentials to assume this role for applications in the containers in the pods that use this service account.
   240  	RoleArn pulumi.StringInput
   241  	// The name of the Kubernetes service account inside the cluster to associate the IAM credentials with.
   242  	//
   243  	// The following arguments are optional:
   244  	ServiceAccount pulumi.StringInput
   245  	// Key-value map of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   246  	Tags pulumi.StringMapInput
   247  }
   248  
   249  func (PodIdentityAssociationArgs) ElementType() reflect.Type {
   250  	return reflect.TypeOf((*podIdentityAssociationArgs)(nil)).Elem()
   251  }
   252  
   253  type PodIdentityAssociationInput interface {
   254  	pulumi.Input
   255  
   256  	ToPodIdentityAssociationOutput() PodIdentityAssociationOutput
   257  	ToPodIdentityAssociationOutputWithContext(ctx context.Context) PodIdentityAssociationOutput
   258  }
   259  
   260  func (*PodIdentityAssociation) ElementType() reflect.Type {
   261  	return reflect.TypeOf((**PodIdentityAssociation)(nil)).Elem()
   262  }
   263  
   264  func (i *PodIdentityAssociation) ToPodIdentityAssociationOutput() PodIdentityAssociationOutput {
   265  	return i.ToPodIdentityAssociationOutputWithContext(context.Background())
   266  }
   267  
   268  func (i *PodIdentityAssociation) ToPodIdentityAssociationOutputWithContext(ctx context.Context) PodIdentityAssociationOutput {
   269  	return pulumi.ToOutputWithContext(ctx, i).(PodIdentityAssociationOutput)
   270  }
   271  
   272  // PodIdentityAssociationArrayInput is an input type that accepts PodIdentityAssociationArray and PodIdentityAssociationArrayOutput values.
   273  // You can construct a concrete instance of `PodIdentityAssociationArrayInput` via:
   274  //
   275  //	PodIdentityAssociationArray{ PodIdentityAssociationArgs{...} }
   276  type PodIdentityAssociationArrayInput interface {
   277  	pulumi.Input
   278  
   279  	ToPodIdentityAssociationArrayOutput() PodIdentityAssociationArrayOutput
   280  	ToPodIdentityAssociationArrayOutputWithContext(context.Context) PodIdentityAssociationArrayOutput
   281  }
   282  
   283  type PodIdentityAssociationArray []PodIdentityAssociationInput
   284  
   285  func (PodIdentityAssociationArray) ElementType() reflect.Type {
   286  	return reflect.TypeOf((*[]*PodIdentityAssociation)(nil)).Elem()
   287  }
   288  
   289  func (i PodIdentityAssociationArray) ToPodIdentityAssociationArrayOutput() PodIdentityAssociationArrayOutput {
   290  	return i.ToPodIdentityAssociationArrayOutputWithContext(context.Background())
   291  }
   292  
   293  func (i PodIdentityAssociationArray) ToPodIdentityAssociationArrayOutputWithContext(ctx context.Context) PodIdentityAssociationArrayOutput {
   294  	return pulumi.ToOutputWithContext(ctx, i).(PodIdentityAssociationArrayOutput)
   295  }
   296  
   297  // PodIdentityAssociationMapInput is an input type that accepts PodIdentityAssociationMap and PodIdentityAssociationMapOutput values.
   298  // You can construct a concrete instance of `PodIdentityAssociationMapInput` via:
   299  //
   300  //	PodIdentityAssociationMap{ "key": PodIdentityAssociationArgs{...} }
   301  type PodIdentityAssociationMapInput interface {
   302  	pulumi.Input
   303  
   304  	ToPodIdentityAssociationMapOutput() PodIdentityAssociationMapOutput
   305  	ToPodIdentityAssociationMapOutputWithContext(context.Context) PodIdentityAssociationMapOutput
   306  }
   307  
   308  type PodIdentityAssociationMap map[string]PodIdentityAssociationInput
   309  
   310  func (PodIdentityAssociationMap) ElementType() reflect.Type {
   311  	return reflect.TypeOf((*map[string]*PodIdentityAssociation)(nil)).Elem()
   312  }
   313  
   314  func (i PodIdentityAssociationMap) ToPodIdentityAssociationMapOutput() PodIdentityAssociationMapOutput {
   315  	return i.ToPodIdentityAssociationMapOutputWithContext(context.Background())
   316  }
   317  
   318  func (i PodIdentityAssociationMap) ToPodIdentityAssociationMapOutputWithContext(ctx context.Context) PodIdentityAssociationMapOutput {
   319  	return pulumi.ToOutputWithContext(ctx, i).(PodIdentityAssociationMapOutput)
   320  }
   321  
   322  type PodIdentityAssociationOutput struct{ *pulumi.OutputState }
   323  
   324  func (PodIdentityAssociationOutput) ElementType() reflect.Type {
   325  	return reflect.TypeOf((**PodIdentityAssociation)(nil)).Elem()
   326  }
   327  
   328  func (o PodIdentityAssociationOutput) ToPodIdentityAssociationOutput() PodIdentityAssociationOutput {
   329  	return o
   330  }
   331  
   332  func (o PodIdentityAssociationOutput) ToPodIdentityAssociationOutputWithContext(ctx context.Context) PodIdentityAssociationOutput {
   333  	return o
   334  }
   335  
   336  // The Amazon Resource Name (ARN) of the association.
   337  func (o PodIdentityAssociationOutput) AssociationArn() pulumi.StringOutput {
   338  	return o.ApplyT(func(v *PodIdentityAssociation) pulumi.StringOutput { return v.AssociationArn }).(pulumi.StringOutput)
   339  }
   340  
   341  // The ID of the association.
   342  func (o PodIdentityAssociationOutput) AssociationId() pulumi.StringOutput {
   343  	return o.ApplyT(func(v *PodIdentityAssociation) pulumi.StringOutput { return v.AssociationId }).(pulumi.StringOutput)
   344  }
   345  
   346  // The name of the cluster to create the association in.
   347  func (o PodIdentityAssociationOutput) ClusterName() pulumi.StringOutput {
   348  	return o.ApplyT(func(v *PodIdentityAssociation) pulumi.StringOutput { return v.ClusterName }).(pulumi.StringOutput)
   349  }
   350  
   351  // The name of the Kubernetes namespace inside the cluster to create the association in. The service account and the pods that use the service account must be in this namespace.
   352  func (o PodIdentityAssociationOutput) Namespace() pulumi.StringOutput {
   353  	return o.ApplyT(func(v *PodIdentityAssociation) pulumi.StringOutput { return v.Namespace }).(pulumi.StringOutput)
   354  }
   355  
   356  // The Amazon Resource Name (ARN) of the IAM role to associate with the service account. The EKS Pod Identity agent manages credentials to assume this role for applications in the containers in the pods that use this service account.
   357  func (o PodIdentityAssociationOutput) RoleArn() pulumi.StringOutput {
   358  	return o.ApplyT(func(v *PodIdentityAssociation) pulumi.StringOutput { return v.RoleArn }).(pulumi.StringOutput)
   359  }
   360  
   361  // The name of the Kubernetes service account inside the cluster to associate the IAM credentials with.
   362  //
   363  // The following arguments are optional:
   364  func (o PodIdentityAssociationOutput) ServiceAccount() pulumi.StringOutput {
   365  	return o.ApplyT(func(v *PodIdentityAssociation) pulumi.StringOutput { return v.ServiceAccount }).(pulumi.StringOutput)
   366  }
   367  
   368  // Key-value map of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   369  func (o PodIdentityAssociationOutput) Tags() pulumi.StringMapOutput {
   370  	return o.ApplyT(func(v *PodIdentityAssociation) pulumi.StringMapOutput { return v.Tags }).(pulumi.StringMapOutput)
   371  }
   372  
   373  // A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   374  //
   375  // Deprecated: Please use `tags` instead.
   376  func (o PodIdentityAssociationOutput) TagsAll() pulumi.StringMapOutput {
   377  	return o.ApplyT(func(v *PodIdentityAssociation) pulumi.StringMapOutput { return v.TagsAll }).(pulumi.StringMapOutput)
   378  }
   379  
   380  type PodIdentityAssociationArrayOutput struct{ *pulumi.OutputState }
   381  
   382  func (PodIdentityAssociationArrayOutput) ElementType() reflect.Type {
   383  	return reflect.TypeOf((*[]*PodIdentityAssociation)(nil)).Elem()
   384  }
   385  
   386  func (o PodIdentityAssociationArrayOutput) ToPodIdentityAssociationArrayOutput() PodIdentityAssociationArrayOutput {
   387  	return o
   388  }
   389  
   390  func (o PodIdentityAssociationArrayOutput) ToPodIdentityAssociationArrayOutputWithContext(ctx context.Context) PodIdentityAssociationArrayOutput {
   391  	return o
   392  }
   393  
   394  func (o PodIdentityAssociationArrayOutput) Index(i pulumi.IntInput) PodIdentityAssociationOutput {
   395  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *PodIdentityAssociation {
   396  		return vs[0].([]*PodIdentityAssociation)[vs[1].(int)]
   397  	}).(PodIdentityAssociationOutput)
   398  }
   399  
   400  type PodIdentityAssociationMapOutput struct{ *pulumi.OutputState }
   401  
   402  func (PodIdentityAssociationMapOutput) ElementType() reflect.Type {
   403  	return reflect.TypeOf((*map[string]*PodIdentityAssociation)(nil)).Elem()
   404  }
   405  
   406  func (o PodIdentityAssociationMapOutput) ToPodIdentityAssociationMapOutput() PodIdentityAssociationMapOutput {
   407  	return o
   408  }
   409  
   410  func (o PodIdentityAssociationMapOutput) ToPodIdentityAssociationMapOutputWithContext(ctx context.Context) PodIdentityAssociationMapOutput {
   411  	return o
   412  }
   413  
   414  func (o PodIdentityAssociationMapOutput) MapIndex(k pulumi.StringInput) PodIdentityAssociationOutput {
   415  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *PodIdentityAssociation {
   416  		return vs[0].(map[string]*PodIdentityAssociation)[vs[1].(string)]
   417  	}).(PodIdentityAssociationOutput)
   418  }
   419  
   420  func init() {
   421  	pulumi.RegisterInputType(reflect.TypeOf((*PodIdentityAssociationInput)(nil)).Elem(), &PodIdentityAssociation{})
   422  	pulumi.RegisterInputType(reflect.TypeOf((*PodIdentityAssociationArrayInput)(nil)).Elem(), PodIdentityAssociationArray{})
   423  	pulumi.RegisterInputType(reflect.TypeOf((*PodIdentityAssociationMapInput)(nil)).Elem(), PodIdentityAssociationMap{})
   424  	pulumi.RegisterOutputType(PodIdentityAssociationOutput{})
   425  	pulumi.RegisterOutputType(PodIdentityAssociationArrayOutput{})
   426  	pulumi.RegisterOutputType(PodIdentityAssociationMapOutput{})
   427  }