Skip to content

Commit 379c367

Browse files
[no-relnote] fix aws security ground create
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent 14a7880 commit 379c367

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pkg/provider/aws/create.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,30 @@ func (p *Provider) createSecurityGroup(cache *AWS) error {
249249
cache.SecurityGroupid = *sgOutput.GroupId
250250

251251
// Enter the Ingress rules for the security group
252+
ipRangeMap := make(map[string]bool)
252253
ipRanges := []types.IpRange{}
254+
253255
// First lookup for the IP address of the user
254256
ip, err := utils.GetIPAddress()
255257
if err != nil {
256258
p.fail()
257259
return fmt.Errorf("error getting IP address: %v", err)
258260
}
261+
262+
// Add the auto-detected IP to the map and list
263+
ipRangeMap[ip] = true
259264
ipRanges = append(ipRanges, types.IpRange{
260265
CidrIp: &ip,
261266
})
262267

263-
// Then add the IP ranges from the spec
268+
// Then add the IP ranges from the spec, skipping duplicates
264269
for _, ip := range p.Spec.IngressIpRanges {
265-
ipRanges = append(ipRanges, types.IpRange{
266-
CidrIp: &ip,
267-
})
270+
if !ipRangeMap[ip] {
271+
ipRangeMap[ip] = true
272+
ipRanges = append(ipRanges, types.IpRange{
273+
CidrIp: &ip,
274+
})
275+
}
268276
}
269277

270278
irInput := &ec2.AuthorizeSecurityGroupIngressInput{

0 commit comments

Comments
 (0)