From c862572d9b58fe32f719f51e9c768ef84dbb68d4 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Thu, 3 Feb 2022 12:14:50 +1000 Subject: [PATCH 1/2] feat(aws): Create a resourceGroup that contains all the resources that we create reference: NITRIC-18 --- pkg/provider/pulumi/aws/aws.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/provider/pulumi/aws/aws.go b/pkg/provider/pulumi/aws/aws.go index fc28c8104..32d2d7ab1 100644 --- a/pkg/provider/pulumi/aws/aws.go +++ b/pkg/provider/pulumi/aws/aws.go @@ -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" @@ -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)}) From c44c866c3ed2f35c1aa8d15cd29b1de33248cb3e Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Thu, 3 Feb 2022 13:00:37 +1000 Subject: [PATCH 2/2] feat(deployment): Add tasklets for major tasks for better output --- pkg/cmd/deployment/root.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/deployment/root.go b/pkg/cmd/deployment/root.go index 803d1cf27..b6abdb30b 100644 --- a/pkg/cmd/deployment/root.go +++ b/pkg/cmd/deployment/root.go @@ -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 @@ -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), } @@ -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), }