Skip to content

Commit

Permalink
Fix clients.pushDownTerraformSetupBuilder when an assume role chain i…
Browse files Browse the repository at this point in the history
…s specified

Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
ulucinar committed Dec 8, 2023
1 parent e6f9d56 commit 5672e7c
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions internal/clients/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ const (
keyRoleArn = "role_arn"
keySessionName = "session_name"
keyWebIdentityTokenFile = "web_identity_token_file"
keyAssumeRole = "assume_role"
keyTags = "tags"
keyTransitiveTagKeys = "transitive_tag_keys"
keyExternalID = "external_id"
keySkipCredsValidation = "skip_credentials_validation"
keyS3UsePathStyle = "s3_use_path_style"
keySkipMetadataApiCheck = "skip_metadata_api_check"
Expand Down Expand Up @@ -91,7 +87,7 @@ func SelectTerraformSetup(log logging.Logger, config *SetupConfig) terraform.Set
keyAccountId: account,
}

if len(pc.Spec.AssumeRoleChain) > 1 || pc.Spec.Endpoint != nil {
if len(pc.Spec.AssumeRoleChain) > 0 || pc.Spec.Endpoint != nil {
err = DefaultTerraformSetupBuilder(ctx, pc, &ps, awsCfg, creds)
if err != nil {
return terraform.Setup{}, errors.Wrap(err, "cannot build terraform configuration")
Expand All @@ -117,9 +113,9 @@ func SelectTerraformSetup(log logging.Logger, config *SetupConfig) terraform.Set
}

func pushDownTerraformSetupBuilder(ctx context.Context, c client.Client, pc *v1beta1.ProviderConfig, ps *terraform.Setup, cfg *aws.Config) error { //nolint:gocyclo
if len(pc.Spec.AssumeRoleChain) > 1 || pc.Spec.Endpoint != nil {
if len(pc.Spec.AssumeRoleChain) > 0 || pc.Spec.Endpoint != nil {
return errors.New("shared scheduler cannot be used because the length of assume role chain array " +
"is more than 1 or endpoint configuration is not nil")
"is more than 0 or endpoint configuration is not nil")
}

ps.Configuration = map[string]any{
Expand Down Expand Up @@ -169,14 +165,6 @@ func pushDownTerraformSetupBuilder(ctx context.Context, c client.Client, pc *v1b
keySessionToken: creds.SessionToken,
}
}
if len(pc.Spec.AssumeRoleChain) != 0 {
ps.Configuration[keyAssumeRole] = map[string]any{
keyRoleArn: pc.Spec.AssumeRoleChain[0].RoleARN,
keyTags: pc.Spec.AssumeRoleChain[0].Tags,
keyTransitiveTagKeys: pc.Spec.AssumeRoleChain[0].TransitiveTagKeys,
keyExternalID: pc.Spec.AssumeRoleChain[0].ExternalID,
}
}
return nil
}

Expand Down

0 comments on commit 5672e7c

Please sign in to comment.