{% set edx_tracking_bucket = 'odl-residential-tracking-backup' %}
{% set edx_tracking_bucket_backup_key = salt.pillar.get('backups:mitx_residential_tracking:aws_key') %}
{% set edx_tracking_bucket_backup_keyid = salt.pillar.get('backups:mitx_residential_tracking:aws_keyid') %}
{% set edx_tracking_local_folder = '/edx/var/log/tracking' %}
{% set instance_id = salt.grains.get('id') %}

tar_tracking_data:
  cmd.run:
    - name: 'tar -czf edx_tracking_{{ instance_id }}.tgz *'
    - cwd: {{ edx_tracking_local_folder }}
    - creates: {{ edx_tracking_local_folder }}/edx_tracking_{{ instance_id }}.tgz

upload_tar_to_s3:
  module.run:
    - name: s3.put
    - bucket: {{ edx_tracking_bucket }}
    - path: 'retired-instance-logs'
    - keyid: {{ edx_tracking_bucket_backup_keyid }}
    - key: {{ edx_tracking_bucket_backup_key }}
    - local_file: {{ edx_tracking_local_folder }}/edx_tracking_{{ instance_id }}.tgz

{% set edx_tracking_bucket = 'odl-residential-tracking-backup' %}
{% set edx_tracking_local_folder = '/edx/var/log/tracking' %}
{% set instance_id = salt.grains.get('id') %}

ensure_tracking_bucket_exists:
  boto_s3_bucket.present:
    - Bucket: {{ edx_tracking_bucket }}
    - region: us-east-1

ensure_instance_profile_exists_for_tracking:
  boto_iam_role.present:
    - name: edx-instance-role
    - delete_policies: False
    - policies:
        edx-old-tracking-logs-policy:
          Statement:
            - Action:
                - s3:*
              Effect: Allow
              Resource:
                - arn:aws:s3:::{{ edx_tracking_bucket }}
                - arn:aws:s3:::{{ edx_tracking_bucket }}/*
    - require:
        - boto_s3_bucket: ensure_tracking_bucket_exists

tar_tracking_data:
  cmd.run:
    - name: 'tar -czf edx_tracking_{{ instance_id }}.tgz *'
    - cwd: {{ edx_tracking_local_folder }}
    - creates: {{ edx_tracking_local_folder }}/edx_tracking_{{ instance_id }}.tgz

upload_tar_to_s3:
  module.run:
    - name: s3.put
    - bucket: {{ edx_tracking_bucket }}
    - path: 'retired-instance-logs'
    - local_file: {{ edx_tracking_local_folder }}/edx_tracking_{{ instance_id }}.tgz

Use edx-instance-role to upload old tracking logs to an S3 bucket and added a check to verify that the S3 bucket exists
Use edx-instance-role to upload old tracking logs to an S3 bucket and added a check to verify that the S3 bucket exists

mitodl/salt-ops,mitodl/salt-ops