Skip to content

Commit 8ebc26e

Browse files
committed
re-ran tests and updated main module
1 parent d502f8c commit 8ebc26e

File tree

6 files changed

+1250
-6
lines changed

6 files changed

+1250
-6
lines changed

README.md

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,50 @@
11
<!-- BEGIN_TF_DOCS -->
22
# Terraform Module Project
33

4-
:no_entry_sign: Do not edit this readme.md file. To learn how to change this content and work with this repository, refer to CONTRIBUTING.md
4+
:no\_entry\_sign: Do not edit this readme.md file. To learn how to change this content and work with this repository, refer to CONTRIBUTING.md
55

66
## Readme Content
77

88
This file will contain any instructional information about this module.
99

1010
## Requirements
1111

12+
| Name | Version |
13+
|------|---------|
14+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.7 |
15+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0.0, < 5.0.0 |
16+
| <a name="requirement_awscc"></a> [awscc](#requirement\_awscc) | >= 0.24.0 |
17+
1218
## Providers
1319

14-
No providers.
20+
| Name | Version |
21+
|------|---------|
22+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0.0, < 5.0.0 |
1523

1624
## Modules
1725

1826
No modules.
1927

2028
## Resources
2129

22-
No resources.
30+
| Name | Type |
31+
|------|------|
32+
| [aws_datasync_location_efs.efs_location](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/datasync_location_efs) | resource |
33+
| [aws_datasync_location_s3.s3_location](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/datasync_location_s3) | resource |
34+
| [aws_iam_role.datasync_role_s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
2335

2436
## Inputs
2537

26-
No inputs.
38+
| Name | Description | Type | Default | Required |
39+
|------|-------------|------|---------|:--------:|
40+
| <a name="input_efs_locations"></a> [efs\_locations](#input\_efs\_locations) | A list of EFS locations and associated configuration | <pre>list(object({<br> name = string<br> access_point_arn = optional(string)<br> ec2_config_security_group_arns = list(string)<br> ec2_config_subnet_arn = string<br> efs_file_system_arn = string<br> file_system_access_role_arn = optional(string)<br> in_transit_encryption = optional(string)<br> subdirectory = optional(string)<br> tags = optional(map(string))<br> }))</pre> | `[]` | no |
41+
| <a name="input_s3_locations"></a> [s3\_locations](#input\_s3\_locations) | A list of S3 locations and associated configuration | <pre>list(object({<br> name = string<br> agent_arns = optional(list(string))<br> s3_bucket_arn = string<br> s3_config_bucket_access_role_arn = optional(string)<br> s3_storage_class = optional(string)<br> subdirectory = optional(string)<br> tags = optional(map(string))<br> create_role = optional(bool)<br> }))</pre> | `[]` | no |
2742

2843
## Outputs
2944

30-
No outputs.
31-
<!-- END_TF_DOCS -->
45+
| Name | Description |
46+
|------|-------------|
47+
| <a name="output_datasync_role_arn"></a> [datasync\_role\_arn](#output\_datasync\_role\_arn) | n/a |
48+
| <a name="output_efs_locations"></a> [efs\_locations](#output\_efs\_locations) | n/a |
49+
| <a name="output_s3_locations"></a> [s3\_locations](#output\_s3\_locations) | n/a |
50+
<!-- END_TF_DOCS -->

main.tf

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#####################################################################################
2+
# Terraform module examples are meant to show an _example_ on how to use a module
3+
# per use-case. The code below should not be copied directly but referenced in order
4+
# to build your own root module that invokes this module
5+
#####################################################################################
6+
7+
# S3 Datasync location
8+
resource "aws_datasync_location_s3" "s3_location" {
9+
for_each = {
10+
for location in var.s3_locations :
11+
location.name => location # Assign key => value
12+
}
13+
s3_bucket_arn = each.value.s3_bucket_arn
14+
s3_storage_class = try(each.value.s3_storage_class, null)
15+
subdirectory = each.value.subdirectory != null ? each.value.subdirectory : "/"
16+
tags = each.value.tags != null ? each.value.tags : {}
17+
agent_arns = try(each.value.agent_arns, null)
18+
19+
s3_config {
20+
bucket_access_role_arn = each.value.s3_config_bucket_access_role_arn != null ? each.value.s3_config_bucket_access_role_arn : aws_iam_role.datasync_role_s3[each.key].arn
21+
}
22+
23+
}
24+
25+
#TFSEC High warning supressed for IAM policy document uses sensitive action 's3:AbortMultipartUpload' on wildcarded resource.
26+
# Ref Doc : https://docs.aws.amazon.com/datasync/latest/userguide/create-s3-location.html#create-role-manually
27+
#tfsec:ignore:aws-iam-no-policy-wildcards
28+
resource "aws_iam_role" "datasync_role_s3" {
29+
30+
for_each = {
31+
for index, location in var.s3_locations :
32+
location.name => location if try(location.create_role, false)
33+
}
34+
35+
assume_role_policy = jsonencode({
36+
Version = "2012-10-17"
37+
Statement = [
38+
{
39+
Action = "sts:AssumeRole"
40+
Effect = "Allow"
41+
Sid = "datasyncAssumeRole"
42+
Principal = {
43+
Service = "datasync.amazonaws.com"
44+
}
45+
},
46+
]
47+
})
48+
49+
inline_policy {
50+
name = "datasync_inline_policy"
51+
policy = jsonencode({
52+
Version = "2012-10-17"
53+
Statement = [
54+
{
55+
Sid = "allowListGetBucket"
56+
Action = [
57+
"s3:GetBucketLocation",
58+
"s3:ListBucket",
59+
"s3:ListBucketMultipartUploads",
60+
]
61+
Effect = "Allow"
62+
Resource = each.value.s3_bucket_arn
63+
},
64+
{
65+
Sid = "allowBucketObjects"
66+
Action = [
67+
"s3:AbortMultipartUpload",
68+
"s3:DeleteObject",
69+
"s3:GetObject",
70+
"s3:ListMultipartUploadParts",
71+
"s3:PutObjectTagging",
72+
"s3:GetObjectTagging",
73+
"s3:PutObject",
74+
]
75+
Effect = "Allow"
76+
Resource = "${each.value.s3_bucket_arn}/*"
77+
},
78+
{
79+
Sid = "allowKMSAccess"
80+
Effect = "Allow",
81+
Action = [
82+
"kms:Encrypt",
83+
"kms:Decrypt",
84+
"kms:DescribeKey",
85+
"kms:GenerateDataKey"
86+
],
87+
Resource = "arn:aws:kms:*:*:key/*"
88+
}
89+
]
90+
})
91+
}
92+
}
93+
94+
# EFS Datasync location
95+
resource "aws_datasync_location_efs" "efs_location" {
96+
for_each = {
97+
for location in var.efs_locations :
98+
location.name => location # Assign key => value
99+
}
100+
efs_file_system_arn = each.value.efs_file_system_arn
101+
subdirectory = each.value.subdirectory != null ? each.value.subdirectory : "/"
102+
tags = each.value.tags != null ? each.value.tags : {}
103+
104+
ec2_config {
105+
subnet_arn = each.value.ec2_config_subnet_arn
106+
security_group_arns = each.value.ec2_config_security_group_arns
107+
}
108+
109+
}

outputs.tf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
output "s3_locations" {
2+
value = aws_datasync_location_s3.s3_location
3+
}
4+
5+
output "efs_locations" {
6+
value = aws_datasync_location_efs.efs_location
7+
}
8+
9+
output "datasync_role_arn" {
10+
value = { for k, role in aws_iam_role.datasync_role_s3 : k => role.arn }
11+
}
12+

test/go.mod

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
module github.com/prabirsekhri/terraform-aws-datasync
2+
3+
go 1.20
4+
5+
require (
6+
github.com/aws/aws-sdk-go-v2 v1.26.1
7+
github.com/aws/aws-sdk-go-v2/config v1.27.10
8+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6
9+
github.com/gruntwork-io/terratest v0.46.11
10+
)
11+
12+
require (
13+
cloud.google.com/go v0.110.0 // indirect
14+
cloud.google.com/go/compute v1.19.1 // indirect
15+
cloud.google.com/go/compute/metadata v0.2.3 // indirect
16+
cloud.google.com/go/iam v0.13.0 // indirect
17+
cloud.google.com/go/storage v1.28.1 // indirect
18+
github.com/agext/levenshtein v1.2.3 // indirect
19+
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
20+
github.com/aws/aws-sdk-go v1.51.13 // indirect
21+
github.com/aws/aws-sdk-go-v2/credentials v1.17.10 // indirect
22+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect
23+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect
24+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect
25+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
26+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
27+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect
28+
github.com/aws/aws-sdk-go-v2/service/sso v1.20.4 // indirect
29+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect
30+
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect
31+
github.com/aws/smithy-go v1.20.2 // indirect
32+
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
33+
github.com/davecgh/go-spew v1.1.1 // indirect
34+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
35+
github.com/golang/protobuf v1.5.3 // indirect
36+
github.com/google/go-cmp v0.5.9 // indirect
37+
github.com/google/uuid v1.3.0 // indirect
38+
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
39+
github.com/googleapis/gax-go/v2 v2.7.1 // indirect
40+
github.com/hashicorp/errwrap v1.0.0 // indirect
41+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
42+
github.com/hashicorp/go-getter v1.7.1 // indirect
43+
github.com/hashicorp/go-multierror v1.1.0 // indirect
44+
github.com/hashicorp/go-safetemp v1.0.0 // indirect
45+
github.com/hashicorp/go-version v1.6.0 // indirect
46+
github.com/hashicorp/hcl/v2 v2.9.1 // indirect
47+
github.com/hashicorp/terraform-json v0.13.0 // indirect
48+
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
49+
github.com/jmespath/go-jmespath v0.4.0 // indirect
50+
github.com/klauspost/compress v1.15.11 // indirect
51+
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
52+
github.com/mitchellh/go-homedir v1.1.0 // indirect
53+
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
54+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
55+
github.com/pmezard/go-difflib v1.0.0 // indirect
56+
github.com/stretchr/testify v1.8.4 // indirect
57+
github.com/tmccombs/hcl2json v0.3.3 // indirect
58+
github.com/ulikunitz/xz v0.5.10 // indirect
59+
github.com/zclconf/go-cty v1.9.1 // indirect
60+
go.opencensus.io v0.24.0 // indirect
61+
golang.org/x/crypto v0.14.0 // indirect
62+
golang.org/x/net v0.17.0 // indirect
63+
golang.org/x/oauth2 v0.8.0 // indirect
64+
golang.org/x/sys v0.13.0 // indirect
65+
golang.org/x/text v0.13.0 // indirect
66+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
67+
google.golang.org/api v0.114.0 // indirect
68+
google.golang.org/appengine v1.6.7 // indirect
69+
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
70+
google.golang.org/grpc v1.56.3 // indirect
71+
google.golang.org/protobuf v1.31.0 // indirect
72+
gopkg.in/yaml.v3 v3.0.1 // indirect
73+
)

0 commit comments

Comments
 (0)