Skip to content

Commit

Permalink
Merge pull request #58 from asalkeld/aws-resource-group
Browse files Browse the repository at this point in the history
Create an Aws resource group that contains all created resources
  • Loading branch information
tjholm authored Feb 3, 2022
2 parents 4408494 + c44c866 commit 78d1f1c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
32 changes: 27 additions & 5 deletions pkg/cmd/deployment/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/nitrictech/newcli/pkg/provider"
"github.com/nitrictech/newcli/pkg/stack"
"github.com/nitrictech/newcli/pkg/target"
"github.com/nitrictech/newcli/pkg/tasklet"
)

var deploymentName string
Expand Down Expand Up @@ -71,10 +72,23 @@ nitric deployment apply -n prod-aws -s ../project/ -t prod "functions/*.ts"
p, err := provider.NewProvider(s, t)
cobra.CheckErr(err)

err = build.Create(s, t)
cobra.CheckErr(err)

cobra.CheckErr(p.Apply(deploymentName))
buildImages := tasklet.Runner{
StartMsg: "Building Images",
Runner: func(tCtx tasklet.TaskletContext) error {
return build.Create(s, t)
},
StopMsg: "Images built!",
}
tasklet.MustRun(buildImages, tasklet.Opts{})

deploy := tasklet.Runner{
StartMsg: "Deploying..",
Runner: func(tCtx tasklet.TaskletContext) error {
return p.Apply(deploymentName)
},
StopMsg: "Deployment complete!",
}
tasklet.MustRun(deploy, tasklet.Opts{})
},
Args: cobra.MinimumNArgs(0),
}
Expand All @@ -97,7 +111,15 @@ nitric deployment delete -n prod-aws -s ../project/ -t prod
p, err := provider.NewProvider(s, t)
cobra.CheckErr(err)

cobra.CheckErr(p.Delete(deploymentName))
deploy := tasklet.Runner{
StartMsg: "Deleting..",
Runner: func(tCtx tasklet.TaskletContext) error {
return p.Delete(deploymentName)
},
StopMsg: "Deployment deleted!",
}
tasklet.MustRun(deploy, tasklet.Opts{})

},
Args: cobra.ExactArgs(0),
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/provider/pulumi/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ package aws

import (
"context"
"encoding/json"
"io/ioutil"
"os"

"github.com/pkg/errors"
"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/dynamodb"
"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ecr"
"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/resourcegroups"
"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/s3"
"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/sns"
"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/sqs"
Expand Down Expand Up @@ -75,6 +77,28 @@ func (a *awsProvider) Deploy(ctx *pulumi.Context) error {
return err
}

rgQueryJSON, err := json.Marshal(map[string]interface{}{
"ResourceTypeFilters": []string{"AWS::AllSupported"},
"TagFilters": []interface{}{
map[string]interface{}{
"Key": "x-nitric-stack",
"Values": []string{ctx.Stack()},
},
},
})
if err != nil {
return errors.WithMessage(err, "resource group json marshal")
}

_, err = resourcegroups.NewGroup(ctx, ctx.Stack(), &resourcegroups.GroupArgs{
ResourceQuery: &resourcegroups.GroupResourceQueryArgs{
Query: pulumi.String(rgQueryJSON),
},
})
if err != nil {
return errors.WithMessage(err, "resource group create")
}

topics := map[string]*sns.Topic{}
for k := range a.s.Topics {
topics[k], err = sns.NewTopic(ctx, k, &sns.TopicArgs{Tags: commonTags(ctx, k)})
Expand Down

0 comments on commit 78d1f1c

Please sign in to comment.