-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (74 loc) · 2.22 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/cantara/nerthus2/cloud/aws/ami"
"github.com/cantara/nerthus2/cloud/aws/key"
"github.com/cantara/nerthus2/cloud/aws/security"
"github.com/cantara/nerthus2/cloud/aws/server"
"github.com/cantara/nerthus2/cloud/aws/vpc"
log "github.com/cantara/bragi/sbragi"
)
func main() {
dl, _ := log.NewDebugLogger()
dl.SetDefault()
// Load the Shared AWS Configuration (~/.aws/config)
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
log.WithError(err).Fatal("while getting aws config")
}
ec2client := ec2.NewFromConfig(cfg)
testCluster := "test-nerthus"
testVpcName := testCluster + "-vpc"
//testKeyName := testCluster + "-key"
//testGroupName := testCluster + "-sg"
v, err := vpc.NewVPC(testVpcName, "172.31.200.0/24", ec2client)
if err != nil {
log.WithError(err).Fatal("while getting vpc")
}
v, err = vpc.GetVPC(testVpcName, ec2client)
if err != nil {
log.WithError(err).Fatal("while getting vpc")
}
vpc.CreateSubnets(v, ec2client)
ig, err := vpc.NewIG(v, ec2client)
if err != nil {
log.WithError(err).Fatal("while getting ig")
}
vpc.AddIGtoRT(v.Id, ig, ec2client)
k, err := key.New(testCluster, ec2client)
if err != nil {
log.WithError(err).Fatal("while getting key")
}
sg, err := security.New(testCluster, v.Id, ec2client)
if err != nil {
log.WithError(err).Error("while creating new security group")
}
img, err := ami.GetImage("Amazon Linux 2023", ami.AMD64, ec2client)
if err != nil {
log.WithError(err).Error("while getting ami")
}
s, err := vpc.GetSubnets(v.Id, ec2client)
if err != nil {
log.WithError(err).Error("while getting subnets")
}
fmt.Println(sg)
fmt.Println(sg.OpenSSH("sindre", "106.155.5.188", ec2client))
nodes := []string{
testCluster + "-1",
testCluster + "-2",
testCluster + "-3",
}
//var wg sync.WaitGroup
//wg.Add(len(nodes))
for i := range nodes {
//go func(i int) {
func(i int) {
//defer wg.Done()
fmt.Println(server.Create(i, nodes, 13030, "H2A", testCluster, "nerthus", "test", "t3.small", s[i].Id, "nerthus.text.exoreaction.dev", "visuale.test.exoreaction.dev", img, k, sg, ec2client))
}(i)
}
//wg.Wait()
}