Skip to content

Commit e2f6061

Browse files
authored
aws - add support for timestream influxdb (cloud-custodian#9858)
1 parent c303cb9 commit e2f6061

24 files changed

+764
-0
lines changed

c7n/resources/resource_map.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
"aws.swf-domain": "c7n.resources.swf.SimpleWorkflowDomain",
293293
"aws.timestream-database": "c7n.resources.timestream.TimestreamDatabase",
294294
"aws.timestream-table": "c7n.resources.timestream.TimestreamTable",
295+
"aws.timestream-influxdb": "c7n.resources.timestream.TimestreamInfluxDB",
295296
"aws.transfer-server": "c7n.resources.transfer.TransferServer",
296297
"aws.transfer-user": "c7n.resources.transfer.TransferUser",
297298
"aws.transit-attachment": "c7n.resources.vpc.TransitGatewayAttachment",

c7n/resources/timestream.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from c7n.manager import resources
22
from c7n.actions import Action
33
from c7n.filters.kms import KmsRelatedFilter
4+
from c7n.filters.vpc import SecurityGroupFilter, SubnetFilter
45
from c7n.query import DescribeSource, QueryResourceManager, TypeInfo
56
from c7n.utils import local_session, type_schema
67
from c7n.tags import (
@@ -52,6 +53,27 @@ class resource_type(TypeInfo):
5253
}
5354

5455

56+
@resources.register('timestream-influxdb')
57+
class TimestreamInfluxDB(QueryResourceManager):
58+
class resource_type(TypeInfo):
59+
service = 'timestream-influxdb'
60+
arn_type = ''
61+
name = 'name'
62+
id = arn = 'arn'
63+
enum_spec = ('list_db_instances', 'items', {})
64+
detail_spec = ('get_db_instance', 'identifier', 'id', None)
65+
permission_prefix = 'timestream-influxdb'
66+
67+
def augment(self, resources):
68+
resources = super().augment(resources)
69+
for r in resources:
70+
client = local_session(self.session_factory).client('timestream-influxdb')
71+
tags = client.list_tags_for_resource(resourceArn=r['arn'])['tags']
72+
if tags:
73+
r['Tags'] = [{'Key': k, 'Value': v} for k, v in tags.items()]
74+
return resources
75+
76+
5577
@TimestreamDatabase.action_registry.register('tag')
5678
@TimestreamTable.action_registry.register('tag')
5779
class TimestreamTag(TagAction):
@@ -81,6 +103,44 @@ def process_resource_set(self, client, resource_set, tag_keys):
81103
TimestreamTable.filter_registry.register('marked-for-op', TagActionFilter)
82104

83105

106+
@TimestreamInfluxDB.action_registry.register('tag')
107+
class TimestreamInfluxDBTag(TagAction):
108+
109+
permissions = ('timestream-influxdb:TagResource', )
110+
111+
def process_resource_set(self, client, resource_set, tags):
112+
tags = {item['Key']: item['Value'] for item in tags}
113+
for r in resource_set:
114+
client.tag_resource(resourceArn=r['arn'], tags=tags)
115+
116+
117+
@TimestreamInfluxDB.action_registry.register('remove-tag')
118+
class TimestreamInfluxDBRemoveTag(RemoveTagAction):
119+
120+
permissions = ('timestream-influxdb:UntagResource', )
121+
122+
def process_resource_set(self, client, resource_set, tag_keys):
123+
for r in resource_set:
124+
client.untag_resource(resourceArn=r['arn'], tagKeys=tag_keys)
125+
126+
127+
TimestreamInfluxDB.action_registry.register('mark-for-op', TagDelayedAction)
128+
129+
TimestreamInfluxDB.filter_registry.register('marked-for-op', TagActionFilter)
130+
131+
132+
@TimestreamInfluxDB.filter_registry.register('security-group')
133+
class TimestreamInfluxDBSGFilter(SecurityGroupFilter):
134+
135+
RelatedIdsExpression = "vpcSecurityGroupIds[]"
136+
137+
138+
@TimestreamInfluxDB.filter_registry.register('subnet')
139+
class TimestreamInfluxDBSubnetFilter(SubnetFilter):
140+
141+
RelatedIdsExpression = "vpcSubnetIds[]"
142+
143+
84144
@TimestreamTable.action_registry.register('delete')
85145
class TimestreamTableDelete(Action):
86146
"""
@@ -145,3 +205,32 @@ def process(self, resources):
145205
@TimestreamDatabase.filter_registry.register('kms-key')
146206
class KmsFilter(KmsRelatedFilter):
147207
RelatedIdsExpression = 'KmsKeyId'
208+
209+
210+
@TimestreamInfluxDB.action_registry.register('delete')
211+
class TimestreamInfluxDBDelete(Action):
212+
"""Delete timestream influx-db instance.
213+
214+
:example:
215+
216+
.. code-block:: yaml
217+
218+
policies:
219+
- name: timestream-influxdb-delete
220+
resource: timestream-influxdb
221+
actions:
222+
- type: delete
223+
"""
224+
225+
schema = type_schema('delete')
226+
permissions = ('timestream-influxdb:DeleteDbInstance', )
227+
228+
def process(self, resources):
229+
client = local_session(self.manager.session_factory).client('timestream-influxdb')
230+
for r in resources:
231+
try:
232+
client.delete_db_instance(
233+
identifier=r['id']
234+
)
235+
except client.exceptions.ResourceNotFoundException:
236+
continue
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"id": "hvnr971atp",
5+
"name": "example-db",
6+
"arn": "arn:aws:timestream-influxdb:us-east-1:644160558196:db-instance/hvnr971atp",
7+
"status": "DELETING",
8+
"endpoint": "example-db-kx3to6fbi4fumn.us-east-1.timestream-influxdb.amazonaws.com",
9+
"port": 8086,
10+
"dbInstanceType": "db.influx.medium",
11+
"dbStorageType": "InfluxIOIncludedT1",
12+
"allocatedStorage": 20,
13+
"deploymentType": "SINGLE_AZ",
14+
"vpcSubnetIds": [
15+
"subnet-efbcccb7",
16+
"subnet-914763e7"
17+
],
18+
"publiclyAccessible": false,
19+
"vpcSecurityGroupIds": [
20+
"sg-6c7fa917"
21+
],
22+
"influxAuthParametersSecretArn": "arn:aws:secretsmanager:us-east-1:644160558196:secret:READONLY-InfluxDB-auth-parameters-hvnr971atp-exLmsO",
23+
"ResponseMetadata": {}
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"id": "hvnr971atp",
5+
"name": "example-db",
6+
"arn": "arn:aws:timestream-influxdb:us-east-1:644160558196:db-instance/hvnr971atp",
7+
"status": "AVAILABLE",
8+
"endpoint": "example-db-kx3to6fbi4fumn.us-east-1.timestream-influxdb.amazonaws.com",
9+
"port": 8086,
10+
"dbInstanceType": "db.influx.medium",
11+
"dbStorageType": "InfluxIOIncludedT1",
12+
"allocatedStorage": 20,
13+
"deploymentType": "SINGLE_AZ",
14+
"vpcSubnetIds": [
15+
"subnet-efbcccb7",
16+
"subnet-914763e7"
17+
],
18+
"publiclyAccessible": false,
19+
"vpcSecurityGroupIds": [
20+
"sg-6c7fa917"
21+
],
22+
"availabilityZone": "us-east-1b",
23+
"influxAuthParametersSecretArn": "arn:aws:secretsmanager:us-east-1:644160558196:secret:READONLY-InfluxDB-auth-parameters-hvnr971atp-exLmsO",
24+
"ResponseMetadata": {}
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"id": "hvnr971atp",
5+
"name": "example-db",
6+
"arn": "arn:aws:timestream-influxdb:us-east-1:644160558196:db-instance/hvnr971atp",
7+
"status": "DELETING",
8+
"endpoint": "example-db-kx3to6fbi4fumn.us-east-1.timestream-influxdb.amazonaws.com",
9+
"port": 8086,
10+
"dbInstanceType": "db.influx.medium",
11+
"dbStorageType": "InfluxIOIncludedT1",
12+
"allocatedStorage": 20,
13+
"deploymentType": "SINGLE_AZ",
14+
"vpcSubnetIds": [
15+
"subnet-efbcccb7",
16+
"subnet-914763e7"
17+
],
18+
"publiclyAccessible": false,
19+
"vpcSecurityGroupIds": [
20+
"sg-6c7fa917"
21+
],
22+
"availabilityZone": "us-east-1b",
23+
"influxAuthParametersSecretArn": "arn:aws:secretsmanager:us-east-1:644160558196:secret:READONLY-InfluxDB-auth-parameters-hvnr971atp-exLmsO",
24+
"ResponseMetadata": {}
25+
}
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"items": [
5+
{
6+
"id": "hvnr971atp",
7+
"name": "example-db",
8+
"arn": "arn:aws:timestream-influxdb:us-east-1:644160558196:db-instance/hvnr971atp",
9+
"status": "AVAILABLE",
10+
"endpoint": "example-db-kx3to6fbi4fumn.us-east-1.timestream-influxdb.amazonaws.com",
11+
"port": 8086,
12+
"dbInstanceType": "db.influx.medium",
13+
"dbStorageType": "InfluxIOIncludedT1",
14+
"allocatedStorage": 20,
15+
"deploymentType": "SINGLE_AZ"
16+
}
17+
],
18+
"ResponseMetadata": {}
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"items": [
5+
{
6+
"id": "hvnr971atp",
7+
"name": "example-db",
8+
"arn": "arn:aws:timestream-influxdb:us-east-1:644160558196:db-instance/hvnr971atp",
9+
"status": "DELETING",
10+
"endpoint": "example-db-kx3to6fbi4fumn.us-east-1.timestream-influxdb.amazonaws.com",
11+
"port": 8086,
12+
"dbInstanceType": "db.influx.medium",
13+
"dbStorageType": "InfluxIOIncludedT1",
14+
"allocatedStorage": 20,
15+
"deploymentType": "SINGLE_AZ"
16+
}
17+
],
18+
"ResponseMetadata": {}
19+
}
20+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"tags": {},
5+
"ResponseMetadata": {}
6+
}
7+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"id": "4nmqhy3bjg",
5+
"name": "db-name-sample",
6+
"arn": "arn:aws:timestream-influxdb:us-east-1:644160558196:db-instance/4nmqhy3bjg",
7+
"status": "AVAILABLE",
8+
"endpoint": "db-name-sample-kx3to6fbi4fumn.us-east-1.timestream-influxdb.amazonaws.com",
9+
"port": 8086,
10+
"dbInstanceType": "db.influx.medium",
11+
"dbStorageType": "InfluxIOIncludedT1",
12+
"allocatedStorage": 20,
13+
"deploymentType": "SINGLE_AZ",
14+
"vpcSubnetIds": [
15+
"subnet-efbcccb7",
16+
"subnet-914763e7"
17+
],
18+
"publiclyAccessible": false,
19+
"vpcSecurityGroupIds": [
20+
"sg-6c7fa917"
21+
],
22+
"availabilityZone": "us-east-1b",
23+
"influxAuthParametersSecretArn": "arn:aws:secretsmanager:us-east-1:644160558196:secret:READONLY-InfluxDB-auth-parameters-4nmqhy3bjg-g97DjK",
24+
"ResponseMetadata": {}
25+
}
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"items": [
5+
{
6+
"id": "4nmqhy3bjg",
7+
"name": "db-name-sample",
8+
"arn": "arn:aws:timestream-influxdb:us-east-1:644160558196:db-instance/4nmqhy3bjg",
9+
"status": "AVAILABLE",
10+
"endpoint": "db-name-sample-kx3to6fbi4fumn.us-east-1.timestream-influxdb.amazonaws.com",
11+
"port": 8086,
12+
"dbInstanceType": "db.influx.medium",
13+
"dbStorageType": "InfluxIOIncludedT1",
14+
"allocatedStorage": 20,
15+
"deploymentType": "SINGLE_AZ"
16+
}
17+
],
18+
"ResponseMetadata": {}
19+
}
20+
}

0 commit comments

Comments
 (0)