Skip to content

Commit 7f683a9

Browse files
davidmc24tj
authored andcommitted
fix stack delete behavior to not attempt to delete configured lambda 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).
1 parent 13dbe84 commit 7f683a9

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Before contributing to Up you'll need a few things:
77
The following are optional:
88

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

1212
## Setup
1313

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

46-
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.
46+
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.
4747

4848
## Proxy
4949

platform/lambda/lambda.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,12 @@ func (p *Platform) roleName() string {
814814
func (p *Platform) deleteRole(region string) error {
815815
name := fmt.Sprintf("%s-function", p.config.Name)
816816
c := iam.New(session.New(aws.NewConfig().WithRegion(region)))
817+
818+
// role is provided
819+
if s := p.config.Lambda.Role; s != "" {
820+
log.Debugf("using role from config %s; not deleting", s)
821+
return nil
822+
}
817823

818824
_, err := c.DeleteRolePolicy(&iam.DeleteRolePolicyInput{
819825
RoleName: &name,

platform/lambda/lambda_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"github.com/aws/aws-sdk-go/aws"
77
"github.com/aws/aws-sdk-go/service/acm"
88
"github.com/tj/assert"
9+
10+
"github.com/apex/up/config"
11+
"github.com/apex/up/platform/event"
912
)
1013

1114
func TestGetCert(t *testing.T) {
@@ -55,3 +58,29 @@ func TestGetCert(t *testing.T) {
5558
arn = getCert(certs, "staging.v1.api.example.com")
5659
assert.Empty(t, arn)
5760
}
61+
62+
func TestCreateRole(t *testing.T) {
63+
t.Run("doesn't attempt to create configured role", func(t *testing.T) {
64+
c := &config.Config{
65+
Lambda: config.Lambda{
66+
Role: "custom-role-name",
67+
},
68+
}
69+
events := make(event.Events)
70+
p := New(c, events)
71+
assert.NoError(t, p.createRole(), "createRole")
72+
})
73+
}
74+
75+
func TestDeleteRole(t *testing.T) {
76+
t.Run("doesn't attempt to delete configured role", func(t *testing.T) {
77+
c := &config.Config{
78+
Lambda: config.Lambda{
79+
Role: "custom-role-name",
80+
},
81+
}
82+
events := make(event.Events)
83+
p := New(c, events)
84+
assert.NoError(t, p.deleteRole("us-west-2"), "deleteRole")
85+
})
86+
}

0 commit comments

Comments
 (0)