Skip to content

Commit 9e29a2e

Browse files
committed
feat(sks): add support to new Exoscale IAM keys
1 parent f8f1f68 commit 9e29a2e

2 files changed

Lines changed: 41 additions & 39 deletions

File tree

examples/sks/s3_buckets.tf

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ locals {
77
}
88

99
resource "aws_s3_bucket" "this" {
10+
provider = aws.exoscale-s3
11+
1012
for_each = toset(local.s3_buckets)
1113

1214
bucket = "${local.cluster_name}-${each.key}"
@@ -20,48 +22,44 @@ resource "aws_s3_bucket" "this" {
2022
}
2123
}
2224

23-
resource "exoscale_iam_access_key" "s3_iam_key" {
25+
# Role based on the example available https://github.com/exoscale/terraform-provider-exoscale/blob/28da8e40dca37d93e4f3438f3bf906ef400f5b07/examples/iam-bucket-access/main.tf
26+
resource "exoscale_iam_role" "s3_role" {
2427
for_each = toset(local.s3_buckets)
2528

26-
name = "${local.cluster_name}-${each.key}-s3-iam-key"
27-
resources = ["sos/bucket:${local.cluster_name}-${each.key}"]
29+
name = "${local.cluster_name}-${each.key}-s3-role"
30+
description = "Role for SOS bucket ${each.key} for the ${local.cluster_name} SKS cluster. Created using Terraform."
31+
editable = true
2832

29-
# Probably not all these permissions are needed. However, these IAM keys are resource-scoped, so there should be no
30-
# issue. The only SOS permissions commented out are the ones related to the creation and deletion of an SOS bucket.
31-
operations = [
32-
"abort-sos-multipart-upload",
33-
"by-pass-sos-governance-retention",
34-
# "create-sos-bucket",
35-
# "delete-sos-bucket",
36-
"delete-sos-object",
37-
"get-sos-bucket-acl",
38-
"get-sos-bucket-cors",
39-
"get-sos-bucket-location",
40-
"get-sos-bucket-object-lock-configuration",
41-
"get-sos-bucket-ownership-controls",
42-
"get-sos-bucket-versioning",
43-
"get-sos-object",
44-
"get-sos-object-acl",
45-
"get-sos-object-legal-hold",
46-
"get-sos-object-retention",
47-
"get-sos-presigned-url",
48-
"list-sos-bucket",
49-
"list-sos-bucket-multipart-uploads",
50-
"list-sos-bucket-versions",
51-
"list-sos-buckets",
52-
"list-sos-buckets-usage",
53-
"put-sos-bucket-acl",
54-
"put-sos-bucket-cors",
55-
"put-sos-bucket-object-lock-configuration",
56-
"put-sos-bucket-ownership-controls",
57-
"put-sos-bucket-versioning",
58-
"put-sos-object",
59-
"put-sos-object-acl",
60-
"put-sos-object-legal-hold",
61-
"put-sos-object-retention",
62-
]
33+
policy = {
34+
default_service_strategy = "deny"
35+
services = {
36+
sos = {
37+
# These rules are used in order, so if a rule does not match, the following rules are NOT evaluated.
38+
# In these settings, we first allow all operations except create-bucket and delete-bucket, then we deny all
39+
# operations on buckets that are not the one that the role relates to.
40+
type = "rules"
41+
rules = [
42+
{
43+
expression = "!(operation in ['create-bucket', 'delete-bucket'])"
44+
action = "allow"
45+
},
46+
{
47+
expression = "!(parameters.bucket in ['${each.key}'])"
48+
action = "deny"
49+
},
50+
]
51+
}
52+
}
53+
}
54+
}
55+
56+
resource "exoscale_iam_api_key" "s3_iam_api_key" {
57+
for_each = toset(local.s3_buckets)
58+
59+
name = "${local.cluster_name}-${each.key}-s3-iam-key"
60+
role_id = resource.exoscale_iam_role.s3_role[each.key].id
6361

6462
depends_on = [
65-
aws_s3_bucket.this,
63+
resource.aws_s3_bucket.this,
6664
]
6765
}

examples/sks/terraform.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ terraform {
1212
required_providers {
1313
exoscale = {
1414
source = "exoscale/exoscale"
15-
version = "~> 0.51"
15+
version = "~> 0.59"
1616
}
1717
aws = { # Needed to store the state file in S3 and to create S3 buckets (provider configuration bellow)
1818
source = "hashicorp/aws"
@@ -37,7 +37,11 @@ terraform {
3737
}
3838
}
3939

40+
provider "aws" {}
41+
4042
provider "aws" {
43+
alias = "exoscale-s3"
44+
4145
endpoints {
4246
s3 = "https://sos-${local.zone}.exo.io"
4347
}

0 commit comments

Comments
 (0)