Skip to content

Commit

Permalink
Refactored from -expired-workspace -protected-workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Withers committed Jun 22, 2020
1 parent c2fd5ae commit 4e7307f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ we need an automated way to destroy these environments, so they don't sit around

So what is the purpose of this? Well, when you create a new environment using a terraform workspace using this you can add the workspace you have
created in your automated pipeline into a DynamoDB table with a TTL value. You can then set up an automated job to also use this tool to
pull expired workspaces from DynamoDB
pull protected workspaces from DynamoDB

## Creating the DynamoDB table

Expand All @@ -26,13 +26,13 @@ module "workspace-cleanup" {

```
Usage: tf-workspace-cleanup -register-workspace=<workspace> -aws-account-id=12345678 -aws-iam-role=operator
Usage: tf-workspace-cleanup -expired-workspaces=true -aws-account-id=12345678 -aws-iam-role=operator
Usage: tf-workspace-cleanup -protected-workspaces=true -aws-account-id=12345678 -aws-iam-role=operator
-aws-account-id string
Account ID for IAM Role
-aws-iam-role string
AWS IAM Role Name
-expired-workspaces
get list of expired workspaces for deletion
-protected-workspaces
get list of protected workspaces for deletion
-register-workspace string
Register a workspace to be deleted at a later point
```
2 changes: 1 addition & 1 deletion cmd/retrieve_registered_workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Item struct {
WorkspaceName string
}

func RetrieveExpiredWorkspaces(accountId *string, iamRoleName *string) {
func RetrieveProtectedWorkspaces(accountId *string, iamRoleName *string) {

sess, err := session.NewSession()
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
func main() {
flag.Usage = func() {
fmt.Println("Usage: tf-workspace-cleanup -register-workspace=<workspace> -aws-account-id=12345678 -aws-iam-role=sirius-ci")
fmt.Println("Usage: tf-workspace-cleanup -expired-workspaces=true -aws-account-id=12345678 -aws-iam-role=sirius-ci")
fmt.Println("Usage: tf-workspace-cleanup -protected-workspaces=true -aws-account-id=12345678 -aws-iam-role=sirius-ci")
flag.PrintDefaults()
}
var workspaceName string
var expiredWorkspaces bool
var protectedWorkspaces bool
var awsAccountId string
var awsIAMRoleName string

flag.StringVar(&workspaceName, "register-workspace", "", "Register a workspace to be deleted at a later point")
flag.StringVar(&awsAccountId, "aws-account-id", "", "Account ID for IAM Role")
flag.StringVar(&awsIAMRoleName, "aws-iam-role", "", "AWS IAM Role Name ")
flag.BoolVar(&expiredWorkspaces, "expired-workspaces", false, "get list of expired workspaces for deletion")
flag.BoolVar(&protectedWorkspaces, "protected-workspaces", false, "get list of protected workspaces for deletion")
flag.Parse()

if awsAccountId == "" {
Expand All @@ -33,13 +33,13 @@ func main() {
flag.Usage()
}

if expiredWorkspaces {
cmd.RetrieveExpiredWorkspaces(&awsAccountId, &awsIAMRoleName)
if protectedWorkspaces {
cmd.RetrieveProtectedWorkspaces(&awsAccountId, &awsIAMRoleName)
}

if workspaceName != "" {
cmd.RegisterWorkspace(&workspaceName, &awsAccountId, &awsIAMRoleName)
} else if expiredWorkspaces != true {
} else if protectedWorkspaces != true {
fmt.Println("Error: Workspace not passed")
flag.Usage()
}
Expand Down

0 comments on commit 4e7307f

Please sign in to comment.