(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Workload)
| 311 | } |
| 312 | |
| 313 | func (m *WorkloadsModule) getEC2WorkloadsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Workload) { |
| 314 | defer func() { |
| 315 | m.CommandCounter.DecrExecuting() |
| 316 | m.CommandCounter.IncrComplete() |
| 317 | wg.Done() |
| 318 | |
| 319 | }() |
| 320 | semaphore <- struct{}{} |
| 321 | defer func() { |
| 322 | <-semaphore |
| 323 | }() |
| 324 | |
| 325 | // Get EC2 instances |
| 326 | ec2Instances, err := sdk.CachedEC2DescribeInstances(m.EC2Client, aws.ToString(m.Caller.Account), r) |
| 327 | if err != nil { |
| 328 | m.modLog.Error(err) |
| 329 | } |
| 330 | for _, instance := range ec2Instances { |
| 331 | var profileArn, profileName, name string |
| 332 | |
| 333 | // The name is in a tag so we have to do this to grab the value from the right tag |
| 334 | for _, tag := range instance.Tags { |
| 335 | if *tag.Key == "Name" { |
| 336 | name = *tag.Value |
| 337 | } |
| 338 | } |
| 339 | if name == "" { |
| 340 | name = aws.ToString(instance.InstanceId) |
| 341 | } |
| 342 | |
| 343 | if instance.IamInstanceProfile != nil { |
| 344 | profileArn = aws.ToString(instance.IamInstanceProfile.Arn) |
| 345 | |
| 346 | // Extracting instance profile name from ARN |
| 347 | profileName = strings.Split(profileArn, "/")[len(strings.Split(profileArn, "/"))-1] |
| 348 | |
| 349 | // Describe the IAM instance profile |
| 350 | profileOutput, err := sdk.CachedIamGetInstanceProfile(m.IAMClient, aws.ToString(m.Caller.Account), profileName) |
| 351 | if err != nil { |
| 352 | m.modLog.Errorf("failed to get instance profile for %s, %v", profileArn, err) |
| 353 | continue |
| 354 | } |
| 355 | |
| 356 | for _, role := range profileOutput.Roles { |
| 357 | dataReceiver <- Workload{ |
| 358 | AWSService: "EC2", |
| 359 | Region: r, |
| 360 | Type: "instance", |
| 361 | Name: name, |
| 362 | Arn: fmt.Sprintf("arn:aws:ec2:%s:%s:instance/%s", r, aws.ToString(m.Caller.Account), aws.ToString(instance.InstanceId)), |
| 363 | Role: aws.ToString(role.Arn), |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | func (m *WorkloadsModule) getECSWorkloadsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Workload) { |
no test coverage detected