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

Add --role-arn option for deploy sub command. #81

Merged
merged 3 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion internal/aws/cfn/cfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func GetStackEvents(stackName string) ([]types.StackEvent, error) {
}

// CreateChangeSet creates a changeset
func CreateChangeSet(template cft.Template, params []types.Parameter, tags map[string]string, stackName string) (string, error) {
func CreateChangeSet(template cft.Template, params []types.Parameter, tags map[string]string, stackName string, roleArn string) (string, error) {
templateBody, err := checkTemplate(template)
if err != nil {
return "", err
Expand Down Expand Up @@ -192,6 +192,10 @@ func CreateChangeSet(template cft.Template, params []types.Parameter, tags map[s
},
}

if roleArn != "" {
input.RoleARN = ptr.String(roleArn)
}

if strings.HasPrefix(templateBody, "http://") {
input.TemplateURL = ptr.String(templateBody)
} else {
Expand Down
4 changes: 3 additions & 1 deletion internal/aws/cfn/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type mockChangeSet struct {
params []types.Parameter
tags map[string]string
stackName string
roleArn string
}

type regionConfig struct {
Expand Down Expand Up @@ -159,14 +160,15 @@ func GetStackEvents(stackName string) ([]types.StackEvent, error) {
}

// CreateChangeSet creates a changeset
func CreateChangeSet(template cft.Template, params []types.Parameter, tags map[string]string, stackName string) (string, error) {
func CreateChangeSet(template cft.Template, params []types.Parameter, tags map[string]string, stackName string, roleArn string) (string, error) {
name := uuid.New().String()

region().changeSets[name] = &mockChangeSet{
template: template,
params: params,
tags: tags,
stackName: stackName,
roleArn: roleArn,
}

return name, nil
Expand Down
4 changes: 3 additions & 1 deletion internal/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var tags []string
var configFilePath string
var terminationProtection bool
var keep bool
var roleArn string

// Cmd is the deploy command's entrypoint
var Cmd = &cobra.Command{
Expand Down Expand Up @@ -156,7 +157,7 @@ Tags:

// Create change set
spinner.Push("Creating change set")
changeSetName, createErr := cfn.CreateChangeSet(template, parameters, combinedTags, stackName)
changeSetName, createErr := cfn.CreateChangeSet(template, parameters, parsedTags, stackName, roleArn)
if createErr != nil {
panic(ui.Errorf(createErr, "error creating changeset"))
}
Expand Down Expand Up @@ -243,4 +244,5 @@ func init() {
Cmd.Flags().StringVarP(&configFilePath, "config", "c", "", "YAML or JSON file to set tags and parameters.")
Cmd.Flags().BoolVarP(&terminationProtection, "termination-protection", "t", false, "Enable termination protection on the stack.")
Cmd.Flags().BoolVarP(&keep, "keep", "k", false, "Keep deployed resources after a failure by disabling rollbacks.")
Cmd.Flags().StringVarP(&roleArn, "role-arn", "", "", "The ARN of IAM role that AWS CloudFormation assumes to deploy the stack.")
}
1 change: 1 addition & 0 deletions internal/cmd/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func Example_deploy_help() {
// -h, --help help for deploy
// -k, --keep Keep deployed resources after a failure by disabling rollbacks.
// --params strings Set parameter values. Use the format key1=value1,key2=value2.
// --role-arn string The ARN of IAM role that AWS CloudFormation assumes to deploy the stack.
// --tags strings Add tags to the stack. Use the format key1=value1,key2=value2.
// -t, --termination-protection Enable termination protection on the stack.
// -y, --yes Don't ask questions; just deploy.
Expand Down