Comments

Xiaohua Guan created an issue. See original summary.

xiaohua guan’s picture

StatusFileSize
new9.15 KB
xiaohua guan’s picture

Status: Active » Needs review
xiaohua guan’s picture

StatusFileSize
new56.65 KB
xiaohua guan’s picture

xiaohua guan’s picture

@yas

Here is the screenshot.

screenshot

xiaohua guan’s picture

StatusFileSize
new9.15 KB
xiaohua guan’s picture

@yas

I implement the feature as the followings.

1. Change field "security groups" to select element, and the element can be selected multiply like the screenshot in comment #6.
2. Fill the select element "security groups" with all security groups which belong to the instance's vpc.
3. Change test case testUpdateInstanceType to testUpdateInstanceAttributes.

Please review the patch file.

yas’s picture

@xiaohua-guan

Thank you for the patch including the tests! Let's change the following code from:

...
      '#default_value' => explode(', ', $entity->security_groups()),
...
    $this->entity->setSecurityGroups(implode(', ', $security_groups));
...

To:

...
define('SECURITY_GROUP_DELIMITER', ', ');
...
      '#default_value' => explode(SECURITY_GROUP_DELIMITER, $entity->security_groups()),
...
    $this->entity->setSecurityGroups(implode(SECURITY_GROUP_DELIMITER, $security_groups));
...
yas’s picture

Status: Needs review » Needs work
xiaohua guan’s picture

StatusFileSize
new9.9 KB
xiaohua guan’s picture

Status: Needs work » Needs review
xiaohua guan’s picture

@yas

Thanks for your code review and comments.

I modified code as you said. Furthermore, I change the form field "security groups" to required.

Please review the new patch.

yas’s picture

Thank you for your new patch including the refactoring. I reviewed your new patch. It looks good to me.

baldwinlouie’s picture

Status: Needs review » Needs work
+++ b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceEditForm.php
@@ -9,6 +9,8 @@ use Drupal\Core\Datetime\Entity\DateFormat;
+define('SECURITY_GROUP_DELIMITER', ', ');

The constant should be defined with the const keyword, and not with define() function.

See this url for reference
https://www.drupal.org/node/1362360

xiaohua guan’s picture

StatusFileSize
new10.11 KB
xiaohua guan’s picture

Status: Needs work » Needs review
xiaohua guan’s picture

@yas, @baldwinlouie

Thanks for comments.

I modified the code. Please review the new patch file. Thanks.

yas’s picture

Status: Needs review » Reviewed & tested by the community

Thank you for the modification. I'll push and merge the patch.

  • yas committed 9255242 on 8.x-1.x authored by Xiaohua Guan
    Issue #3017570 by Xiaohua Guan, yas, baldwinlouie: Make it possible to...
yas’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

baldwinlouie’s picture

Status: Closed (fixed) » Needs work
StatusFileSize
new67.56 KB
+++ b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceEditForm.php
@@ -249,4 +265,35 @@ class InstanceEditForm extends AwsCloudContentForm {
+  private function getSecurityGroupsOptions() {
+    $options = [];
+    $this->awsEc2Service->setCloudContext($this->entity->get('cloud_context')->value);
+    $response = $this->awsEc2Service->describeSecurityGroups([
+      'Filters' => [[
+        'Name' => 'vpc-id',
+        'Values' => [$this->entity->vpc_id()],
+      ]]
+    ]);

Not all instances are part of a VPC. In my test AWS console, I do not have instances that are part of a VPC. This code can potentially bring back an empty list.

Combine with the fact that selecting a security is required, there will be cases where you cannot edit an instance because of an empty security group list.

See attached screenshot.

yas’s picture

@baldwinlouie,

According to AWS document at https://docs.aws.amazon.com/vpc/latest/userguide/default-vpc.html,

If you created your AWS account after 2013-12-04, it supports only EC2-VPC. In this case, you have a default VPC in each AWS Region. A default VPC is ready for you to use so that you don't have to create and configure your own VPC.

We have a long long history to use AWS. Therefore you (we) might be able to launch a NON-VPC instance. However, in most of cases I guess NON-VPC instance support should not be the problem since using VPC is the best practice (and now strictly forced to use for newer AWS users) even if we can technically launch a NON-VPC instance. Also, when AWS adds a new region, now they give a default VPC to a user (such as Paris, Stockholm and etc.)

Also you can refer to the forum discussion at https://forums.aws.amazon.com/thread.jspa?threadID=182773

How do you think about it?

baldwinlouie’s picture

Status: Needs work » Closed (works as designed)

@yas, Thank you for the explanation. I understand that VPC is best practice and the default. I think we should document it somewhere in the README.txt file that we are only supporting EC2 VPC.

My followup question is what should happen to users that *ARE* from EC2 classic and they try to add an EC2 region, such as myself? (I have been using my own aws account, which is REALLY old. That is why I can still launch EC2 classic instances)

One idea I have is that when a user sets up a cloud config, we verify if the account is ec2-classic or ec2-vpc, by calling this API: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2016-11-15.html#d... . If they are ec2-classic, we error out and let the user know that we do not support EC2-classic?

What do you think? We can move this discussion to another issue. I am marking this one Closed (works as designed)

yas’s picture

@baldwinlouie,

A new VPC region is automatically added by AWS w/ default VPC that AWS provide when they are ready.

If you don't have an existing VPC since it is a classic account, you need to create your own VPC (at least one VPC) if you want to launch a VPC-enabled instance.

Thank you for your comment. Yes, we should document that we are only supporting EC2 VPC in the README.txt file.

I totally agree that your idea:

When a user sets up a cloud config, we verify if the account is ec2-classic or ec2-vpc, by calling this API

Also, We'll move this discussion to another issue.