Skip to content
This repository was archived by the owner on Jun 3, 2023. It is now read-only.

Commit 6790fcd

Browse files
committed
add cors policy
1 parent 0fd8792 commit 6790fcd

File tree

7 files changed

+121
-47
lines changed

7 files changed

+121
-47
lines changed

.github/workflows/readme.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
actions_subcommand: 'readme'
2424
github_token: '${{ secrets.GITHUB }}'
2525
env:
26-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
GITHUB_TOKEN: ${{ secrets.CLOUDDROVE_GITHUB_TOKEN }}
2727

2828

2929
- name: 'pre-commit check errors'

.github/workflows/terraform.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ jobs:
1313
uses: actions/checkout@master
1414

1515
- name: 'Terraform Format'
16-
uses: 'clouddrove/[email protected]'
16+
uses: 'clouddrove/[email protected].1'
1717
with:
1818
actions_subcommand: 'fmt'
1919

2020
- name: 'Terraform init'
21-
uses: 'clouddrove/[email protected]'
21+
uses: 'clouddrove/[email protected].1'
2222
with:
2323
actions_subcommand: 'init'
2424
tf_actions_working_dir: ./_example
2525

2626
- name: 'Terraform validate'
27-
uses: 'clouddrove/[email protected]'
27+
uses: 'clouddrove/[email protected].1'
2828
with:
2929
actions_subcommand: 'validate'
3030
tf_actions_working_dir: ./_example
3131

3232
- name: 'Terraform plan'
33-
uses: 'clouddrove/[email protected]'
33+
uses: 'clouddrove/[email protected].1'
3434
with:
3535
actions_subcommand: 'plan'
3636
tf_actions_working_dir: ./_example

.github/workflows/terratest.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,20 @@ jobs:
1414
- name: 'Checkout'
1515
uses: actions/checkout@master
1616

17-
- name: Configure AWS Credentials
18-
uses: clouddrove/configure-aws-credentials@v1
17+
- name: Install doctl
18+
uses: digitalocean/action-doctl@v2
1919
with:
20-
aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY }}
21-
aws-secret-access-key: ${{ secrets.TEST_AWS_ACCESS_SECRET_KEY }}
22-
aws-region: us-east-2
23-
20+
token: ${{ secrets.DO_TOKEN }}
2421

2522
- name: 'Terratest'
2623
if: ${{ github.event.label.name == 'terratest' }}
27-
uses: 'clouddrove/[email protected]'
24+
uses: 'clouddrove/[email protected].1'
2825
with:
2926
actions_subcommand: 'terratest'
3027
tf_actions_working_dir: '_test'
3128
env:
3229
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
DO_TOKEN: ${{ secrets.DO_TOKEN }}
3331

3432

3533
- name: 'Slack Notification'

_example/.terraform.lock.hcl

Lines changed: 0 additions & 24 deletions
This file was deleted.

_example/example.tf

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,33 @@
22
provider "digitalocean" {
33
# You need to set this in your .bashrc
44
# export DIGITALOCEAN_TOKEN="Your API TOKEN"
5-
spaces_access_id = "xxxxxxxxxxx"
6-
spaces_secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxx"
5+
spaces_access_id = "ING6PR3ZYTSCEI2KHDBY"
6+
spaces_secret_key = "YuCbsjncTnDwUaBhsy1SUzMAW2eD6cTkaZqSamB1pvk"
77
}
88

99

1010
module "spaces" {
11-
source = "./../"
11+
source = "./../"
1212
name = "clouddrove"
1313
environment = "test"
14-
label_order = ["name"]
14+
label_order = ["name", "environment"]
1515
acl = "public-read"
1616
force_destroy = true
1717
region = "nyc3"
1818

19-
}
19+
cors_rule = [{
20+
"allowed_headers" : ["*"]
21+
allowed_methods = ["PUT", "POST"],
22+
allowed_origins = ["https://s3-website-test.hashicorp.com"],
23+
expose_headers = ["ETag"],
24+
max_age_seconds = 3000 }]
25+
26+
prefix = true
27+
abort_incomplete_multipart_upload_days = "30"
28+
date = "2021-09-06"
29+
expiration_days = "30"
30+
expired_object_delete_marker = true
31+
noncurrent_version_expiration = "30"
32+
33+
}
34+

