Skip to content

Commit

Permalink
add-tags-to-resources2 (#211)
Browse files Browse the repository at this point in the history
* add-tags-to-resources2

* add-tags-to-resources2
  • Loading branch information
calvix authored Nov 2, 2023
1 parent 6e51af2 commit 4a57d84
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add tags from `AWSCluster.Spec.AdditionalTags` and `AWSManagedControlPlane.Spec.AdditionalTags` to all created resources.

## [0.11.0] - 2023-11-01

### Added
Expand Down
1 change: 1 addition & 0 deletions controllers/awsmachinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (r *AWSMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Reque
RoleType: iam.NodesRole,
Region: awsCluster.Spec.Region,
IAMClientFactory: r.IAMClientFactory,
CustomTags: awsCluster.Spec.AdditionalTags,
}
iamService, err = iam.New(c)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions controllers/awsmachinetemplate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (r *AWSMachineTemplateReconciler) Reconcile(ctx context.Context, req ctrl.R
RoleType: role,
Region: awsCluster.Spec.Region,
IAMClientFactory: r.IAMClientFactory,
CustomTags: awsCluster.Spec.AdditionalTags,
}
iamService, err = iam.New(c)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions controllers/awsmanagedcontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (r *AWSManagedControlPlaneReconciler) Reconcile(ctx context.Context, req ct
RoleType: iam.IRSARole,
Region: eksCluster.Spec.Region,
IAMClientFactory: r.IAMClientFactory,
CustomTags: eksCluster.Spec.AdditionalTags,
}
iamService, err = iam.New(c)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/iam/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type IAMServiceConfig struct {
RoleType string
Region string
PrincipalRoleARN string
CustomTags map[string]string

IAMClientFactory func(awsclientgo.ConfigProvider) iamiface.IAMAPI
}
Expand All @@ -50,6 +51,7 @@ type IAMService struct {
region string
roleType string
principalRoleARN string
customTags map[string]string
}

type Route53RoleParams struct {
Expand Down Expand Up @@ -90,6 +92,7 @@ func New(config IAMServiceConfig) (*IAMService, error) {
roleType: config.RoleType,
region: config.Region,
principalRoleARN: config.PrincipalRoleARN,
customTags: config.CustomTags,
}

return s, nil
Expand Down Expand Up @@ -259,6 +262,12 @@ func (s *IAMService) createRole(roleName string, roleType string, params interfa
Value: aws.String("owned"),
},
}
for k, v := range s.customTags {
tags = append(tags, &awsiam.Tag{
Key: aws.String(k),
Value: aws.String(v),
})
}

_, err = s.iamClient.CreateRole(&awsiam.CreateRoleInput{
RoleName: aws.String(roleName),
Expand Down

0 comments on commit 4a57d84

Please sign in to comment.