Commit 92c9b492 authored by baldwinlouie's avatar baldwinlouie Committed by Yas Naoi
Browse files

Issue #3269708 by baldwinlouie, yas: Fix error when assigning Default security...

Issue #3269708 by baldwinlouie, yas: Fix error when assigning Default security group in EC2 instance edit form
parent 775c8947
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -548,11 +548,13 @@ class Ec2OperationsService extends CloudServiceBase implements Ec2OperationsServ
   *
   * @param array $group_names
   *   Array of group names.
   * @param string $vpc_id
   *   VPC id used for the query.
   *
   * @return array
   *   Array of group names.
   */
  private function getSecurityGroupIdsByNames(array $group_names): array {
  private function getSecurityGroupIdsByNames(array $group_names, string $vpc_id): array {
    // Querying for Group Name is done using filters.
    // @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2016-11-15.html#describesecuritygroups
    $response = $this->ec2Service->describeSecurityGroups([
@@ -561,6 +563,15 @@ class Ec2OperationsService extends CloudServiceBase implements Ec2OperationsServ
          'Name' => 'group-name',
          'Values' => $group_names,
        ],
        [
          // Specify VPC ID because the group names can duplicate across
          // different VPC networks. For example the 'default' group name
          // exists across different groups.
          'Name' => 'vpc-id',
          'Values' => [
            $vpc_id,
          ],
        ],
      ],
    ]);

@@ -594,7 +605,7 @@ class Ec2OperationsService extends CloudServiceBase implements Ec2OperationsServ

      $this->ec2Service->modifyInstanceAttribute([
        'InstanceId' => $entity->getInstanceId(),
        'Groups' => $this->getSecurityGroupIdsByNames($security_groups),
        'Groups' => $this->getSecurityGroupIdsByNames($security_groups, $entity->getVpcId()),
      ]);
    }
  }