CSIT: Set daily jobs cadence to normal
[ci-management.git] / jjb / scripts / terraform_s3_docs_ship.sh
1 #!/bin/bash
2
3 # Copyright (c) 2021 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 echo "---> terraform_s3_docs_ship.sh"
17
18 set -exuo pipefail
19
20 cat >"/w/workspace/main.tf" <<'END_OF_TERRAFORM_SCRIPT'
21 terraform {
22   required_providers {
23     aws = {
24       source  = "hashicorp/aws"
25       version = "5.18.1"
26     }
27   }
28 }
29
30 provider "aws" {
31   region                      = "us-east-1"
32   profile                     = "default"
33   s3_use_path_style           = false
34   skip_credentials_validation = true
35   skip_metadata_api_check     = true
36   skip_requesting_account_id  = true
37 }
38
39 locals {
40   mime_types = {
41     xml   = "application/xml",
42     html  = "text/html",
43     txt   = "text/plain",
44     log   = "text/plain",
45     css   = "text/css",
46     md    = "text/markdown",
47     rst   = "text/x-rst",
48     csv   = "text/csv",
49     svg   = "image/svg+xml",
50     jpg   = "image/jpeg",
51     png   = "image/png",
52     gif   = "image/gif",
53     js    = "application/javascript",
54     pdf   = "application/pdf"
55     json  = "application/json",
56     otf   = "font/otf",
57     ttf   = "font/ttf",
58     woff  = "font/woff",
59     woff2 = "font/woff2"
60   }
61 }
62
63 variable "workspace_dir" {
64   description = "Workspace base directory"
65   type        = string
66 }
67
68 variable "file_match_pattern" {
69   description = "File matching pattern"
70   type        = string
71   default     = "**/*"
72 }
73
74 variable "bucket" {
75   description = "S3 bucket name"
76   type        = string
77 }
78
79 variable "bucket_path" {
80   description = "S3 bucket path to key"
81   type        = string
82 }
83
84 resource "aws_s3_bucket_object" "object" {
85   for_each = fileset(var.workspace_dir, var.file_match_pattern)
86
87   bucket = var.bucket
88   key    = "${var.bucket_path}${each.value}"
89   source = "${var.workspace_dir}/${each.value}"
90
91   cache_control = "no-store,max-age=0,s-maxage=0"
92   etag          = filemd5("${var.workspace_dir}/${each.value}")
93   content_type = lookup(
94     local.mime_types,
95     regex("\\.(?P<extension>[A-Za-z0-9]+)$", each.value).extension,
96     "application/octet-stream"
97   )
98 }
99 END_OF_TERRAFORM_SCRIPT