Skip to content

Commit

Permalink
fix stack delete behavior to not attempt to delete configured lambda …
Browse files Browse the repository at this point in the history
…roles. (Closes #787) (#788)

* Corrections to CONTRIBUTING.md

Running `make test` fails unless the `-modtime` option to `go-bindata` is available.
The jteeuwen fork lacks such an option.
My assumption is that at some point this project migrated from the jteeuwen fork to the shuLhan fork and failed to update the contributing docs.

Also, a minor typo correction.

* Don't attempt to delete a configured lambda role (fixes #787)

This makes the behavior of delete stack match create stack (if there's a role configured, skip doing anything regarding the role).
  • Loading branch information
davidmc24 authored and tj committed Nov 21, 2019
1 parent 13dbe84 commit 7f683a9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Before contributing to Up you'll need a few things:
The following are optional:

- Install [pointlander/peg](https://github.com/pointlander/peg) if you're working on the log grammar
- Install [jteeuwen/go-bindata](https://github.com/jteeuwen/go-bindata) if you need to bake `up-proxy` into `up`
- Install [shuLhan/go-bindata](https://github.com/shuLhan/go-bindata) if you need to bake `up-proxy` into `up`

## Setup

Expand Down Expand Up @@ -43,7 +43,7 @@ Although Up is not provided as a library it is structured as if it was, for orga
- [config](config) – Configuration structures and validation for `up.json`
- [cmd](cmd) – Commands, where `up` is the CLI and `up-proxy` is serving requests in production

Note that this is just a first past, and the code / layout will be refactored. View [Godoc](http://godoc.org/github.com/apex/up) for more details of the internals.
Note that this is just a first pass, and the code / layout will be refactored. View [Godoc](http://godoc.org/github.com/apex/up) for more details of the internals.

## Proxy

Expand Down
6 changes: 6 additions & 0 deletions platform/lambda/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,12 @@ func (p *Platform) roleName() string {
func (p *Platform) deleteRole(region string) error {
name := fmt.Sprintf("%s-function", p.config.Name)
c := iam.New(session.New(aws.NewConfig().WithRegion(region)))

// role is provided
if s := p.config.Lambda.Role; s != "" {
log.Debugf("using role from config %s; not deleting", s)
return nil
}

_, err := c.DeleteRolePolicy(&iam.DeleteRolePolicyInput{
RoleName: &name,
Expand Down
29 changes: 29 additions & 0 deletions platform/lambda/lambda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/acm"
"github.com/tj/assert"

"github.com/apex/up/config"
"github.com/apex/up/platform/event"
)

func TestGetCert(t *testing.T) {
Expand Down Expand Up @@ -55,3 +58,29 @@ func TestGetCert(t *testing.T) {
arn = getCert(certs, "staging.v1.api.example.com")
assert.Empty(t, arn)
}

func TestCreateRole(t *testing.T) {
t.Run("doesn't attempt to create configured role", func(t *testing.T) {
c := &config.Config{
Lambda: config.Lambda{
Role: "custom-role-name",
},
}
events := make(event.Events)
p := New(c, events)
assert.NoError(t, p.createRole(), "createRole")
})
}

func TestDeleteRole(t *testing.T) {
t.Run("doesn't attempt to delete configured role", func(t *testing.T) {
c := &config.Config{
Lambda: config.Lambda{
Role: "custom-role-name",
},
}
events := make(event.Events)
p := New(c, events)
assert.NoError(t, p.deleteRole("us-west-2"), "deleteRole")
})
}

0 comments on commit 7f683a9

Please sign in to comment.