Skip to content

Commit

Permalink
[IT-3396] Use a better jinja linter
Browse files Browse the repository at this point in the history
Switch to using a better Jinja linter and fix linter errors
  • Loading branch information
zaro0508 committed Apr 8, 2024
1 parent df3e2b9 commit 20ef4ef
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 37 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ jobs:
with:
python-version: 3.9
- uses: pre-commit/action@v3.0.0
jinja-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install jinja libraries
run: |
python -m pip install --upgrade jinja2==3.0.1
- name: Install jinja linter tool
run: git clone --single-branch https://github.com/drm/jinja2-lint.git /tmp/jinja2-lint && pushd /tmp/jinja2-lint && git checkout 75dcd5a
- name: Execute jinja linter
run: find . -type f -name "*.j2" -exec /tmp/jinja2-lint/j2lint.py '{}' +
deploy:
name: Upload to Amazon S3
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ repos:
rev: v1.5.4
hooks:
- id: remove-tabs
- repo: https://github.com/aristanetworks/j2lint.git
rev: v1.1.0
hooks:
- id: j2lint
args: [--ignore, V1, --]
4 changes: 2 additions & 2 deletions templates/EC2/basic-ec2.j2
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ Resources:
GroupDescription: "Allow ports for incoming traffic"
VpcId: !Ref VpcId
SecurityGroupIngress:
{% for port in sceptre_user_data.OpenPorts %}
{% for port in sceptre_user_data.OpenPorts %}
- CidrIp: "0.0.0.0/0"
FromPort: {{ port }}
ToPort: {{ port }}
IpProtocol: tcp
{% endfor %}
{% endfor %}
{% endif %}
Instance:
Type: 'AWS::EC2::Instance'
Expand Down
4 changes: 2 additions & 2 deletions templates/EC2/jc-ec2-linux.j2
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ Resources:
VpcId: !ImportValue
'Fn::Sub': '${AWS::Region}-${VpcName}-VPCId'
SecurityGroupIngress:
{% for port in sceptre_user_data.OpenPorts %}
{% for port in sceptre_user_data.OpenPorts %}
- CidrIp: "0.0.0.0/0"
FromPort: {{ port }}
ToPort: {{ port }}
IpProtocol: tcp
{% endfor %}
{% endfor %}
SecurityGroupEgress:
- CidrIp: "0.0.0.0/0"
FromPort: -1
Expand Down
4 changes: 2 additions & 2 deletions templates/EC2/jc-ec2-win.j2
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ Resources:
VpcId: !ImportValue
'Fn::Sub': '${AWS::Region}-${VpcName}-VPCId'
SecurityGroupIngress:
{% for port in sceptre_user_data.OpenPorts %}
{% for port in sceptre_user_data.OpenPorts %}
- CidrIp: "0.0.0.0/0"
FromPort: {{ port }}
ToPort: {{ port }}
IpProtocol: tcp
{% endfor %}
{% endfor %}
SecurityGroupEgress:
- CidrIp: "0.0.0.0/0"
FromPort: -1
Expand Down
18 changes: 9 additions & 9 deletions templates/IAM/github-oidc-provider.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
{# GitHubOrg: "Sage-Bionetworks" #}

{% if sceptre_user_data.Repositories is defined %}
{% set Repositories = sceptre_user_data.Repositories %}
{% set Repositories = sceptre_user_data.Repositories %}
{% endif %}
{% if sceptre_user_data.GitHubOrg is defined %}
{% set GitHubOrg = sceptre_user_data.GitHubOrg %}
{% set GitHubOrg = sceptre_user_data.GitHubOrg %}
{% endif %}

AWSTemplateFormatVersion: 2010-09-09
Expand Down Expand Up @@ -104,13 +104,13 @@ Resources:
StringLike:
token.actions.githubusercontent.com:sub: [
{% for Repository in Repositories %}
{% for branch in Repository.branches %}
{% if branch == '*' %}
"repo:{{ GitHubOrg}}/{{ Repository.name }}:{{ branch }}",
{% else %}
"repo:{{ GitHubOrg}}/{{ Repository.name }}:ref:refs/heads/{{ branch }}",
{% endif %}
{% endfor %}
{% for branch in Repository.branches %}
{% if branch == '*' %}
"repo:{{ GitHubOrg }}/{{ Repository.name }}:{{ branch }}",
{% else %}
"repo:{{ GitHubOrg }}/{{ Repository.name }}:ref:refs/heads/{{ branch }}",
{% endif %}
{% endfor %}
"repo:{{ GitHubOrg }}/{{ Repository.name }}:ref:refs/tags/*",
"repo:{{ GitHubOrg }}/{{ Repository.name }}:environment:*",
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions templates/S3/synapse-external-bucket.j2
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ Resources:
Key: owner.txt
ContentType: text
Body: >-
{% for SynapseID in sceptre_user_data.SynapseIDs %}
{% for SynapseID in sceptre_user_data.SynapseIDs %}
{{ SynapseID }}
{% endfor %}
{% endfor %}
{% endif %}

IPAddressRestictionLambda:
Expand Down
10 changes: 5 additions & 5 deletions templates/SystemsManager/ssm-parameters.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
template_path: remote/ssm-parameters.j2
hooks:
before_launch:
- !cmd "curl https://{{stack_group_config.admincentral_cf_bucket}}.s3.amazonaws.com/aws-infra/master/ssm-parameters.j2 --create-dirs -o templates/remote/ssm-parameters.j2"
- !cmd "curl https://{{ stack_group_config.admincentral_cf_bucket }}.s3.amazonaws.com/aws-infra/master/ssm-parameters.j2 --create-dirs -o templates/remote/ssm-parameters.j2"
stack_name: my-ssm-vars
sceptre_user_data:
Prefix: /my-ssm-vars/
Expand All @@ -24,8 +24,8 @@ Description: "Setup parameters in the SSM parameter store"
AWSTemplateFormatVersion: "2010-09-09"
Resources:
{% for parameter in sceptre_user_data.Parameters %}
{%- set name = parameter.Name -%}
{%- set value = parameter.Value|safe -%}
{% set name = parameter.Name %}
{% set value = parameter.Value | safe %}
{{ name }}:
Type: AWS::SSM::Parameter
Properties:
Expand All @@ -39,8 +39,8 @@ Outputs:
Export:
Name: !Sub '${AWS::Region}-${AWS::StackName}-Prefix'
{% for parameter in sceptre_user_data.Parameters %}
{%- set name = parameter.Name -%}
{%- set value = parameter.Value -%}
{% set name = parameter.Name %}
{% set value = parameter.Value %}
{{ name }}:
Value: !GetAtt {{ name }}.Value
Export:
Expand Down

0 comments on commit 20ef4ef

Please sign in to comment.