Skip to content

Commit

Permalink
feat(resource): adding support for codedeploy deployment configs and …
Browse files Browse the repository at this point in the history
…groups
  • Loading branch information
swhite-oreilly authored and ekristen committed Oct 1, 2024

Verified

This commit was signed with the committer’s verified signature.
abernix Jesse Rosenberger
1 parent f4c02e9 commit bca0505
Showing 2 changed files with 142 additions and 0 deletions.
73 changes: 73 additions & 0 deletions resources/codedeploy-deployment-configs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package resources

import (
"fmt"
"strings"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/codedeploy"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type CodeDeployDeploymentConfig struct {
svc *codedeploy.CodeDeploy
deploymentConfigName *string
}

func init() {
register("CodeDeployDeploymentConfig", ListCodeDeployDeploymentConfigs, mapCloudControl("AWS::CodeDeploy::DeploymentConfig"))
}

func ListCodeDeployDeploymentConfigs(sess *session.Session) ([]Resource, error) {
svc := codedeploy.New(sess)
resources := []Resource{}

params := &codedeploy.ListDeploymentConfigsInput{}

for {
resp, err := svc.ListDeploymentConfigs(params)
if err != nil {
return nil, err
}

for _, config := range resp.DeploymentConfigsList {
resources = append(resources, &CodeDeployDeploymentConfig{
svc: svc,
deploymentConfigName: config,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (f *CodeDeployDeploymentConfig) Filter() error {
if strings.HasPrefix(*f.deploymentConfigName, "CodeDeployDefault") {
return fmt.Errorf("cannot delete default codedeploy config")
}
return nil
}

func (f *CodeDeployDeploymentConfig) Remove() error {
_, err := f.svc.DeleteDeploymentConfig(&codedeploy.DeleteDeploymentConfigInput{
DeploymentConfigName: f.deploymentConfigName,
})

return err
}

func (f *CodeDeployDeploymentConfig) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("DeploymentConfigName", f.deploymentConfigName)
return properties
}

func (f *CodeDeployDeploymentConfig) String() string {
return *f.deploymentConfigName
}
69 changes: 69 additions & 0 deletions resources/codedeploy-deployment-groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/codedeploy"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type CodeDeployDeploymentGroup struct {
svc *codedeploy.CodeDeploy
deploymentGroupName *string
applicationName *string
}

func init() {
register("CodeDeployDeploymentGroup", ListCodeDeployDeploymentGroups)
}

func ListCodeDeployDeploymentGroups(sess *session.Session) ([]Resource, error) {
svc := codedeploy.New(sess)
resources := []Resource{}

appParams := &codedeploy.ListApplicationsInput{}
appResp, err := svc.ListApplications(appParams)
if err != nil {
return nil, err
}

for _, appName := range appResp.Applications {
// For each application, list deployment groups
deploymentGroupParams := &codedeploy.ListDeploymentGroupsInput{
ApplicationName: appName,
}
deploymentGroupResp, err := svc.ListDeploymentGroups(deploymentGroupParams)
if err != nil {
return nil, err
}

for _, group := range deploymentGroupResp.DeploymentGroups {
resources = append(resources, &CodeDeployDeploymentGroup{
svc: svc,
deploymentGroupName: group,
applicationName: appName,
})
}
}

return resources, nil
}

func (f *CodeDeployDeploymentGroup) Remove() error {
_, err := f.svc.DeleteDeploymentGroup(&codedeploy.DeleteDeploymentGroupInput{
ApplicationName: f.applicationName,
DeploymentGroupName: f.deploymentGroupName,
})

return err
}

func (f *CodeDeployDeploymentGroup) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("DeploymentGroupName", f.deploymentGroupName)
properties.Set("ApplicationName", f.applicationName)
return properties
}

func (f *CodeDeployDeploymentGroup) String() string {
return *f.deploymentGroupName
}

0 comments on commit bca0505

Please sign in to comment.