Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from radius-project:main #1

Open
wants to merge 141 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
4c85b6a
Updating Purge AWS Test Resources workflow (#7581)
ytimocin May 13, 2024
10627b0
Update bubbletea version and the unit test (#7526)
ytimocin May 13, 2024
0edd2b6
Bump the all group across 1 directory with 2 updates (#7591)
dependabot[bot] May 13, 2024
5fba423
Bump the all group across 1 directory with 4 updates (#7587)
dependabot[bot] May 13, 2024
427eed2
Update CLI client code and add tests (#7594)
rynowak May 16, 2024
a1cb280
add functional test results to artifacts (#7583)
nithyatsu May 16, 2024
af5e332
Stern - maxLogRequests option update (#7578)
ytimocin May 18, 2024
4537dfe
Bump the all group with 16 updates (#7615)
dependabot[bot] May 20, 2024
658dba7
fix for purge old container (#7616)
nithyatsu May 20, 2024
1a88d49
fix: close file (#7608)
testwill May 21, 2024
1af1fd8
Update Terraform recipe download error to include module version (#7620)
kachawla May 21, 2024
ea316f3
fix for rad init cannot work from folders with uppercase (#7617)
nithyatsu May 21, 2024
66aad2c
Add required_providers block to main.tf.config, functional test for T…
lakshmimsft May 21, 2024
4cacb58
Update kubebuilder to the latest working version (#7629)
sk593 May 23, 2024
950a256
Release 0.34.0-rc1: Update release version with RC1 (#7628)
sk593 May 23, 2024
1376150
Update release version 0.34 (#7633)
sk593 May 24, 2024
260c376
Bump the all group with 22 updates (#7635)
dependabot[bot] May 27, 2024
67f19d3
Update autorest related dependencies (#7636)
ytimocin May 28, 2024
f7ef3b2
Update purge workflow with manual trigger (#7622)
sk593 May 28, 2024
2b2b9d9
Revert "Update kubebuilder to the latest working version" (#7632)
sk593 May 28, 2024
0b6e13b
Update CNCF sandbox acceptance in README.md (#7639)
Reshrahim May 29, 2024
32e99aa
Update documentation on guideline for test images to be added to/pull…
lakshmimsft May 29, 2024
0cd0c8a
Fixing flaky config unit test (#7649)
ytimocin May 30, 2024
de7033d
Update purge workflow_dispatch logic (#7646)
sk593 May 30, 2024
85e1bcc
Fix purge workflow (#7653)
sk593 May 31, 2024
3ce1d0f
Adding support for terraform nested modules (#7519)
vishwahiremat May 31, 2024
b92cf6f
Update release docs (#7642)
sk593 May 31, 2024
869f120
Update instructions to publish bicep extension (#7579)
kachawla May 31, 2024
a8654c7
Bump the all group with 7 updates (#7656)
dependabot[bot] Jun 3, 2024
fe9355c
Fix for flaky unit test (#7654)
lakshmimsft Jun 3, 2024
d1a55c9
Adding EnableWebsockets property to the gateway (#7643)
ytimocin Jun 3, 2024
e3900e3
fixes #7592 - adding typed to mockgen (#7647)
superbeeny Jun 4, 2024
1ff7d17
Show correct environment and application for delete commands (#7669)
rynowak Jun 8, 2024
db6eeb2
Bump the all group with 10 updates (#7671)
dependabot[bot] Jun 10, 2024
a03a0c7
Remove extra files in TF recipe using azurerm (#7672)
lakshmimsft Jun 10, 2024
fd8d14e
Add upmerge instructions to release instructions (#7675)
willtsai Jun 10, 2024
eda496e
Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity from 1.5.1 to 1…
dependabot[bot] Jun 11, 2024
7ffcb23
Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity from 1.5.2 to 1…
dependabot[bot] Jun 12, 2024
9e9812a
Adding TypeSpec check to Lint workflow and running the TypeSpec forma…
ytimocin Jun 13, 2024
d7c5874
Adding the step to delete the created Azure resource group to the fun…
ytimocin Jun 15, 2024
5f7c51c
Bump the all group with 11 updates (#7689)
dependabot[bot] Jun 17, 2024
b2c8878
Bump mikefarah/yq from 4.44.1 to 4.44.2 in the all group (#7690)
dependabot[bot] Jun 17, 2024
d26a411
Switch Radius Helm chart pull from ACR to GHCR (#7455)
willdavsmith Jun 17, 2024
86b4397
Rename misspelled field (#7692)
rynowak Jun 17, 2024
b748443
Add Azure Workload Identity support (#7640)
willdavsmith Jun 18, 2024
e7a4ec9
Fix UCP test (#7694)
willdavsmith Jun 19, 2024
e253d7c
Fixing containerd should be direct warning by running go mod tidy (#7…
ytimocin Jun 19, 2024
3845082
Adding a test for annotations and labels to the existing k8s extensib…
ytimocin Jun 19, 2024
0b6ecc0
Release 0.35.0-rc1: Update release version with RC1 (#7698)
vishwahiremat Jun 19, 2024
d7031e2
Update release version 0.35 (#7701)
vishwahiremat Jun 21, 2024
3222fe9
Update wait time on postgres db in functional test (#7707)
lakshmimsft Jun 21, 2024
f1cdec3
Bump the all group with 14 updates (#7711)
dependabot[bot] Jun 24, 2024
95dce96
Updating dependencies manually (#7710)
ytimocin Jun 24, 2024
13d50f7
Update link in release notes highlights (#7712)
Reshrahim Jun 24, 2024
a8371ee
add IRSA credential type (#7708)
nithyatsu Jul 3, 2024
7ebd49e
Bump the all group with 13 updates (#7720)
dependabot[bot] Jul 5, 2024
534cba6
Bump the all group with 14 updates (#7729)
dependabot[bot] Jul 8, 2024
5d448d5
Fix prompt text test occasional failure (#7722)
brooke-hamilton Jul 8, 2024
ccc385f
Bump google.golang.org/grpc from 1.64.0 to 1.64.1 in the go_modules g…
dependabot[bot] Jul 9, 2024
b183209
Add secret support to Terraform Providers (backend updates) (#7695)
lakshmimsft Jul 13, 2024
00a3092
Fix broken link in contributing docs (#7736)
willdavsmith Jul 13, 2024
0782511
Bump the all group with 9 updates (#7737)
dependabot[bot] Jul 15, 2024
9b9cf3b
implement controllers for AWS IRSA (#7739)
nithyatsu Jul 16, 2024
faa6d3d
Add datamodel changes for secret support to Terraform Providers (#7731)
lakshmimsft Jul 18, 2024
2a4effe
Update release version v0.36.0-rc1 (#7742)
sk593 Jul 18, 2024
53e19b2
Update testrp and magpie Dockerfiles (#7745)
ytimocin Jul 19, 2024
fbed321
Update release version v0.36.0 (#7749)
sk593 Jul 22, 2024
a8f29eb
Bump the all group with 13 updates (#7751)
dependabot[bot] Jul 22, 2024
46bf036
Splitting functional tests as cloud and non-cloud (#7716)
ytimocin Jul 22, 2024
0dbbf5a
Reformatting the files in the scripts folder (#7755)
ytimocin Jul 22, 2024
594faf6
Update cyrilgdn/postgresql version in the postgres recipe (#7766)
ytimocin Jul 25, 2024
1127d12
Bump ossf/scorecard-action from 2.3.3 to 2.4.0 in the all group (#7769)
dependabot[bot] Jul 29, 2024
1c7b3ea
Bump the all group with 2 updates (#7768)
dependabot[bot] Jul 29, 2024
93ddbdb
Increasing `Test_TerraformRecipe_KubernetesPostgres` timeout to 2m (#…
willdavsmith Jul 29, 2024
c9b6581
implement irsa server side support (#7738)
nithyatsu Jul 29, 2024
9b77737
rad credential show - support for IRSA (#7757)
nithyatsu Jul 30, 2024
81b89fd
Adding rad install changes for AWS IRSA support (#7741)
vishwahiremat Jul 30, 2024
9b564db
"rad credential register aws" command changes for irsa (#7750)
vishwahiremat Jul 30, 2024
c62434f
Bump github.com/docker/docker from 27.0.0+incompatible to 27.1.0+inco…
dependabot[bot] Jul 30, 2024
78b52b1
Adding multi arch container image generation for magpie and testrp (#…
ytimocin Jul 31, 2024
a61a428
Updating and adding a timeout to the cleanup cluster step (#7727)
ytimocin Aug 1, 2024
b2ecfe8
Adding packages:write permission to the purge test resources workflow…
ytimocin Aug 1, 2024
be5da14
Update the registry in CLI functional test (#7779)
ytimocin Aug 2, 2024
4c9db50
Updating registry in the redis functional test (#7781)
ytimocin Aug 2, 2024
63490d6
Bump the all group with 3 updates (#7783)
dependabot[bot] Aug 5, 2024
4ba025d
Use local aws config in cli to get account and regions (#7758)
vishwahiremat Aug 5, 2024
a4a4b90
Adding rad init command changes to support irsa (#7761)
vishwahiremat Aug 6, 2024
83f57c2
Removing double imports found by staticcheck (#7791)
ytimocin Aug 8, 2024
3d96ee6
Adding a check to a cast to the Recipe object (#7797)
ytimocin Aug 9, 2024
5c10d92
Bicep compiler merge (#7662)
sk593 Aug 12, 2024
255c6d8
Update credential precedence in bicepconfig.json (#7803)
sk593 Aug 13, 2024
d01ecf9
Add warning when deleting an environment with existing applications (…
SoTrx Aug 13, 2024
9ed50f4
Replace Azure Service Principal auth with Azure Workload Identity aut…
willdavsmith Aug 13, 2024
f7c07fd
Bump the all group across 1 directory with 2 updates (#7802)
dependabot[bot] Aug 13, 2024
531d123
Bump github.com/docker/docker from 27.1.0+incompatible to 27.1.1+inco…
dependabot[bot] Aug 13, 2024
fb02873
Update error message value for LRT (#7810)
sk593 Aug 14, 2024
487081f
Update release version v0.37.0-rc1 (#7813)
vishwahiremat Aug 15, 2024
65ca82d
Update release version v0.37.0 (#7817)
vishwahiremat Aug 19, 2024
3cfb583
Add dependabot updates for bicep-types submodule (#7807)
sk593 Aug 19, 2024
6e18608
Bump bicep-types from `cd259b2` to `f0cd725` (#7821)
dependabot[bot] Aug 20, 2024
875c5ca
Remove unused test artifacts (#7824)
kachawla Aug 21, 2024
33d3d5e
Update validate workflow to test against PR specific schema changes …
sk593 Aug 21, 2024
7da87d4
Remove assets.yaml (#7832)
lakshmimsft Aug 22, 2024
a58b8cb
Temporarily disabling tests: `Test_Storage` and `Test_PersistentVolum…
willdavsmith Aug 28, 2024
84cb120
Update LoadSecrets() (#7796)
lakshmimsft Aug 29, 2024
50fef93
Add new secret types to Applications.Core/secretstores (#7816)
lakshmimsft Aug 29, 2024
940792c
Bump bicep-types from `f0cd725` to `49b2a9e` (#7843)
dependabot[bot] Aug 30, 2024
28fb22c
Fix doc links in kubernetes install command docs (#7849)
Reshrahim Aug 30, 2024
7232cc6
Updates to adding secret types PR (#7867)
lakshmimsft Aug 30, 2024
0c4a1bd
Bump the all group across 1 directory with 34 updates (#7858)
dependabot[bot] Sep 1, 2024
64da215
Bump bicep-types from `49b2a9e` to `99cdcee` (#7877)
dependabot[bot] Sep 2, 2024
96d5cf8
Bump the npm_and_yarn group across 2 directories with 2 updates (#7875)
dependabot[bot] Sep 3, 2024
3ddb61e
Adding Kubernetes native secrets to secret stores (#7744)
superbeeny Sep 3, 2024
5366a82
Fixes #7391 - fixing error in rad group show for no args (#7852)
superbeeny Sep 4, 2024
9091f8b
Add purge flag to delete radius related namespace (#7847)
lbzss Sep 5, 2024
dca3a27
Adding fix for publishing recipes to ECR (#7887)
vishwahiremat Sep 5, 2024
a1ab146
Support for secret store reference in Dapr components (#7823)
SoTrx Sep 5, 2024
dd81399
Add more Logging for cloud functional test workflow (#7885)
lakshmimsft Sep 5, 2024
cce1fe6
Add to debug logs for cloud functional test workflow (#7892)
lakshmimsft Sep 6, 2024
f89f424
Adding Bicep private registry support using basic auth, Azure workloa…
vishwahiremat Sep 9, 2024
8151a96
Add workflow condition in cloud functional tests (#7907)
lakshmimsft Sep 9, 2024
3d2825f
Remove radbicep references (#7894)
sk593 Sep 9, 2024
897f2aa
support deployment of an application to a scope "scope1" using enviro…
nithyatsu Sep 10, 2024
96fb582
Remove the error message added for debugging. (#7913)
vishwahiremat Sep 10, 2024
48c28ed
Release Radius v0.38.0-rc1 (#7920)
willdavsmith Sep 13, 2024
547fa81
Update version to 0.38 in versions.yaml (#7924)
ytimocin Sep 16, 2024
a5e97c3
Bump bicep-types from `99cdcee` to `d936309` (#7929)
dependabot[bot] Sep 16, 2024
a17f9cf
Implementation of Dapr Building Block: Configuration Store (#7906)
SoTrx Sep 18, 2024
69d6726
Updating and reformatting the release doc (#7933)
ytimocin Sep 19, 2024
50c1600
Update the timeout of the clean-up cluster step to 1h (#7938)
ytimocin Sep 19, 2024
a7395fb
Add dapr-sts* namespaces to be deleted to the clean-up workflow (#7942)
ytimocin Sep 19, 2024
cf639b4
Update golangci-lint version and fix new warnings (#7951)
ytimocin Sep 21, 2024
8f78e63
Improve validation and simplify database tests (#7949)
rynowak Sep 23, 2024
d13b0c4
Separating purge old images and purge Azure test resources workflows …
ytimocin Sep 23, 2024
62c6291
Bump peter-evans/create-pull-request from 6 to 7 in the all group (#7…
dependabot[bot] Sep 23, 2024
78751aa
Bump bicep-types from `d936309` to `ebba845` (#7957)
dependabot[bot] Sep 23, 2024
2df79ec
Add an in-memory data store (#7950)
rynowak Sep 23, 2024
24be8e6
Removing bicep workaround + minor cleanup (#7965)
sk593 Sep 27, 2024
b4c4d50
Update the bicep extension used in the dev container (#7969)
brooke-hamilton Sep 27, 2024
223ec1e
Implement PostgreSQL datastore (#7961)
rynowak Sep 27, 2024
ecd79d1
Add a PR Checklist for Contributions (#7921)
kachawla Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding rad init command changes to support irsa (radius-project#7761)
# Description

- Added changes to `rad init --full` command to add types i.e
accesskey,irsa while configuring aws provider

![image](https://github.com/user-attachments/assets/da396b4d-5877-4772-a247-9ef6cf0c9e79)
- And adding prompts to accept role arn
- refactoring the code with switch cases to handle it differently for
both cases.
- updated the tests


## Type of change

<!--

Please select **one** of the following options that describes your
change and delete the others. Clearly identifying the type of change you
are making will help us review your PR faster, and is used in authoring
release notes.

If you are making a bug fix or functionality change to Radius and do not
have an associated issue link please create one now.

-->

- This pull request fixes a bug in Radius and has an approved issue
(issue link required).
- This pull request adds or changes features of Radius and has an
approved issue (issue link required).
- This pull request is a minor refactor, code cleanup, test improvement,
or other maintenance task and doesn't change the functionality of Radius
(issue link optional).

<!--

Please update the following to link the associated issue. This is
required for some kinds of changes (see above).

-->

Fixes: #issue_number

---------

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>
  • Loading branch information
vishwahiremat authored Aug 6, 2024
commit a4a4b90a69d717ad3857807c1117cdab2ccef3a5
34 changes: 28 additions & 6 deletions pkg/cli/aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,44 @@ limitations under the License.

package aws

// AWSCredentialKind - AWS credential kinds supported.
type AWSCredentialKind string

const (
// ProviderDisplayName is the text used in display for AWS.
ProviderDisplayName = "AWS"
ProviderDisplayName = "AWS"
AWSCredentialKindAccessKey = "AccessKey"
AWSCredentialKindIRSA = "IRSA"
)

// Provider specifies the properties required to configure AWS provider for cloud resources.
type Provider struct {
// AccessKeyID is the access key id for the AWS account.
AccessKeyID string

// SecretAccessKey is the secret access key for the AWS account.
SecretAccessKey string

// Region is the AWS region to use.
Region string

// AccountID is the AWS account id.
AccountID string

// CredentialKind represents ucp credential kind for aws provider.
CredentialKind AWSCredentialKind

// AccessKey represents ucp credential kind for aws access key credentials.
AccessKey *AccessKeyCredential

// IRSA represents ucp credential kind for aws irsa credentials.
IRSA *IRSACredential
}

type AccessKeyCredential struct {
// AccessKeyID is the access key id for the AWS account.
AccessKeyID string

// SecretAccessKey is the secret access key for the AWS account.
SecretAccessKey string
}

type IRSACredential struct {
// RoleARN for AWS IRSA identity
RoleARN string
}
2 changes: 1 addition & 1 deletion pkg/cli/azure/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Provider struct {
ServicePrincipal *ServicePrincipalCredential
}

// Wor specifies the properties of an Azure service principal
// WorkloadIdentityCredential specifies the properties of an Azure service principal
type WorkloadIdentityCredential struct {
ClientID string
TenantID string
Expand Down
102 changes: 80 additions & 22 deletions pkg/cli/cmd/radinit/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import (

const (
selectAWSRegionPrompt = "Select the region you would like to deploy AWS resources to:"
selectAWSCredentialKindPrompt = "Select a credential kind for the AWS credential:"
enterAWSIAMAcessKeyIDPrompt = "Enter the IAM access key id:"
enterAWSRoleARNPrompt = "Enter the role ARN:"
enterAWSRoleARNPlaceholder = "Enter IAM role ARN..."
enterAWSIAMAcessKeyIDPlaceholder = "Enter IAM access key id..."
enterAWSIAMSecretAccessKeyPrompt = "Enter your IAM Secret Access Key:"
enterAWSIAMSecretAccessKeyPlaceholder = "Enter IAM secret access key..."
Expand All @@ -39,37 +42,80 @@ const (
enterAWSAccountIDPlaceholder = "Enter the account ID you want to use..."

awsAccessKeysCreateInstructionFmt = "\nAWS IAM Access keys (Access key ID and Secret access key) are required to access and create AWS resources.\n\nFor example, you can create one using the following command:\n\033[36maws iam create-access-key\033[0m\n\nFor more information refer to https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html.\n\n"
awsIRSACredentialKind = "IRSA"
awsAccessKeyCredentialKind = "Access Key"
)

func (r *Runner) enterAWSCloudProvider(ctx context.Context) (*aws.Provider, error) {
r.Output.LogInfo(awsAccessKeysCreateInstructionFmt)

accessKeyID, err := r.Prompter.GetTextInput(enterAWSIAMAcessKeyIDPrompt, prompt.TextInputOptions{Placeholder: enterAWSIAMAcessKeyIDPlaceholder})
func (r *Runner) enterAWSCloudProvider(ctx context.Context, options *initOptions) (*aws.Provider, error) {
credentialKind, err := r.selectAWSCredentialKind()
if err != nil {
return nil, err
}

secretAccessKey, err := r.Prompter.GetTextInput(enterAWSIAMSecretAccessKeyPrompt, prompt.TextInputOptions{Placeholder: enterAWSIAMSecretAccessKeyPlaceholder, EchoMode: textinput.EchoPassword})
if err != nil {
return nil, err
}
switch credentialKind {
case awsAccessKeyCredentialKind:
r.Output.LogInfo(awsAccessKeysCreateInstructionFmt)

accountId, err := r.getAccountId(ctx)
if err != nil {
return nil, err
}
accessKeyID, err := r.Prompter.GetTextInput(enterAWSIAMAcessKeyIDPrompt, prompt.TextInputOptions{Placeholder: enterAWSIAMAcessKeyIDPlaceholder})
if err != nil {
return nil, err
}

region, err := r.selectAWSRegion(ctx)
if err != nil {
return nil, err
}
secretAccessKey, err := r.Prompter.GetTextInput(enterAWSIAMSecretAccessKeyPrompt, prompt.TextInputOptions{Placeholder: enterAWSIAMSecretAccessKeyPlaceholder, EchoMode: textinput.EchoPassword})
if err != nil {
return nil, err
}

return &aws.Provider{
AccessKeyID: accessKeyID,
SecretAccessKey: secretAccessKey,
AccountID: accountId,
Region: region,
}, nil
accountId, err := r.getAccountId(ctx)
if err != nil {
return nil, err
}

region, err := r.selectAWSRegion(ctx)
if err != nil {
return nil, err
}

return &aws.Provider{
AccessKey: &aws.AccessKeyCredential{
AccessKeyID: accessKeyID,
SecretAccessKey: secretAccessKey,
},
CredentialKind: aws.AWSCredentialKindAccessKey,
AccountID: accountId,
Region: region,
}, nil
case awsIRSACredentialKind:
r.Output.LogInfo(awsAccessKeysCreateInstructionFmt)

roleARN, err := r.Prompter.GetTextInput(enterAWSRoleARNPrompt, prompt.TextInputOptions{Placeholder: enterAWSRoleARNPlaceholder})
if err != nil {
return nil, err
}

accountId, err := r.getAccountId(ctx)
if err != nil {
return nil, err
}

region, err := r.selectAWSRegion(ctx)
if err != nil {
return nil, err
}

// Set the value for the Helm chart
options.SetValues = append(options.SetValues, "global.aws.irsa.enabled=true")
return &aws.Provider{
AccountID: accountId,
Region: region,
CredentialKind: aws.AWSCredentialKindIRSA,
IRSA: &aws.IRSACredential{
RoleARN: roleARN,
},
}, nil
default:
return nil, clierrors.Message("Invalid AWS credential kind: %s", credentialKind)
}
}

func (r *Runner) getAccountId(ctx context.Context) (string, error) {
Expand Down Expand Up @@ -123,3 +169,15 @@ func (r *Runner) buildAWSRegionsList(listRegionsOutput *ec2.DescribeRegionsOutpu

return regions
}

func (r *Runner) selectAWSCredentialKind() (string, error) {
credentialKinds := r.buildAWSCredentialKind()
return r.Prompter.GetListInput(credentialKinds, selectAWSCredentialKindPrompt)
}

func (r *Runner) buildAWSCredentialKind() []string {
return []string{
awsAccessKeyCredentialKind,
awsIRSACredentialKind,
}
}
52 changes: 46 additions & 6 deletions pkg/cli/cmd/radinit/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"go.uber.org/mock/gomock"
)

func Test_enterAWSCloudProvider(t *testing.T) {
func Test_enterAWSCloudProvider_AccessKey(t *testing.T) {
ctrl := gomock.NewController(t)
prompter := prompt.NewMockInterface(ctrl)
client := aws.NewMockClient(ctrl)
Expand All @@ -43,21 +43,61 @@ func Test_enterAWSCloudProvider(t *testing.T) {
}
regions := []string{"region", "region2"}

setAWSCredentialKindPrompt(prompter, "Access Key")
setAWSAccessKeyIDPrompt(prompter, "access-key-id")
setAWSSecretAccessKeyPrompt(prompter, "secret-access-key")
setAWSCallerIdentity(client, &sts.GetCallerIdentityOutput{Account: to.Ptr("account-id")})
setAWSAccountIDConfirmPrompt(prompter, "account-id", prompt.ConfirmYes)
setAWSListRegions(client, &ec2.DescribeRegionsOutput{Regions: ec2Regions})
setAWSRegionPrompt(prompter, regions, "region")

provider, err := runner.enterAWSCloudProvider(context.Background())
options := &initOptions{}
provider, err := runner.enterAWSCloudProvider(context.Background(), options)
require.NoError(t, err)

expected := &aws.Provider{
AccessKeyID: "access-key-id",
SecretAccessKey: "secret-access-key",
Region: "region",
AccountID: "account-id",
AccessKey: &aws.AccessKeyCredential{
AccessKeyID: "access-key-id",
SecretAccessKey: "secret-access-key",
},
CredentialKind: "AccessKey",
Region: "region",
AccountID: "account-id",
}
require.Equal(t, expected, provider)
require.Equal(t, []any{output.LogOutput{Format: awsAccessKeysCreateInstructionFmt}}, outputSink.Writes)
}

func Test_enterAWSCloudProvider_IRSA(t *testing.T) {
ctrl := gomock.NewController(t)
prompter := prompt.NewMockInterface(ctrl)
client := aws.NewMockClient(ctrl)
outputSink := output.MockOutput{}
runner := Runner{Prompter: prompter, awsClient: client, Output: &outputSink}
ec2Regions := []ec2_types.Region{
{RegionName: to.Ptr("region")},
{RegionName: to.Ptr("region2")},
}
regions := []string{"region", "region2"}

setAWSCredentialKindPrompt(prompter, "IRSA")
setAwsIRSARoleARNPrompt(prompter, "role-arn")
setAWSCallerIdentity(client, &sts.GetCallerIdentityOutput{Account: to.Ptr("account-id")})
setAWSAccountIDConfirmPrompt(prompter, "account-id", prompt.ConfirmYes)
setAWSListRegions(client, &ec2.DescribeRegionsOutput{Regions: ec2Regions})
setAWSRegionPrompt(prompter, regions, "region")

options := &initOptions{}
provider, err := runner.enterAWSCloudProvider(context.Background(), options)
require.NoError(t, err)

expected := &aws.Provider{
IRSA: &aws.IRSACredential{
RoleARN: "role-arn",
},
CredentialKind: "IRSA",
Region: "region",
AccountID: "account-id",
}
require.Equal(t, expected, provider)
require.Equal(t, []any{output.LogOutput{Format: awsAccessKeysCreateInstructionFmt}}, outputSink.Writes)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/radinit/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r *Runner) enterCloudProviderOptions(ctx context.Context, options *initOpt

options.CloudProviders.Azure = provider
case aws.ProviderDisplayName:
provider, err := r.enterAWSCloudProvider(ctx)
provider, err := r.enterAWSCloudProvider(ctx, options)
if err != nil {
return err
}
Expand Down
65 changes: 52 additions & 13 deletions pkg/cli/cmd/radinit/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,23 @@ func Test_enterCloudProviderOptions(t *testing.T) {
},
}

awsProvider := aws.Provider{
Region: "test-region",
AccessKeyID: "test-access-key-id",
SecretAccessKey: "test-secret-access-key",
AccountID: "test-account-id",
awsProviderAccessKey := aws.Provider{
Region: "test-region",
CredentialKind: "AccessKey",
AccessKey: &aws.AccessKeyCredential{
AccessKeyID: "test-access-key-id",
SecretAccessKey: "test-secret-access-key",
},
AccountID: "test-account-id",
}

awsProviderIRSA := aws.Provider{
Region: "test-region",
CredentialKind: "IRSA",
IRSA: &aws.IRSACredential{
RoleARN: "test-role-arn",
},
AccountID: "test-account-id",
}

t.Run("cloud providers skipped when no flags specified", func(t *testing.T) {
Expand Down Expand Up @@ -114,7 +126,7 @@ func Test_enterCloudProviderOptions(t *testing.T) {
require.Empty(t, outputSink.Writes)
})

t.Run("--full - aws provider", func(t *testing.T) {
t.Run("--full - aws provider - accesskey", func(t *testing.T) {
ctrl := gomock.NewController(t)
prompter := prompt.NewMockInterface(ctrl)
awsClient := aws.NewMockClient(ctrl)
Expand All @@ -124,14 +136,41 @@ func Test_enterCloudProviderOptions(t *testing.T) {

initAddCloudProviderPromptYes(prompter)
initSelectCloudProvider(prompter, aws.ProviderDisplayName)
setAWSCloudProvider(prompter, awsClient, awsProvider)
setAWSCloudProviderAccessKey(prompter, awsClient, awsProviderAccessKey)
initAddCloudProviderPromptNo(prompter)

options := initOptions{Environment: environmentOptions{Create: true}}
err := runner.enterCloudProviderOptions(context.Background(), &options)
require.NoError(t, err)
require.Nil(t, options.CloudProviders.Azure)
require.Equal(t, awsProvider, *options.CloudProviders.AWS)
require.Equal(t, awsProviderAccessKey, *options.CloudProviders.AWS)

expectedWrites := []any{
output.LogOutput{
Format: awsAccessKeysCreateInstructionFmt,
},
}
require.Equal(t, expectedWrites, outputSink.Writes)
})

t.Run("--full - aws provider - irsa", func(t *testing.T) {
ctrl := gomock.NewController(t)
prompter := prompt.NewMockInterface(ctrl)
awsClient := aws.NewMockClient(ctrl)
azureClient := azure.NewMockClient(ctrl)
outputSink := output.MockOutput{}
runner := Runner{Prompter: prompter, awsClient: awsClient, azureClient: azureClient, Output: &outputSink, Full: true}

initAddCloudProviderPromptYes(prompter)
initSelectCloudProvider(prompter, aws.ProviderDisplayName)
setAWSCloudProviderIRSA(prompter, awsClient, awsProviderIRSA)
initAddCloudProviderPromptNo(prompter)

options := initOptions{Environment: environmentOptions{Create: true}}
err := runner.enterCloudProviderOptions(context.Background(), &options)
require.NoError(t, err)
require.Nil(t, options.CloudProviders.Azure)
require.Equal(t, awsProviderIRSA, *options.CloudProviders.AWS)

expectedWrites := []any{
output.LogOutput{
Expand Down Expand Up @@ -206,7 +245,7 @@ func Test_enterCloudProviderOptions(t *testing.T) {

initAddCloudProviderPromptYes(prompter)
initSelectCloudProvider(prompter, aws.ProviderDisplayName)
setAWSCloudProvider(prompter, awsClient, awsProvider)
setAWSCloudProviderAccessKey(prompter, awsClient, awsProviderAccessKey)

initAddCloudProviderPromptYes(prompter)
initSelectCloudProvider(prompter, azure.ProviderDisplayName)
Expand All @@ -217,7 +256,7 @@ func Test_enterCloudProviderOptions(t *testing.T) {
options := initOptions{Environment: environmentOptions{Create: true}}
err := runner.enterCloudProviderOptions(context.Background(), &options)
require.NoError(t, err)
require.Equal(t, awsProvider, *options.CloudProviders.AWS)
require.Equal(t, awsProviderAccessKey, *options.CloudProviders.AWS)
require.Equal(t, azureProviderServicePrincipal, *options.CloudProviders.Azure)

expectedWrites := []any{
Expand All @@ -243,13 +282,13 @@ func Test_enterCloudProviderOptions(t *testing.T) {

initAddCloudProviderPromptYes(prompter)
initSelectCloudProvider(prompter, aws.ProviderDisplayName)
setAWSCloudProvider(prompter, awsClient, awsProvider)
setAWSCloudProviderAccessKey(prompter, awsClient, awsProviderAccessKey)

awsProvider := awsProvider
awsProvider := awsProviderAccessKey
awsProvider.Region = "another-region"
initAddCloudProviderPromptYes(prompter)
initSelectCloudProvider(prompter, aws.ProviderDisplayName)
setAWSCloudProvider(prompter, awsClient, awsProvider)
setAWSCloudProviderAccessKey(prompter, awsClient, awsProvider)

initAddCloudProviderPromptNo(prompter)

Expand Down
Loading