2022-03-10 14:26:22 +00:00
|
|
|
from app.terraform.list import ListAutomation
|
|
|
|
|
|
|
|
|
2022-05-08 17:20:04 +01:00
|
|
|
class ListS3Automation(ListAutomation):
|
2022-03-10 14:26:22 +00:00
|
|
|
short_name = "list_s3"
|
2022-05-08 17:20:04 +01:00
|
|
|
description = "Update mirror lists in AWS S3 buckets"
|
2022-03-10 14:26:22 +00:00
|
|
|
provider = "s3"
|
|
|
|
|
|
|
|
template_parameters = [
|
|
|
|
"aws_access_key",
|
|
|
|
"aws_secret_key"
|
|
|
|
]
|
|
|
|
|
|
|
|
template = """
|
|
|
|
terraform {
|
|
|
|
required_providers {
|
|
|
|
aws = {
|
|
|
|
version = "~> 4.4.0"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-11 16:12:52 +01:00
|
|
|
{% for list in lists %}
|
2022-03-10 14:26:22 +00:00
|
|
|
provider "aws" {
|
|
|
|
access_key = "{{ aws_access_key }}"
|
|
|
|
secret_key = "{{ aws_secret_key }}"
|
2022-05-11 16:12:52 +01:00
|
|
|
region = "{{ list.branch }}"
|
|
|
|
{% if list.role %}
|
|
|
|
assume_role {
|
|
|
|
role_arn = "{{ list.role }}"
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
alias = "list_{{ list.id }}"
|
2022-03-10 14:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_s3_object" "object_{{ list.id }}" {
|
2022-05-11 16:12:52 +01:00
|
|
|
provider = aws.list_{{ list.id }}
|
2022-03-10 14:26:22 +00:00
|
|
|
bucket = "{{ list.container }}"
|
|
|
|
key = "{{ list.filename }}"
|
|
|
|
source = "{{ list.format }}.json"
|
|
|
|
content_type = "application/json"
|
2022-05-16 17:09:33 +01:00
|
|
|
etag = filemd5("{{ list.format }}.{{ list.encoding }}")
|
2022-03-10 14:26:22 +00:00
|
|
|
}
|
|
|
|
{% endfor %}
|
|
|
|
"""
|