main.tf

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,49 @@ module "labels" {
2727
name = var.name
2828
environment = var.environment
2929
label_order = var.label_order
30+
attributes = var.attributes
31+
3032

3133
}
3234

3335
#Module : Spaces
3436
#Description : Provides a bucket resource for Spaces, DigitalOcean's object storage product.
3537

3638
resource "digitalocean_spaces_bucket" "spaces" {
37-
name = var.name
38-
region = var.region
39-
acl = var.acl
40-
force_destroy = var.force_destroy
39+
name = module.labels.id
40+
region = var.region
41+
acl = var.acl
4142

42-
}
43+
force_destroy = var.force_destroy
44+
45+
dynamic "cors_rule" {
46+
for_each = var.cors_rule == null ? [] : var.cors_rule
47+
48+
content {
49+
allowed_headers = cors_rule.value.allowed_headers
50+
allowed_methods = cors_rule.value.allowed_methods
51+
allowed_origins = cors_rule.value.allowed_origins
52+
max_age_seconds = cors_rule.value.max_age_seconds
53+
}
54+
}
55+
56+
lifecycle_rule {
57+
enabled = false
58+
prefix = var.prefix
59+
60+
abort_incomplete_multipart_upload_days = var.abort_incomplete_multipart_upload_days
61+
expiration {
62+
date = var.date
63+
days = var.expiration_days
64+
65+
expired_object_delete_marker = var.expired_object_delete_marker
66+
}
67+
noncurrent_version_expiration {
68+
days = var.noncurrent_version_expiration
69+
}
70+
}
71+
versioning {
72+
enabled = var.versioning
73+
}
4374

75+
}

variables.tf

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ variable "delimiter" {
2323
default = "-"
2424
description = "Delimiter to be used between `organization`, `environment`, `name` and `attributes`."
2525
}
26-
26+
variable "attributes" {
27+
type = list(any)
28+
default = []
29+
description = "Additional attributes (e.g. `1`)."
30+
}
2731

2832
variable "region" {
2933
type = string
@@ -52,3 +56,52 @@ variable "force_destroy" {
5256
default = false
5357
description = "Unless true, the bucket will only be destroyed if empty (Defaults to false)."
5458
}
59+
60+
variable "cors_rule" {
61+
type = list(object({
62+
allowed_headers = list(string)
63+
allowed_methods = list(string)
64+
allowed_origins = list(string)
65+
expose_headers = list(string)
66+
max_age_seconds = number
67+
}))
68+
default = null
69+
description = "CORS Configuration specification for this bucket"
70+
}
71+
72+
variable "prefix" {
73+
type = string
74+
default = null
75+
description = " (Optional, Forces new resource) Creates a unique bucket name beginning with the specified prefix."
76+
}
77+
78+
variable "abort_incomplete_multipart_upload_days" {
79+
type = number
80+
default = null
81+
description = "Specifies the number of days after initiating a multipart upload when the multipart upload must be completed or else Spaces will abort the upload."
82+
}
83+
84+
variable "date" {
85+
type = string
86+
default = null
87+
description = "pecifies the date/time after which you want applicable objects to expire. The argument uses RFC3339 format, e.g.(2020-03-22T15:03:55Z) or parts thereof e.g. 2019-02-28."
88+
}
89+
90+
variable "expiration_days" {
91+
type = number
92+
default = null
93+
description = "Specifies the number of days after object creation when the applicable objects will expire."
94+
95+
}
96+
97+
variable "expired_object_delete_marker" {
98+
type = string
99+
default = ""
100+
description = "On a versioned bucket (versioning-enabled or versioning-suspended bucket), setting this to true directs Spaces to delete expired object delete markers."
101+
}
102+
103+
variable "noncurrent_version_expiration" {
104+
type = string
105+
default = ""
106+
description = "On a versioned bucket (versioning-enabled or versioning-suspended bucket), setting this to true directs Spaces to delete expired object delete markers."
107+
}

0 commit comments

Comments
 (0)