Commit 56f93cf6 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3273058 by Xiaohua Guan, yas: Fix an Automatically assign a VPC option...

Issue #3273058 by Xiaohua Guan, yas: Fix an  Automatically assign a VPC option when launching an EC2 instance w/ a "Test only" option in AWS Cloud launch template
parent 0292dfab
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -200,9 +200,11 @@ class AwsCloudLaunchTemplatePlugin extends CloudPluginBase implements CloudLaunc
  public function launch(CloudLaunchTemplateInterface $cloud_launch_template, FormStateInterface $form_state = NULL): array {
    $this->ec2Service->setCloudContext($cloud_launch_template->getCloudContext());

    $test_only = $cloud_launch_template->get('field_test_only')->value === '0' ? FALSE : TRUE;

    $subnet_id = NULL;
    $security_group_id = NULL;
    if (!empty($form_state) && !empty($form_state->getValue('automatically_assign_vpc'))) {
    if (!$test_only && !empty($form_state) && !empty($form_state->getValue('automatically_assign_vpc'))) {
      [$subnet_id, $security_group_id] = $this->automaticallyAssignVpc(
        $form_state,
        $cloud_launch_template->getCloudContext()
@@ -219,7 +221,7 @@ class AwsCloudLaunchTemplatePlugin extends CloudPluginBase implements CloudLaunc
    }

    $params = [];
    $params['DryRun'] = $cloud_launch_template->get('field_test_only')->value === '0' ? FALSE : TRUE;
    $params['DryRun'] = $test_only;
    $params['ImageId'] = $cloud_launch_template->get('field_image_id')->value;
    $params['MaxCount'] = $cloud_launch_template->get('field_max_count')->value;
    $params['MinCount'] = $cloud_launch_template->get('field_min_count')->value;
@@ -252,7 +254,7 @@ class AwsCloudLaunchTemplatePlugin extends CloudPluginBase implements CloudLaunc
    }

    $params['SecurityGroupIds'] = [];
    if (!empty($form_state->getValue('automatically_assign_vpc'))) {
    if (!$test_only && !empty($form_state->getValue('automatically_assign_vpc'))) {
      // The availability zone will be ignored,
      // if the VPC was automatically assigned.
      $params['SubnetId'] = $subnet_id;