-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
152 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package destroy | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/atoz-technology/mantil-backend/internal/destroy" | ||
"github.com/atoz-technology/mantil-backend/internal/mantil" | ||
) | ||
|
||
type Destroy struct{} | ||
|
||
type DestroyRequest struct { | ||
ProjectName string | ||
Token string | ||
} | ||
|
||
type DestroyResponse struct { | ||
} | ||
|
||
func (d *Destroy) Invoke(ctx context.Context, req *DestroyRequest) (*DestroyResponse, error) { | ||
return d.Destroy(ctx, req) | ||
} | ||
|
||
func (f *Destroy) Destroy(ctx context.Context, req *DestroyRequest) (*DestroyResponse, error) { | ||
if req.ProjectName == "" || req.Token == "" { | ||
return nil, fmt.Errorf("bad request") | ||
} | ||
p, err := mantil.LoadProject(req.ProjectName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if p.Token != req.Token { | ||
return nil, fmt.Errorf("access denied") | ||
} | ||
err = destroy.Destroy(p, "/tmp") | ||
if err != nil { | ||
log.Printf("%v", err) | ||
return nil, err | ||
} | ||
return &DestroyResponse{}, nil | ||
} | ||
|
||
func New() *Destroy { | ||
return &Destroy{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM public.ecr.aws/lambda/go:latest | ||
|
||
# terrraform install | ||
RUN yum -y install unzip wget git | ||
ARG version=1.0.0 | ||
ARG arch=_linux_amd64 #_linux_arm64 | ||
RUN wget https://releases.hashicorp.com/terraform/$version/terraform_${version}${arch}.zip \ | ||
&& unzip terraform_${version}${arch}.zip \ | ||
&& rm terraform_${version}${arch}.zip \ | ||
&& mv terraform /usr/bin/ \ | ||
&& terraform --version | ||
ENV TF_IN_AUTOMATION=1 | ||
|
||
# aws cli install | ||
# ref: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html#cliv2-linux-install | ||
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \ | ||
&& unzip awscliv2.zip \ | ||
&& ./aws/install | ||
|
||
COPY destroy /var/task/ | ||
CMD [ "destroy" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/atoz-technology/mantil-backend/api/destroy" | ||
"github.com/atoz-technology/mantil.go" | ||
) | ||
|
||
func main() { | ||
var api = destroy.New() | ||
mantil.LambdaHandler(api) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package assets | ||
|
||
import "net/http" | ||
|
||
func StartServer() { | ||
go func() { | ||
mux := http.NewServeMux() | ||
mux.Handle("/", http.FileServer(AssetFile())) | ||
http.ListenAndServe(":8080", mux) | ||
}() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package destroy | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/atoz-technology/mantil-backend/internal/assets" | ||
"github.com/atoz-technology/mantil-backend/internal/aws" | ||
"github.com/atoz-technology/mantil-backend/internal/mantil" | ||
"github.com/atoz-technology/mantil-backend/internal/terraform" | ||
) | ||
|
||
func Destroy(project *mantil.Project, path string) error { | ||
assets.StartServer() | ||
tf := terraform.New(path) | ||
if err := tf.ApplyForProject(project, true); err != nil { | ||
return fmt.Errorf("could not terraform destroy - %v", err) | ||
} | ||
aws, err := aws.New() | ||
if err != nil { | ||
return fmt.Errorf("could not initialize aws - %v", err) | ||
} | ||
bucketName := project.Bucket | ||
bucketExists, _ := aws.S3BucketExists(bucketName) | ||
if bucketExists { | ||
err = aws.DeleteS3Bucket(bucketName) | ||
if err != nil { | ||
return fmt.Errorf("could not delete bucket %s - %v", bucketName, err) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters