Support the new TLS termination on NLBs (#51327) (#58031)

This commit is contained in:
Kohei Asano 2019-06-21 08:03:04 +08:00 committed by Jill R
parent b9d77b997e
commit ddf6d096c5
6 changed files with 139 additions and 8 deletions

View file

@ -0,0 +1,17 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowAccessToServerCertificates",
"Effect": "Allow",
"Action": [
"iam:ListServerCertificates",
"iam:UploadServerCertificate",
"iam:UpdateServerCertificate",
"iam:DeleteServerCertificate",
"iam:GetServerCertificate"
],
"Resource": "*"
}
]
}

View file

@ -103,7 +103,7 @@ EXAMPLES = '''
- subnet-012345678
- subnet-abcdef000
listeners:
- Protocol: TCP # Required. The protocol for connections from clients to the load balancer (Only TCP is available) (case-sensitive).
- Protocol: TCP # Required. The protocol for connections from clients to the load balancer (TCP or TLS) (case-sensitive).
Port: 80 # Required. The port on which the load balancer is listening.
DefaultActions:
- Type: forward # Required. Only 'forward' is accepted at this time
@ -117,7 +117,7 @@ EXAMPLES = '''
- SubnetId: subnet-012345678
AllocationId: eipalloc-aabbccdd
listeners:
- Protocol: TCP # Required. The protocol for connections from clients to the load balancer (Only TCP is available) (case-sensitive).
- Protocol: TCP # Required. The protocol for connections from clients to the load balancer (TCP or TLS) (case-sensitive).
Port: 80 # Required. The port on which the load balancer is listening.
DefaultActions:
- Type: forward # Required. Only 'forward' is accepted at this time
@ -402,8 +402,8 @@ def main():
if listeners is not None:
for listener in listeners:
for key in listener.keys():
if key == 'Protocol' and listener[key] != 'TCP':
module.fail_json(msg="'Protocol' must be 'TCP'")
if key == 'Protocol' and listener[key] not in ['TCP', 'TLS']:
module.fail_json(msg="'Protocol' must be either 'TCP' or 'TLS'")
connection = module.client('elbv2')
connection_ec2 = module.client('ec2')

View file

@ -0,0 +1,32 @@
-----BEGIN CERTIFICATE-----
MIIFiTCCA3GgAwIBAgIJAKE+XLUKdWtPMA0GCSqGSIb3DQEBCwUAMFsxCzAJBgNV
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN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aIkk1QT1iwFimxhdmLfg8bq5IJEDZiJGVQ4cQ3HKG6mchNp
Hr2aBex2it/UnlUVYec9QotCpDCDORO8g5NOH3dTAoIBAQCJH9htqVYWgIESzvW9
2ua7dAqpM0CEGeWFH8mik0s1c9lSZtfP51OYDdjj3dhBjjEeJQVIANAERCCwqYyK
5UmzgLqJrO85dgiTDGFgJmkM7+7O+M5ZB6BeVn7C2KD3KrBNT0lupIzeAXFNe69o
HSY5+W+JPSUGm72BAdxkqsL7aLm0N2qwUViPFlIztG1QzS25W7sEsSFL85VDAT1+
ACvpk7OXwDjNd7G2tw+b2kZt6Mn9WsJR23rP1WO6/85ay00PncXzNKc4F9YY7YTW
VveWE+h8lOmkrZN8M/kP1qAPncVgsqwzaCxUh/8Q9wlRTwT2dtLuY9ajv8hfAImd
pla5AoIBAQCduiA3aZBDqGrUTH9bcMRtyU8RTlc2Y5+jFSBP4KfcS/ORoILVdvZz
v+o0jw01keGAtW77Mq70ZCpc8HjOm8Ju8GYtwUGmPRS+hQaZwT8/QseF6q2Q+Bi5
Wc0Lqa4YA0cI7XViJRhHIPfdV8YEEAW8rIAUqFSoAT6G7z/o0K4zlSa+2RbG0l1v
zLWmJtF8OJfM8IboIyER0PHrWjNFzxKCJssu2WE7WT6/Rupus04XVXRR+Fb6DAGb
yw2MpB3kLvjugQpolx4YbXE4n+F1mkqm9fHjo4fbfSwjmeFnPsRvRmiRTomHxq/s
DUZ6eZM8TIlGhUrx/Y1TP0GQjKxDN6ZQ
-----END PRIVATE KEY-----

View file

@ -9,6 +9,15 @@
region: "{{ aws_region }}"
no_log: yes
- name: create certificate
iam_cert:
name: test_cert
state: present
cert: "{{ lookup('file', 'cert.pem') }}"
key: "{{ lookup('file', 'key.pem') }}"
<<: *aws_connection_info
register: cert
- name: create VPC
ec2_vpc_net:
cidr_block: 10.228.228.0/22
@ -203,3 +212,10 @@
delay: 5
until: remove_vpc is success
ignore_errors: yes
- name: destroy certificate
iam_cert:
name: test_cert
state: absent
<<: *aws_connection_info
ignore_errors: yes

View file

@ -9,7 +9,7 @@
region: "{{ aws_region }}"
no_log: yes
- name: create NLB with a listener
- name: create NLB with listeners
elb_network_lb:
name: "{{ nlb_name }}"
subnets: "{{ nlb_subnets }}"
@ -20,15 +20,22 @@
DefaultActions:
- Type: forward
TargetGroupName: "{{ tg_name }}"
- Protocol: TLS
Port: 443
Certificates:
- CertificateArn: "{{ cert.arn }}"
DefaultActions:
- Type: forward
TargetGroupName: "{{ tg_name }}"
<<: *aws_connection_info
register: nlb
- assert:
that:
- nlb.changed
- nlb.listeners|length == 1
- nlb.listeners|length == 2
- name: test idempotence creating NLB with a listener
- name: test idempotence creating NLB with listeners
elb_network_lb:
name: "{{ nlb_name }}"
subnets: "{{ nlb_subnets }}"
@ -39,10 +46,17 @@
DefaultActions:
- Type: forward
TargetGroupName: "{{ tg_name }}"
- Protocol: TLS
Port: 443
Certificates:
- CertificateArn: "{{ cert.arn }}"
DefaultActions:
- Type: forward
TargetGroupName: "{{ tg_name }}"
<<: *aws_connection_info
register: nlb
- assert:
that:
- not nlb.changed
- nlb.listeners|length == 1
- nlb.listeners|length == 2