generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 12
/
createSecurityGroup.go
47 lines (40 loc) · 1.31 KB
/
createSecurityGroup.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
package nfsinstance
import (
"context"
ec2Types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/kyma-project/cloud-manager/pkg/common"
"github.com/kyma-project/cloud-manager/pkg/composed"
"k8s.io/utils/pointer"
)
func createSecurityGroup(ctx context.Context, st composed.State) (error, context.Context) {
state := st.(*State)
if state.securityGroup != nil {
return nil, nil
}
logger := composed.LoggerFromCtx(ctx)
sgId, err := state.awsClient.CreateSecurityGroup(ctx, state.IpRange().Status.VpcId, state.Obj().GetName(), []ec2Types.Tag{
{
Key: pointer.String("Name"),
Value: pointer.String(state.Obj().GetName()),
},
{
Key: pointer.String(common.TagCloudManagerRemoteName),
Value: pointer.String(state.ObjAsNfsInstance().Spec.RemoteRef.String()),
},
{
Key: pointer.String(common.TagCloudManagerName),
Value: pointer.String(state.Name().String()),
},
{
Key: pointer.String(common.TagScope),
Value: pointer.String(state.ObjAsNfsInstance().Spec.Scope.Name),
},
})
if err != nil {
return composed.LogErrorAndReturn(err, "Error creating security group", composed.StopWithRequeue, ctx)
}
state.securityGroupId = sgId
logger = logger.WithValues("securityGroupId", sgId)
logger.Info("Security group created")
return nil, composed.LoggerIntoCtx(ctx, logger)
}