aws-cloudformation / cfn-lint

CloudFormation Linter
MIT No Attribution
2.43k stars 587 forks source link

Flag previous generation instance types #2213

Closed PatMyron closed 2 years ago

PatMyron commented 2 years ago

https://github.com/aws-cloudformation/cfn-lint/issues/19, https://github.com/terraform-linters/tflint-ruleset-aws/pull/309 Inspired by @wata727's tflint rules, an informational rule flagging these for the most popular instance-based services: https://aws.amazon.com/ec2/previous-generation/

https://aws.amazon.com/rds/previous-generation/:

https://docs.aws.amazon.com/opensearch-service/latest/developerguide/supported-instance-types.html:

https://aws.amazon.com/elasticache/previous-generation/:

One consideration is that updating some of these values for existing resources causes interruptions


could also add https://aws.amazon.com/redshift/pricing/:

AWS::Redshift::Cluster.NodeType

https://aws.amazon.com/cloudsearch/pricing/ https://aws.amazon.com/ebs/previous-generation/ https://aws.amazon.com/gamelift/previous-generation/ https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-supported-instance-types.html

PatMyron commented 2 years ago

would look something like:

```python matches = [] for resource_type, property_type in [ ('AWS::AutoScaling::LaunchConfiguration', 'InstanceType'), ('AWS::EC2::CapacityReservation', 'InstanceType'), ('AWS::EC2::Host', 'InstanceType'), ('AWS::EC2::Instance', 'InstanceType'), ('AWS::RDS::DBInstance', 'DBInstanceClass'), ('AWS::ElastiCache::CacheCluster', 'CacheNodeType'), ('AWS::ElastiCache::GlobalReplicationGroup', 'CacheNodeType'), ('AWS::ElastiCache::ReplicationGroup', 'CacheNodeType'), ]: for resource_name, resource in cfn.get_resources([resource_type]).items(): if re.search(r'([cmr][1-3]|cc2|cg1|cr1|g2|hi1|hs1|i2|t1)\.', resource.get('Properties', {}).get(property_type, '')): matches.append(RuleMatch(['Resources', resource_name, property_type], 'Upgrade previous generation instance type: ' + resource.get('Properties').get(property_type))) for resource_type, top_level_property_type, property_type in [ ('AWS::EC2::EC2Fleet', 'FleetLaunchTemplateOverridesRequest', 'InstanceType'), ('AWS::EC2::LaunchTemplate', 'LaunchTemplateData', 'InstanceType'), ('AWS::EC2::SpotFleet', 'SpotFleetLaunchSpecification', 'InstanceType'), ('AWS::OpenSearchService::Domain', 'ClusterConfig', 'InstanceType'), ('AWS::Elasticsearch::Domain', 'ElasticsearchClusterConfig', 'InstanceType'), ]: for resource_name, resource in cfn.get_resources([resource_type]).items(): if re.search(r'([cmr][1-3]|cc2|cg1|cr1|g2|hi1|hs1|i2|t1)\.', resource.get('Properties', {}).get(top_level_property_type, {}).get(property_type, '')): matches.append(RuleMatch(['Resources', resource_name, top_level_property_type, property_type], 'Upgrade previous generation instance type: ' + resource.get('Properties').get(top_level_property_type).get(property_type))) return matches ```