-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6591 from terraform-providers/f-aws_datasync
Support DataSync Service
- Loading branch information
Showing
22 changed files
with
4,463 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package aws | ||
|
||
import ( | ||
"net/url" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/datasync" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSyncParseLocationURI(uri string) (string, error) { | ||
parsedURL, err := url.ParseRequestURI(uri) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return parsedURL.Path, nil | ||
} | ||
|
||
func expandDataSyncEc2Config(l []interface{}) *datasync.Ec2Config { | ||
if len(l) == 0 || l[0] == nil { | ||
return nil | ||
} | ||
|
||
m := l[0].(map[string]interface{}) | ||
|
||
ec2Config := &datasync.Ec2Config{ | ||
SecurityGroupArns: expandStringSet(m["security_group_arns"].(*schema.Set)), | ||
SubnetArn: aws.String(m["subnet_arn"].(string)), | ||
} | ||
|
||
return ec2Config | ||
} | ||
|
||
func expandDataSyncOnPremConfig(l []interface{}) *datasync.OnPremConfig { | ||
if len(l) == 0 || l[0] == nil { | ||
return nil | ||
} | ||
|
||
m := l[0].(map[string]interface{}) | ||
|
||
onPremConfig := &datasync.OnPremConfig{ | ||
AgentArns: expandStringSet(m["agent_arns"].(*schema.Set)), | ||
} | ||
|
||
return onPremConfig | ||
} | ||
|
||
func expandDataSyncOptions(l []interface{}) *datasync.Options { | ||
if len(l) == 0 || l[0] == nil { | ||
return nil | ||
} | ||
|
||
m := l[0].(map[string]interface{}) | ||
|
||
options := &datasync.Options{ | ||
Atime: aws.String(m["atime"].(string)), | ||
Gid: aws.String(m["gid"].(string)), | ||
Mtime: aws.String(m["mtime"].(string)), | ||
PreserveDeletedFiles: aws.String(m["preserve_deleted_files"].(string)), | ||
PreserveDevices: aws.String(m["preserve_devices"].(string)), | ||
PosixPermissions: aws.String(m["posix_permissions"].(string)), | ||
Uid: aws.String(m["uid"].(string)), | ||
VerifyMode: aws.String(m["verify_mode"].(string)), | ||
} | ||
|
||
if v, ok := m["bytes_per_second"]; ok && v.(int) > 0 { | ||
options.BytesPerSecond = aws.Int64(int64(v.(int))) | ||
} | ||
|
||
return options | ||
} | ||
|
||
func expandDataSyncS3Config(l []interface{}) *datasync.S3Config { | ||
if len(l) == 0 || l[0] == nil { | ||
return nil | ||
} | ||
|
||
m := l[0].(map[string]interface{}) | ||
|
||
s3Config := &datasync.S3Config{ | ||
BucketAccessRoleArn: aws.String(m["bucket_access_role_arn"].(string)), | ||
} | ||
|
||
return s3Config | ||
} | ||
|
||
func flattenDataSyncEc2Config(ec2Config *datasync.Ec2Config) []interface{} { | ||
if ec2Config == nil { | ||
return []interface{}{} | ||
} | ||
|
||
m := map[string]interface{}{ | ||
"security_group_arns": schema.NewSet(schema.HashString, flattenStringList(ec2Config.SecurityGroupArns)), | ||
"subnet_arn": aws.StringValue(ec2Config.SubnetArn), | ||
} | ||
|
||
return []interface{}{m} | ||
} | ||
|
||
func flattenDataSyncOnPremConfig(onPremConfig *datasync.OnPremConfig) []interface{} { | ||
if onPremConfig == nil { | ||
return []interface{}{} | ||
} | ||
|
||
m := map[string]interface{}{ | ||
"agent_arns": schema.NewSet(schema.HashString, flattenStringList(onPremConfig.AgentArns)), | ||
} | ||
|
||
return []interface{}{m} | ||
} | ||
|
||
func flattenDataSyncOptions(options *datasync.Options) []interface{} { | ||
if options == nil { | ||
return []interface{}{} | ||
} | ||
|
||
m := map[string]interface{}{ | ||
"atime": aws.StringValue(options.Atime), | ||
"bytes_per_second": aws.Int64Value(options.BytesPerSecond), | ||
"gid": aws.StringValue(options.Gid), | ||
"mtime": aws.StringValue(options.Mtime), | ||
"posix_permissions": aws.StringValue(options.PosixPermissions), | ||
"preserve_deleted_files": aws.StringValue(options.PreserveDeletedFiles), | ||
"preserve_devices": aws.StringValue(options.PreserveDevices), | ||
"uid": aws.StringValue(options.Uid), | ||
"verify_mode": aws.StringValue(options.VerifyMode), | ||
} | ||
|
||
return []interface{}{m} | ||
} | ||
|
||
func flattenDataSyncS3Config(s3Config *datasync.S3Config) []interface{} { | ||
if s3Config == nil { | ||
return []interface{}{} | ||
} | ||
|
||
m := map[string]interface{}{ | ||
"bucket_access_role_arn": aws.StringValue(s3Config.BucketAccessRoleArn), | ||
} | ||
|
||
return []interface{}{m} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package aws | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/datasync" | ||
) | ||
|
||
// dataSyncTagsDiff takes our tags locally and the ones remotely and returns | ||
// the set of tags that must be created, and the set of tags that must | ||
// be destroyed. | ||
func dataSyncTagsDiff(oldTags, newTags []*datasync.TagListEntry) ([]*datasync.TagListEntry, []*datasync.TagListEntry) { | ||
// First, we're creating everything we have | ||
create := make(map[string]interface{}) | ||
for _, t := range newTags { | ||
create[aws.StringValue(t.Key)] = aws.StringValue(t.Value) | ||
} | ||
|
||
// Build the list of what to remove | ||
var remove []*datasync.TagListEntry | ||
for _, t := range oldTags { | ||
old, ok := create[aws.StringValue(t.Key)] | ||
if !ok || old != aws.StringValue(t.Value) { | ||
// Delete it! | ||
remove = append(remove, t) | ||
} | ||
} | ||
|
||
return expandDataSyncTagListEntry(create), remove | ||
} | ||
|
||
func dataSyncTagsKeys(tags []*datasync.TagListEntry) []*string { | ||
keys := make([]*string, 0) | ||
|
||
for _, tag := range tags { | ||
if tag == nil { | ||
continue | ||
} | ||
keys = append(keys, tag.Key) | ||
} | ||
|
||
return keys | ||
} | ||
|
||
func expandDataSyncTagListEntry(m map[string]interface{}) []*datasync.TagListEntry { | ||
result := []*datasync.TagListEntry{} | ||
for k, v := range m { | ||
result = append(result, &datasync.TagListEntry{ | ||
Key: aws.String(k), | ||
Value: aws.String(v.(string)), | ||
}) | ||
} | ||
|
||
return result | ||
} | ||
|
||
func flattenDataSyncTagListEntry(ts []*datasync.TagListEntry) map[string]string { | ||
result := map[string]string{} | ||
for _, t := range ts { | ||
result[aws.StringValue(t.Key)] = aws.StringValue(t.Value) | ||
} | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package aws | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestDataSyncTagsDiff(t *testing.T) { | ||
cases := []struct { | ||
Old, New map[string]interface{} | ||
Create, Remove map[string]string | ||
}{ | ||
// Basic add/remove | ||
{ | ||
Old: map[string]interface{}{ | ||
"foo": "bar", | ||
}, | ||
New: map[string]interface{}{ | ||
"bar": "baz", | ||
}, | ||
Create: map[string]string{ | ||
"bar": "baz", | ||
}, | ||
Remove: map[string]string{ | ||
"foo": "bar", | ||
}, | ||
}, | ||
|
||
// Modify | ||
{ | ||
Old: map[string]interface{}{ | ||
"foo": "bar", | ||
}, | ||
New: map[string]interface{}{ | ||
"foo": "baz", | ||
}, | ||
Create: map[string]string{ | ||
"foo": "baz", | ||
}, | ||
Remove: map[string]string{ | ||
"foo": "bar", | ||
}, | ||
}, | ||
} | ||
|
||
for i, tc := range cases { | ||
create, remove := dataSyncTagsDiff(expandDataSyncTagListEntry(tc.Old), expandDataSyncTagListEntry(tc.New)) | ||
createMap := flattenDataSyncTagListEntry(create) | ||
removeMap := flattenDataSyncTagListEntry(remove) | ||
if !reflect.DeepEqual(createMap, tc.Create) { | ||
t.Fatalf("%d: bad create: %#v", i, createMap) | ||
} | ||
if !reflect.DeepEqual(removeMap, tc.Remove) { | ||
t.Fatalf("%d: bad remove: %#v", i, removeMap) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestDataSyncParseLocationURI(t *testing.T) { | ||
testCases := []struct { | ||
LocationURI string | ||
Subdirectory string | ||
}{ | ||
{ | ||
LocationURI: "efs://us-east-2.fs-abcd1234/", | ||
Subdirectory: "/", | ||
}, | ||
{ | ||
LocationURI: "efs://us-east-2.fs-abcd1234/path", | ||
Subdirectory: "/path", | ||
}, | ||
{ | ||
LocationURI: "nfs://example.com/", | ||
Subdirectory: "/", | ||
}, | ||
{ | ||
LocationURI: "nfs://example.com/path", | ||
Subdirectory: "/path", | ||
}, | ||
{ | ||
LocationURI: "s3://myBucket/", | ||
Subdirectory: "/", | ||
}, | ||
{ | ||
LocationURI: "s3://myBucket/path", | ||
Subdirectory: "/path", | ||
}, | ||
} | ||
|
||
for i, tc := range testCases { | ||
subdirectory, err := dataSyncParseLocationURI(tc.LocationURI) | ||
if err != nil { | ||
t.Fatalf("%d: received error parsing (%s): %s", i, tc.LocationURI, err) | ||
} | ||
if subdirectory != tc.Subdirectory { | ||
t.Fatalf("%d: expected subdirectory (%s), received: %s", i, tc.Subdirectory, subdirectory) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.