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

[IT-3396] Use a better jinja linter #411

Merged
merged 3 commits into from
Apr 9, 2024
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
17 changes: 1 addition & 16 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,11 @@ jobs:
with:
python-version: 3.9
- uses: pre-commit/[email protected]
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
if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }}
needs: [ "pre-commit", "jinja-lint" ]
needs: [ "pre-commit" ]
permissions:
id-token: write
contents: read
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
Loading