From 9ca102b06fcddc64e1f88e3f722cb51a3cf729a1 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Wed, 31 May 2023 10:16:26 -0700 Subject: [PATCH] Update time offset update/read (#214) --- resources/Time_Offset/.gitignore | 2 ++ resources/Time_Offset/.rpdk-config | 3 ++- .../Time_Offset/cmd/resource/resource.go | 20 ++++++++++++++++++- resources/Time_Offset/makebuild | 2 +- resources/Time_Offset/requirements.txt | 2 ++ 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 resources/Time_Offset/requirements.txt diff --git a/resources/Time_Offset/.gitignore b/resources/Time_Offset/.gitignore index 5c7bffc7..2295add0 100644 --- a/resources/Time_Offset/.gitignore +++ b/resources/Time_Offset/.gitignore @@ -15,3 +15,5 @@ vender/ sam-tests/ .hypothesis/ /awscommunity-time-offset.zip + +.venv diff --git a/resources/Time_Offset/.rpdk-config b/resources/Time_Offset/.rpdk-config index c21cbf36..7602bb1e 100644 --- a/resources/Time_Offset/.rpdk-config +++ b/resources/Time_Offset/.rpdk-config @@ -16,6 +16,7 @@ "region": null, "target_schemas": [], "import_path": "github.com/aws-cloudformation/awscommunity-registry-extensions/resources/Time_Offset", - "protocolVersion": "2.0.0" + "protocolVersion": "2.0.0", + "pluginVersion": "2.0.4" } } diff --git a/resources/Time_Offset/cmd/resource/resource.go b/resources/Time_Offset/cmd/resource/resource.go index 38c15b3d..80af89e5 100644 --- a/resources/Time_Offset/cmd/resource/resource.go +++ b/resources/Time_Offset/cmd/resource/resource.go @@ -146,7 +146,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists, + HandlerErrorCode: cloudformation.HandlerErrorCodeInternalFailure, ResourceModel: nil, }, nil } @@ -154,6 +154,24 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler // convert a timestamp into the model so we have all the attributes timeToModel(currentModel, t) + // Save the unique identifier in SSM if it exists its a duplicate + jsonData, _ := json.Marshal(currentModel) + _, err = svc.PutParameter(&ssm.PutParameterInput{ + Name: &ssmParameter, + Value: aws.String(string(jsonData)), + Overwrite: aws.Bool(true), + Tier: aws.String("Standard"), + Type: aws.String("String"), + }) + if err != nil { + return handler.ProgressEvent{ + OperationStatus: handler.Failed, + Message: err.Error(), + HandlerErrorCode: cloudformation.HandlerErrorCodeInternalFailure, + ResourceModel: nil, + }, nil + } + response := handler.ProgressEvent{ OperationStatus: handler.Success, Message: "Create complete", diff --git a/resources/Time_Offset/makebuild b/resources/Time_Offset/makebuild index 390b673b..78049149 100644 --- a/resources/Time_Offset/makebuild +++ b/resources/Time_Offset/makebuild @@ -4,4 +4,4 @@ .PHONY: build build: cfn generate - env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -tags="$(TAGS)" -o bin/handler cmd/main.go + env GOOS=linux go build -ldflags="-s -w" -tags="$(TAGS)" -o bin/handler cmd/main.go diff --git a/resources/Time_Offset/requirements.txt b/resources/Time_Offset/requirements.txt new file mode 100644 index 00000000..5405f3a4 --- /dev/null +++ b/resources/Time_Offset/requirements.txt @@ -0,0 +1,2 @@ +cloudformation-cli==0.2.28 +cloudformation-cli-go-plugin==2.0.4