@@ -117,4 +117,113 @@ def test_create_delete(self, standard_elastic_address, ec2_client):
117117 time .sleep (DELETE_WAIT_AFTER_SECONDS )
118118
119119 # Check NAT Gateway no longer exists in AWS
120- ec2_validator .assert_nat_gateway (resource_id , exists = False )
120+ ec2_validator .assert_nat_gateway (resource_id , exists = False )
121+
122+ def test_terminal_condition_invalid_subnet (self , standard_elastic_address ):
123+ test_resource_values = REPLACEMENT_VALUES .copy ()
124+ resource_name = random_suffix_name ("nat-gateway-fail-1" , 24 )
125+ subnet_id = "InvalidSubnet"
126+
127+ (_ , eip ) = standard_elastic_address
128+
129+ test_resource_values ["NAT_GATEWAY_NAME" ] = resource_name
130+ test_resource_values ["SUBNET_ID" ] = subnet_id
131+ test_resource_values ["ALLOCATION_ID" ] = eip ["status" ]["allocationID" ]
132+
133+ # Load NAT Gateway CR
134+ resource_data = load_ec2_resource (
135+ "nat_gateway" ,
136+ additional_replacements = test_resource_values ,
137+ )
138+ logging .debug (resource_data )
139+
140+ # Create k8s resource
141+ ref = k8s .CustomResourceReference (
142+ CRD_GROUP , CRD_VERSION , RESOURCE_PLURAL ,
143+ resource_name , namespace = "default" ,
144+ )
145+ k8s .create_custom_resource (ref , resource_data )
146+ cr = k8s .wait_resource_consumed_by_controller (ref )
147+
148+ assert cr is not None
149+ assert k8s .get_resource_exists (ref )
150+
151+ expected_msg = "InvalidSubnet: The subnet ID 'InvalidSubnet' is malformed"
152+ terminal_condition = k8s .get_resource_condition (ref , "ACK.Terminal" )
153+ # Example condition message:
154+ # An error occurred (InvalidSubnet) when calling the CreateNatGateway operation:
155+ # The subnet ID 'InvalidSubnet' is malformed
156+ assert expected_msg in terminal_condition ['message' ]
157+
158+ def test_terminal_condition_malformed_elastic_ip (self ):
159+ test_resource_values = REPLACEMENT_VALUES .copy ()
160+ resource_name = random_suffix_name ("nat-gateway-fail-2" , 24 )
161+ test_vpc = get_bootstrap_resources ().SharedTestVPC
162+ subnet_id = test_vpc .public_subnets .subnet_ids [0 ]
163+
164+ test_resource_values ["NAT_GATEWAY_NAME" ] = resource_name
165+ test_resource_values ["SUBNET_ID" ] = subnet_id
166+ test_resource_values ["ALLOCATION_ID" ] = "MalformedElasticIpId"
167+
168+ # Load NAT Gateway CR
169+ resource_data = load_ec2_resource (
170+ "nat_gateway" ,
171+ additional_replacements = test_resource_values ,
172+ )
173+ logging .debug (resource_data )
174+
175+ # Create k8s resource
176+ ref = k8s .CustomResourceReference (
177+ CRD_GROUP , CRD_VERSION , RESOURCE_PLURAL ,
178+ resource_name , namespace = "default" ,
179+ )
180+ k8s .create_custom_resource (ref , resource_data )
181+ cr = k8s .wait_resource_consumed_by_controller (ref )
182+
183+ assert cr is not None
184+ assert k8s .get_resource_exists (ref )
185+
186+ expected_msg = "InvalidElasticIpID.Malformed: The elastic-ip ID 'MalformedElasticIpId' is malformed"
187+ terminal_condition = k8s .get_resource_condition (ref , "ACK.Terminal" )
188+ # Example condition message:
189+ # An error occurred (InvalidElasticIpID.Malformed) when calling the CreateNatGateway operation:
190+ # The elastic-ip ID 'MalformedElasticIpId' is malformed"
191+ assert expected_msg in terminal_condition ['message' ]
192+
193+ def test_terminal_condition_missing_parameter (self ):
194+ test_resource_values = REPLACEMENT_VALUES .copy ()
195+ resource_name = random_suffix_name ("nat-gateway-fail-3" , 24 )
196+ test_vpc = get_bootstrap_resources ().SharedTestVPC
197+ subnet_id = test_vpc .public_subnets .subnet_ids [0 ]
198+
199+ test_resource_values ["NAT_GATEWAY_NAME" ] = resource_name
200+ test_resource_values ["SUBNET_ID" ] = subnet_id
201+
202+ # ALLOCATION_ID is required for creating public nat gateways only
203+ test_resource_values ["ALLOCATION_ID" ] = ""
204+
205+ # Load NAT Gateway CR
206+ resource_data = load_ec2_resource (
207+ "nat_gateway" ,
208+ additional_replacements = test_resource_values ,
209+ )
210+ logging .debug (resource_data )
211+
212+ # Create k8s resource
213+ ref = k8s .CustomResourceReference (
214+ CRD_GROUP , CRD_VERSION , RESOURCE_PLURAL ,
215+ resource_name , namespace = "default" ,
216+ )
217+ k8s .create_custom_resource (ref , resource_data )
218+ cr = k8s .wait_resource_consumed_by_controller (ref )
219+
220+ assert cr is not None
221+ assert k8s .get_resource_exists (ref )
222+
223+ expected_msg = "MissingParameter: The request must include the AllocationId parameter. Add the required parameter and retry the request."
224+ terminal_condition = k8s .get_resource_condition (ref , "ACK.Terminal" )
225+ # Example condition message:
226+ # An error occurred (MissingParameter) when calling the CreateNatGateway operation:
227+ # The request must include the AllocationId parameter.
228+ # Add the required parameter and retry the request.
229+ assert expected_msg in terminal_condition ['message' ]
0 commit comments