ELBv2 - enable Tags for create_target_group (#5045)

This commit is contained in:
Bert Blommers 2022-04-21 19:27:14 +00:00 committed by GitHub
parent 8da9666a90
commit 61a5d5ca3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 15 deletions

View File

@ -115,6 +115,9 @@ class FakeTargetGroup(CloudFormationModel):
self.attributes = {
"deregistration_delay.timeout_seconds": 300,
"stickiness.enabled": "false",
"load_balancing.algorithm.type": "round_robin",
"slow_start.duration_seconds": 0,
"waf.fail_open.enabled": "false",
}
self.targets = OrderedDict()
@ -1009,8 +1012,11 @@ Member must satisfy regular expression pattern: {}".format(
arn = make_arn_for_target_group(
account_id=ACCOUNT_ID, name=name, region_name=self.region_name
)
tags = kwargs.pop("tags", None)
target_group = FakeTargetGroup(name, arn, **kwargs)
self.target_groups[target_group.arn] = target_group
if tags:
self.add_tags(resource_arns=[target_group.arn], tags=tags)
return target_group
def modify_target_group_attributes(self, target_group_arn, attributes):

View File

@ -177,11 +177,12 @@ class ELBV2Response(BaseResponse):
@amzn_request_id
def create_target_group(self):
name = self._get_param("Name")
vpc_id = self._get_param("VpcId")
protocol = self._get_param("Protocol")
protocol_version = self._get_param("ProtocolVersion", "HTTP1")
port = self._get_param("Port")
params = self._get_params()
name = params.get("Name")
vpc_id = params.get("VpcId")
protocol = params.get("Protocol")
protocol_version = params.get("ProtocolVersion", "HTTP1")
port = params.get("Port")
healthcheck_protocol = self._get_param("HealthCheckProtocol")
healthcheck_port = self._get_param("HealthCheckPort")
healthcheck_path = self._get_param("HealthCheckPath")
@ -190,8 +191,9 @@ class ELBV2Response(BaseResponse):
healthcheck_enabled = self._get_param("HealthCheckEnabled")
healthy_threshold_count = self._get_param("HealthyThresholdCount")
unhealthy_threshold_count = self._get_param("UnhealthyThresholdCount")
matcher = self._get_params().get("Matcher")
target_type = self._get_param("TargetType")
matcher = params.get("Matcher")
target_type = params.get("TargetType")
tags = params.get("Tags")
target_group = self.elbv2_backend.create_target_group(
name,
@ -209,6 +211,7 @@ class ELBV2Response(BaseResponse):
unhealthy_threshold_count=unhealthy_threshold_count,
matcher=matcher,
target_type=target_type,
tags=tags,
)
template = self.response_template(CREATE_TARGET_GROUP_TEMPLATE)

View File

@ -10,7 +10,7 @@ relative_files = True
[flake8]
ignore = W503,W605,E128,E501,E203,E266,E501,E231
exclude = moto/packages,dist
exclude = moto/packages,dist,tests/terraformtests
[pylint.MASTER]
ignore-paths=moto/packages

View File

@ -6,7 +6,6 @@ TestAccAPIGatewayV2Authorizer
TestAccAPIGatewayV2Route
TestAccAppsyncApiKey
TestAccAppsyncGraphqlApi
TestAccAutoscalingAttachment
TestAccAutoscalingPolicy
TestAccBatchJobQueue
TestAccCloudTrail
@ -48,8 +47,6 @@ TestAccIAMRole
TestAccIotThing
TestAccIPRanges
TestAccKinesisStream
TestAccLbListenerCertificate
TestAccLBTargetGroupAttachment
TestAccELBPolicy
TestAccLambdaAlias
TestAccLambdaLayerVersion
@ -68,4 +65,4 @@ TestAccTimestreamWriteTable
TestAccDataSourceLambdaLayerVersion
TestAccDataSourceLambdaInvocation
TestAccDataSourceNetworkInterface_
TestAccSQSQueueDataSource
TestAccSQSQueueDataSource

View File

@ -9,6 +9,7 @@ apigatewayv2:
- TestAccAPIGatewayV2VPCLink
autoscaling:
- TestAccAutoScalingGroupDataSource
- TestAccAutoScalingAttachment
batch:
- TestAccBatchJobDefinition
cloudtrail:
@ -50,6 +51,10 @@ elb:
- TestAccELBListenerPolicy
- TestAccELBServiceAccountDataSource
- TestAccELBSSLNegotiationPolicy
elbv2:
- TestAccELBV2ListenerCertificate
- TestAccELBV2TargetGroupAttachment
- TestAccELBV2TargetGroupDataSource
events:
- TestAccEventsAPIDestination
- TestAccEventsArchive

View File

@ -54,6 +54,7 @@ def test_create_target_group_with_tags():
HealthyThresholdCount=5,
UnhealthyThresholdCount=2,
Matcher={"HttpCode": "200"},
Tags=[{"Key": "key1", "Value": "val1"}],
)
target_group = response.get("TargetGroups")[0]
target_group_arn = target_group["TargetGroupArn"]
@ -61,7 +62,7 @@ def test_create_target_group_with_tags():
# Add tags to the target group
conn.add_tags(
ResourceArns=[target_group_arn],
Tags=[{"Key": "key1", "Value": "val1"}, {"Key": "key2", "Value": "val2"}],
Tags=[{"Key": "key2", "Value": "val2"}],
)
conn.describe_tags(ResourceArns=[target_group_arn])["TagDescriptions"][0][
"Tags"
@ -384,10 +385,11 @@ def test_target_group_attributes():
# The attributes should start with the two defaults
response = conn.describe_target_group_attributes(TargetGroupArn=target_group_arn)
response["Attributes"].should.have.length_of(2)
response["Attributes"].should.have.length_of(5)
attributes = {attr["Key"]: attr["Value"] for attr in response["Attributes"]}
attributes["deregistration_delay.timeout_seconds"].should.equal("300")
attributes["stickiness.enabled"].should.equal("false")
attributes["waf.fail_open.enabled"].should.equal("false")
# Add cookie stickiness
response = conn.modify_target_group_attributes(
@ -406,7 +408,7 @@ def test_target_group_attributes():
# These new values should be in the full attribute list
response = conn.describe_target_group_attributes(TargetGroupArn=target_group_arn)
response["Attributes"].should.have.length_of(3)
response["Attributes"].should.have.length_of(6)
attributes = {attr["Key"]: attr["Value"] for attr in response["Attributes"]}
attributes["stickiness.type"].should.equal("lb_cookie")
attributes["stickiness.enabled"].should.equal("true")