Skip to content

Commit

Permalink
changing subcommands and adjusting the s3 bucket creation
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarsilva948 committed Sep 10, 2023
1 parent e86e3a0 commit e10f68c
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 324 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tests
cover.out

aft-deployment
example-output

pre-flight.sh

Expand Down
22 changes: 22 additions & 0 deletions cmd/aft/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright © 2023 Edgar Costa [email protected]
*/

package aft

import (
"github.com/edgarsilva948/aftctl/cmd/aft/deploy"
"github.com/spf13/cobra"
)

// Cmd represents the root command for the "deploy" functionality.
var Cmd = &cobra.Command{
Use: "aft",
Short: "Deploy AFT from from stdin",
Long: "Deploy AFT from from stdin",
}

func init() {

Cmd.AddCommand(deploy.Cmd)
}
42 changes: 15 additions & 27 deletions cmd/deploy/prereqs/cmd.go → cmd/aft/deploy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
Copyright © 2023 Edgar Costa [email protected]
*/

package prereqs
package deploy

import (
"strings"

"github.com/edgarsilva948/aftctl/pkg/aws"
"github.com/edgarsilva948/aftctl/pkg/initialcommit"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -47,7 +45,7 @@ var args struct {

// Cmd is the exported command for the AFT prerequisites.
var Cmd = &cobra.Command{
Use: "prereqs",
Use: "deploy",
Short: "Setup AFT prerequisites in AFT-Management Account",
Long: "Setup AFT prerequisites in AFT-Management Account",
Example: `# aftctl usage examples"
Expand All @@ -61,10 +59,11 @@ func init() {
flags := Cmd.Flags()
flags.SortFlags = false

flags.StringVar(
flags.StringVarP(
&args.terraformStateBucketName,
"terraform-state-bucket-name",
"",
"aft-deployment-terraform-tfstate",
"Name of the deployment terraform state bucket",
)

Expand Down Expand Up @@ -259,12 +258,8 @@ func init() {
func run(cmd *cobra.Command, _ []string) {
awsClient := aws.NewClient()

// Trim names to remove any leading/trailing invisible characters
terraformStateBucketName := strings.Trim(args.terraformStateBucketName, " \t")
aftManagementAccountID := strings.Trim(args.aftManagementAccountID, " \t")

interpolatedCodeSuiteBucketName := args.aftManagementAccountID + "-" + args.codePipelineBucketName

interpolatedTerraformBucketName := args.aftManagementAccountID + "-" + args.terraformStateBucketName
interpolatedZIPFileName := args.gitSourceRepo + ".zip"

interpolatedCloudformationStackName := args.gitSourceRepo + "-cloudformation-stack"
Expand All @@ -279,10 +274,10 @@ func run(cmd *cobra.Command, _ []string) {
codePipelineTrustRelationshipService,
args.codePipelineRolePolicyName,
args.region,
aftManagementAccountID,
args.aftManagementAccountID,
args.gitSourceRepo,
interpolatedCodeSuiteBucketName,
terraformStateBucketName,
interpolatedTerraformBucketName,
)

// Ensure the Code Build Service Role is created
Expand All @@ -292,17 +287,17 @@ func run(cmd *cobra.Command, _ []string) {
codebuildTrustRelationshipService,
args.codeBuildRolePolicyName,
args.region,
aftManagementAccountID,
args.aftManagementAccountID,
args.gitSourceRepo,
interpolatedCodeSuiteBucketName,
terraformStateBucketName,
interpolatedTerraformBucketName,
)

// Ensure the tfstate bucket is created
aws.EnsureS3BucketExists(
awsClient.GetS3Client(),
terraformStateBucketName,
aftManagementAccountID,
interpolatedTerraformBucketName,
args.aftManagementAccountID,
"test-kms-key-id",
args.codeBuildRoleName,
)
Expand All @@ -311,15 +306,15 @@ func run(cmd *cobra.Command, _ []string) {
aws.EnsureS3BucketExists(
awsClient.GetS3Client(),
interpolatedCodeSuiteBucketName,
aftManagementAccountID,
args.aftManagementAccountID,
"test-kms-key-id",
args.codeBuildRoleName,
)

// Ensure the CodeCommit repo is created with initial code
initialcommit.GenerateCommitFiles(
args.gitSourceRepo,
terraformStateBucketName,
interpolatedTerraformBucketName,
args.region,
args.tfVersion,
args.ctManagementAccountID,
Expand All @@ -342,13 +337,6 @@ func run(cmd *cobra.Command, _ []string) {
interpolatedZIPFileName,
)

// Ensure the repository is created
// aws.EnsureCodeCommitRepoExists(
// awsClient.GetCodeCommitClient(),
// args.gitSourceRepo,
// args.gitSourceDescription,
// )

// Ensure the repository is created
aws.EnsureCloudformationExists(
awsClient.CloudformationClient(),
Expand All @@ -362,7 +350,7 @@ func run(cmd *cobra.Command, _ []string) {
// Ensure the Code Build Project is created
aws.EnsureCodeBuildProjectExists(
awsClient.CodebuildClient(),
aftManagementAccountID,
args.aftManagementAccountID,
args.codeBuildDockerImage,
args.projectName,
args.gitSourceRepo,
Expand All @@ -373,7 +361,7 @@ func run(cmd *cobra.Command, _ []string) {
// Ensure the Code Pipeline Pipe is created
aws.EnsureCodePipelineExists(
awsClient.CodePipelineClient(),
aftManagementAccountID,
args.aftManagementAccountID,
args.codePipelineRoleName,
args.pipelineName,
interpolatedCodeSuiteBucketName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prereqs_test
package deploy

import (
ginkgo "github.com/onsi/ginkgo/v2"
Expand All @@ -9,5 +9,5 @@ import (

func TestPrereqs(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Prereqs Suite")
ginkgo.RunSpecs(t, "deploy Suite")
}
8 changes: 2 additions & 6 deletions cmd/deploy/prereqs/test_cmd.go → cmd/aft/deploy/test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Copyright © 2023 Edgar Costa [email protected]
*/

// Package prereqs contains tests for the prereqs cmd
package prereqs
// Package deploy contains tests for the prereqs cmd
package deploy

import (
ginkgo "github.com/onsi/ginkgo/v2"
Expand All @@ -14,11 +14,7 @@ var _ = ginkgo.Describe("testing the prereqs steps", func() {
ginkgo.Context("stores the bucket name that will store the tfstate", func() {
ginkgo.When("the command aftctl deploy prereqs --terraform-state-bucket-name=\"\" ", func() {
ginkgo.It("should print an object with the version", func() {
// cmd := &cobra.Command{
// Use: "prereqs",
// }

// gomega.Expect(out).To(gomega.MatchRegexp(expectedRegex))
})
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package deploy_test
package aft

import (
ginkgo "github.com/onsi/ginkgo/v2"
Expand All @@ -9,5 +9,5 @@ import (

func TestDeploy(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Deploy Suite")
ginkgo.RunSpecs(t, "aft Suite")
}
13 changes: 13 additions & 0 deletions cmd/aft/test_cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
Copyright © 2023 Edgar Costa [email protected]
*/

package aft

import (
ginkgo "github.com/onsi/ginkgo/v2"
)

var _ = ginkgo.Describe("Deploy Command", func() {

})
4 changes: 2 additions & 2 deletions cmd/aftctl/aftctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/spf13/cobra"

"github.com/edgarsilva948/aftctl/cmd/aft"
"github.com/edgarsilva948/aftctl/cmd/completion"
"github.com/edgarsilva948/aftctl/cmd/deploy"
"github.com/edgarsilva948/aftctl/cmd/docs"
"github.com/edgarsilva948/aftctl/cmd/version"

Expand All @@ -35,7 +35,7 @@ func init() {
root.AddCommand(completion.Cmd)
root.AddCommand(docs.Cmd)
root.AddCommand(version.Cmd)
root.AddCommand(deploy.Cmd)
root.AddCommand(aft.Cmd)
}

func main() {
Expand Down
13 changes: 0 additions & 13 deletions cmd/deploy/aft/aft_suite_test.go

This file was deleted.

104 changes: 0 additions & 104 deletions cmd/deploy/aft/cmd.go

This file was deleted.

Loading

0 comments on commit e10f68c

Please sign in to comment.