Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 463 introduce yamllint to improve code consistency #470

Merged
merged 10 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
yaml-files:
- '*.yaml'
- '*.yml'
- '.yamllint'

rules:
braces:
forbid: non-empty
min-spaces-inside-empty: 0
max-spaces-inside-empty: 0
brackets: enable
colons: enable
commas: enable
comments:
level: warning
comments-indentation:
level: warning
document-end: disable
document-start: disable
empty-lines: enable
empty-values: disable
javydekoning marked this conversation as resolved.
Show resolved Hide resolved
empty-values: disable
float-values:
forbid-inf: true
forbid-nan: true
forbid-scientific-notation: true
require-numeral-before-decimal: true
hyphens: enable
indentation: enable
key-duplicates: enable
key-ordering: disable
line-length: disable
new-line-at-end-of-file: disable
new-lines: enable
octal-values: enable
quoted-strings: disable
trailing-spaces: enable
truthy:
level: error
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ test:
pytest src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python -vvv -s -c src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/pytest.ini
pytest src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk -vvv -s -c src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/pytest.ini
pytest src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared -vvv -s -c src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/pytest.ini

lint:
# Linter performs static analysis to catch latent bugs
find src/ -iname "*.py" -not -path "src/.aws-sam/*" | xargs pylint --rcfile .pylintrc
find src -iname "*.yml" -o -iname "*.yaml" -not -path "src/.aws-sam/*" | xargs yamllint -c .yamllint
cfn-lint

build:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ pytest~=6.2.5
pyyaml>=5.4.1
schema~=0.7.5
tox==3.24.4
yamllint~=1.27.1
cfn-lint~=0.60.1
docutils~=0.15.2
2 changes: 1 addition & 1 deletion samples/sample-ec2-java-app-codedeploy/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ phases:
commands:
- mvn clean package --quiet
artifacts:
discard-paths: yes
discard-paths: yes # yamllint disable-line rule:truthy
files:
- target/*
- scripts/*
Expand Down
28 changes: 14 additions & 14 deletions samples/sample-ec2-with-codedeploy/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Resources:
GroupDescription: Access to the Instance
VpcId:
Fn::ImportValue:
Fn::Sub: ${Environment}-vpc-id
Fn::Sub: ${Environment}-vpc-id
SecurityGroupIngressFromPublicALB:
Type: AWS::EC2::SecurityGroupIngress
Properties:
Expand All @@ -147,25 +147,25 @@ Resources:
GroupDescription: Access to the public facing load balancer
VpcId:
Fn::ImportValue:
Fn::Sub: ${Environment}-vpc-id
Fn::Sub: ${Environment}-vpc-id
SecurityGroupIngress:
# Allow access to ALB from anywhere on the internet
- CidrIp: 0.0.0.0/0
IpProtocol: -1
# Allow access to ALB from anywhere on the internet
- CidrIp: 0.0.0.0/0
IpProtocol: -1
PublicLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Scheme: internet-facing
LoadBalancerAttributes:
- Key: idle_timeout.timeout_seconds
Value: '30'
- Key: idle_timeout.timeout_seconds
Value: '30'
Subnets:
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1a
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1b
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1c
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1a
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1b
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1c
SecurityGroups:
- !Ref 'PublicLoadBalancerSG'
ApplicationLoadBalancerHTTPListener:
Expand Down Expand Up @@ -197,7 +197,7 @@ Resources:
Value: "5"
VpcId:
Fn::ImportValue:
Fn::Sub: ${Environment}-vpc-id
Fn::Sub: ${Environment}-vpc-id
ScaleDownCloudWatchAlarm:
Type: "AWS::CloudWatch::Alarm"
Properties:
Expand Down
130 changes: 65 additions & 65 deletions samples/sample-ecs-cluster/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ AWSTemplateFormatVersion: '2010-09-09'
Description: ADF CloudFormation Sample Template (ECS Cluster)
Metadata:
License: Apache-2.0
Parameters:
Environment:
Description: The Current Environment
Type: String
Parameters:
Environment:
Description: The Current Environment
Type: String
Resources:
ECSCluster:
Type: AWS::ECS::Cluster
Expand All @@ -20,7 +20,7 @@ Resources:
GroupDescription: Access to the Fargate containers
VpcId:
Fn::ImportValue:
Fn::Sub: ${Environment}-vpc-id
Fn::Sub: ${Environment}-vpc-id
EcsSecurityGroupIngressFromPublicALB:
Type: AWS::EC2::SecurityGroupIngress
Properties:
Expand All @@ -41,26 +41,26 @@ Resources:
GroupDescription: Access to the public facing load balancer
VpcId:
Fn::ImportValue:
Fn::Sub: ${Environment}-vpc-id
Fn::Sub: ${Environment}-vpc-id
SecurityGroupIngress:
# Allow access to ALB from anywhere on the internet
- CidrIp: 0.0.0.0/0
IpProtocol: -1
# Allow access to ALB from anywhere on the internet
- CidrIp: 0.0.0.0/0
IpProtocol: -1
PublicLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Scheme: internet-facing
LoadBalancerAttributes:
- Key: idle_timeout.timeout_seconds
Value: '30'
Subnets:
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1a
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1b
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1c
SecurityGroups: [!Ref 'PublicLoadBalancerSG']
LoadBalancerAttributes:
- Key: idle_timeout.timeout_seconds
Value: '30'
Subnets:
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1a
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1b
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1c
DummyTargetGroupPublic:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Expand All @@ -75,7 +75,7 @@ Resources:
UnhealthyThresholdCount: 2
VpcId:
Fn::ImportValue:
Fn::Sub: ${Environment}-vpc-id
Fn::Sub: ${Environment}-vpc-id
PublicLoadBalancerListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
Expand All @@ -90,69 +90,69 @@ Resources:
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: [ecs.amazonaws.com]
Action: ['sts:AssumeRole']
- Effect: Allow
Principal:
Service: [ecs.amazonaws.com]
Action: ['sts:AssumeRole']
Path: /
Policies:
- PolicyName: ecs-service
PolicyDocument:
Statement:
- Effect: Allow
Action:
# Rules which allow ECS to attach network interfaces to instances
# on your behalf in order for awsvpc networking mode to work right
- 'ec2:AttachNetworkInterface'
- 'ec2:CreateNetworkInterface'
- 'ec2:CreateNetworkInterfacePermission'
- 'ec2:DeleteNetworkInterface'
- 'ec2:DeleteNetworkInterfacePermission'
- 'ec2:Describe*'
- 'ec2:DetachNetworkInterface'
- PolicyName: ecs-service
PolicyDocument:
Statement:
- Effect: Allow
Action:
# Rules which allow ECS to attach network interfaces to instances
# on your behalf in order for awsvpc networking mode to work right
- 'ec2:AttachNetworkInterface'
- 'ec2:CreateNetworkInterface'
- 'ec2:CreateNetworkInterfacePermission'
- 'ec2:DeleteNetworkInterface'
- 'ec2:DeleteNetworkInterfacePermission'
- 'ec2:Describe*'
- 'ec2:DetachNetworkInterface'

# Rules which allow ECS to update load balancers on your behalf
# with the information sabout how to send traffic to your containers
- 'elasticloadbalancing:DeregisterInstancesFromLoadBalancer'
- 'elasticloadbalancing:DeregisterTargets'
- 'elasticloadbalancing:Describe*'
- 'elasticloadbalancing:RegisterInstancesWithLoadBalancer'
- 'elasticloadbalancing:RegisterTargets'
Resource: '*'
# Rules which allow ECS to update load balancers on your behalf
# with the information sabout how to send traffic to your containers
- 'elasticloadbalancing:DeregisterInstancesFromLoadBalancer'
- 'elasticloadbalancing:DeregisterTargets'
- 'elasticloadbalancing:Describe*'
- 'elasticloadbalancing:RegisterInstancesWithLoadBalancer'
- 'elasticloadbalancing:RegisterTargets'
Resource: '*'

# This is a role which is used by the ECS tasks themselves.
ECSTaskExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: [ecs-tasks.amazonaws.com]
Action: ['sts:AssumeRole']
- Effect: Allow
Principal:
Service: [ecs-tasks.amazonaws.com]
Action: ['sts:AssumeRole']
Path: /
Policies:
- PolicyName: AmazonECSTaskExecutionRolePolicy
PolicyDocument:
Statement:
- Effect: Allow
Action:
# Allow the ECS Tasks to download images from ECR
- 'ecr:GetAuthorizationToken'
- 'ecr:BatchCheckLayerAvailability'
- 'ecr:GetDownloadUrlForLayer'
- 'ecr:BatchGetImage'
- Effect: Allow
Action:
# Allow the ECS Tasks to download images from ECR
- 'ecr:GetAuthorizationToken'
- 'ecr:BatchCheckLayerAvailability'
- 'ecr:GetDownloadUrlForLayer'
- 'ecr:BatchGetImage'

# Allow the ECS tasks to upload logs to CloudWatch
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: '*'
# Allow the ECS tasks to upload logs to CloudWatch
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: '*'
Outputs:
ClusterName:
Description: The name of the ECS cluster
Value: !Ref 'ECSCluster'
Export:
Name: 'ClusterName'
Name: 'ClusterName'
ExternalUrl:
Description: The url of the external load balancer
Value: !Sub http://${PublicLoadBalancer.DNSName}
Expand All @@ -162,7 +162,7 @@ Outputs:
Description: The ARN of the ECS role
Value: !GetAtt 'ECSRole.Arn'
Export:
Name: 'ECSRole'
Name: 'ECSRole'
ECSTaskExecutionRole:
Description: The ARN of the ECS role
Value: !GetAtt 'ECSTaskExecutionRole.Arn'
Expand All @@ -172,9 +172,9 @@ Outputs:
Description: The ARN of the public load balancer's Listener
Value: !Ref PublicLoadBalancerListener
Export:
Name: 'PublicListener'
Name: 'PublicListener'
FargateContainerSecurityGroup:
Description: A security group used to allow Fargate containers to receive traffic
Value: !Ref 'FargateContainerSecurityGroup'
Export:
Name: 'FargateContainerSecurityGroup'
Name: 'FargateContainerSecurityGroup'
16 changes: 8 additions & 8 deletions samples/sample-fargate-node-app/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ Resources:
AssignPublicIp: ENABLED
SecurityGroups:
- Fn::ImportValue: 'FargateContainerSecurityGroup'
Subnets:
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1a
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1b
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1c
Subnets:
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1a
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1b
- Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1c
TaskDefinition: !Ref 'TaskDefinition'
LoadBalancers:
- ContainerName: !Ref 'ServiceName'
Expand All @@ -113,7 +113,7 @@ Resources:
UnhealthyThresholdCount: 2
VpcId:
Fn::ImportValue:
Fn::Sub: ${Environment}-vpc-id
Fn::Sub: ${Environment}-vpc-id
LoadBalancerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Expand Down
6 changes: 3 additions & 3 deletions samples/sample-service-catalog-product/productX/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Resources:
Description: !Ref InstanceDescription
InstanceType: !Ref InstanceType
Name: !Ref InstanceName
OwnerArn: !Sub "arn:${AWS::Partition}:iam::${AWS::AccountId}:user/${UserName}" #In this sample case 'sample-developer' from the IAM stack can be used here
OwnerArn: !Sub "arn:${AWS::Partition}:iam::${AWS::AccountId}:user/${UserName}" # In this sample case 'sample-developer' from the IAM stack can be used here
SubnetId:
Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1a # Imported from sample-vpc
Fn::ImportValue:
Fn::Sub: ${Environment}-public-subnet-1a # Imported from sample-vpc
5 changes: 3 additions & 2 deletions samples/sample-service-catalog-product/template.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# // Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# // SPDX-License-Identifier: Apache-2.0

AWSTemplateFormatVersion: '2010-09-09'
AWSTemplateFormatVersion: "2010-09-09"
Description: ADF CloudFormation Sample Template (Service Catalog Product)
Metadata:
License: Apache-2.0
Expand Down Expand Up @@ -36,7 +36,8 @@ Resources:
Name: Cloud9 Development Environment
Owner: Company
ProvisioningArtifactParameters:
- Info: { "LoadTemplateFromURL": !Ref ProductXTemplateURL }
- Info:
LoadTemplateFromURL: !Ref ProductXTemplateURL
SupportDescription: For help with Cloud9 Dev Environment contact us
SupportEmail: [email protected]
SupportUrl: http://example.com
Expand Down
Loading