Delete event rule when deleted from cloudformation template (#4382)
This commit is contained in:
parent
6ff03f3974
commit
acf34a685f
@ -271,6 +271,13 @@ class Rule(CloudFormationModel):
|
|||||||
new_resource_name, cloudformation_json, region_name
|
new_resource_name, cloudformation_json, region_name
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def delete_from_cloudformation_json(
|
||||||
|
cls, resource_name, cloudformation_json, region_name
|
||||||
|
):
|
||||||
|
event_backend = events_backends[region_name]
|
||||||
|
event_backend.delete_rule(resource_name)
|
||||||
|
|
||||||
def describe(self):
|
def describe(self):
|
||||||
attributes = {
|
attributes = {
|
||||||
"Arn": self.arn,
|
"Arn": self.arn,
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
import pytest
|
||||||
import copy
|
import copy
|
||||||
from string import Template
|
from string import Template
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import json
|
import json
|
||||||
|
from botocore.exceptions import ClientError
|
||||||
from moto import mock_cloudformation, mock_events
|
from moto import mock_cloudformation, mock_events
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
|
|
||||||
@ -60,6 +62,15 @@ rule_template = Template(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
empty = json.dumps(
|
||||||
|
{
|
||||||
|
"AWSTemplateFormatVersion": "2010-09-09",
|
||||||
|
"Description": "EventBridge Rule Test",
|
||||||
|
"Resources": {},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@mock_events
|
@mock_events
|
||||||
@mock_cloudformation
|
@mock_cloudformation
|
||||||
def test_create_archive():
|
def test_create_archive():
|
||||||
@ -154,3 +165,24 @@ def test_create_rule():
|
|||||||
|
|
||||||
response["Arn"].should.equal(rule_arn)
|
response["Arn"].should.equal(rule_arn)
|
||||||
response["EventPattern"].should.equal('{"detail-type": ["SomeDetailType"]}')
|
response["EventPattern"].should.equal('{"detail-type": ["SomeDetailType"]}')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_events
|
||||||
|
@mock_cloudformation
|
||||||
|
def test_delete_rule():
|
||||||
|
# given
|
||||||
|
cfn_client = boto3.client("cloudformation", region_name="eu-central-1")
|
||||||
|
name = "test-rule"
|
||||||
|
stack_name = "test-stack"
|
||||||
|
template = rule_template.substitute({"rule_name": name})
|
||||||
|
cfn_client.create_stack(StackName=stack_name, TemplateBody=template)
|
||||||
|
|
||||||
|
# when
|
||||||
|
cfn_client.update_stack(StackName=stack_name, TemplateBody=empty)
|
||||||
|
|
||||||
|
# then
|
||||||
|
events_client = boto3.client("events", region_name="eu-central-1")
|
||||||
|
|
||||||
|
with pytest.raises(ClientError, match="does not exist") as e:
|
||||||
|
|
||||||
|
events_client.describe_rule(Name=name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user