diff --git a/modules/cloud_service_providers/aws_cloud/src/Form/Vpc/VpcEditForm.php b/modules/cloud_service_providers/aws_cloud/src/Form/Vpc/VpcEditForm.php index 5adf7c702cb5b86dcb7e48886220b41bbdfc78f1..d10e8250a5d5baa72800c1eee6b0428c4fefdabb 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Form/Vpc/VpcEditForm.php +++ b/modules/cloud_service_providers/aws_cloud/src/Form/Vpc/VpcEditForm.php @@ -3,6 +3,7 @@ namespace Drupal\aws_cloud\Form\Vpc; use Drupal\aws_cloud\Form\Ec2\AwsCloudContentForm; +use Drupal\aws_cloud\Service\AwsServiceInterface; use Drupal\cloud\Traits\CloudContentEntityTrait; use Drupal\Core\Form\FormStateInterface; @@ -132,7 +133,16 @@ class VpcEditForm extends AwsCloudContentForm { // Update tags. $tag_map = []; foreach ($entity->getTags() ?: [] as $tag) { - $tag_map[$tag['item_key']] = $tag['item_value']; + // If the tag name contains the prefix + // which is reserved for AWS, it will not be saved. + if (!str_contains($tag['item_key'], AwsServiceInterface::AWS_RESOURCE_TAG_PREFIX)) { + $tag_map[$tag['item_key']] = $tag['item_value']; + } + else { + $this->messenger()->addWarning($this->t('The tag @tag_name is preserved as it is because it contains the prefix <em>aws:</em>, which is reserved by AWS.', [ + '@tag_name' => $tag['item_key'], + ])); + } } $this->setTagsInAws($entity->getVpcId(), $tag_map); diff --git a/modules/cloud_service_providers/aws_cloud/src/Service/AwsServiceInterface.php b/modules/cloud_service_providers/aws_cloud/src/Service/AwsServiceInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..c757f87fff21f25c11312bbaa4e78d5fea1ec231 --- /dev/null +++ b/modules/cloud_service_providers/aws_cloud/src/Service/AwsServiceInterface.php @@ -0,0 +1,19 @@ +<?php + +namespace Drupal\aws_cloud\Service; + +/** + * Aws Service interface. + */ +interface AwsServiceInterface { + + /** + * Resource tag prefix for AWS. + * + * @var string + * + * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html + */ + public const AWS_RESOURCE_TAG_PREFIX = 'aws:'; + +}