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:
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 echo "---> terraform_s3_docs_ship.sh"
20 cat >"/w/workspace/main.tf" <<'END_OF_TERRAFORM_SCRIPT'
24 source = "hashicorp/aws"
33 s3_use_path_style = false
34 skip_credentials_validation = true
35 skip_metadata_api_check = true
36 skip_requesting_account_id = true
41 xml = "application/xml",
49 svg = "image/svg+xml",
53 js = "application/javascript",
54 pdf = "application/pdf"
55 json = "application/json",
63 variable "workspace_dir" {
64 description = "Workspace base directory"
68 variable "file_match_pattern" {
69 description = "File matching pattern"
75 description = "S3 bucket name"
79 variable "bucket_path" {
80 description = "S3 bucket path to key"
84 resource "aws_s3_bucket_object" "object" {
85 for_each = fileset(var.workspace_dir, var.file_match_pattern)
88 key = "${var.bucket_path}${each.value}"
89 source = "${var.workspace_dir}/${each.value}"
91 cache_control = "no-store,max-age=0,s-maxage=0"
92 etag = filemd5("${var.workspace_dir}/${each.value}")
93 content_type = lookup(
95 regex("\\.(?P<extension>[A-Za-z0-9]+)$", each.value).extension,
96 "application/octet-stream"
99 END_OF_TERRAFORM_SCRIPT