From 21b51e7bff7c4f631fb8290d9772cc9e6159a5a6 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 4 Apr 2020 21:29:24 +0300 Subject: [PATCH 01/23] initial commit --- ...ource_aws_datasync_location_fsx_windows.go | 191 ++++++++ ..._aws_datasync_location_fsx_windows_test.go | 421 ++++++++++++++++++ 2 files changed, 612 insertions(+) create mode 100644 aws/resource_aws_datasync_location_fsx_windows.go create mode 100644 aws/resource_aws_datasync_location_fsx_windows_test.go diff --git a/aws/resource_aws_datasync_location_fsx_windows.go b/aws/resource_aws_datasync_location_fsx_windows.go new file mode 100644 index 00000000000..7eb9be2d55e --- /dev/null +++ b/aws/resource_aws_datasync_location_fsx_windows.go @@ -0,0 +1,191 @@ +package aws + +import ( + "fmt" + "log" + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/datasync" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" +) + +func resourceAwsDataSyncLocationFsxWindows() *schema.Resource { + return &schema.Resource{ + Create: resourceAwsDataSyncLocationFsxWindowsCreate, + Read: resourceAwsDataSyncLocationFsxWindowsRead, + Update: resourceAwsDataSyncLocationFsxWindowsUpdate, + Delete: resourceAwsDataSyncLocationFsxWindowsDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "fsx_filesystem_arn": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateArn, + }, + "password": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Sensitive: true, + }, + "user": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "domain": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "security_group_arns": { + Type: schema.TypeSet, + Required: true, + ForceNew: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validateArn, + }, + }, + "subdirectory": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "tags": tagsSchema(), + "uri": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceAwsDataSyncLocationFsxWindowsCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).datasyncconn + + input := &datasync.CreateLocationFsxWindowsInput{ + FsxFilesystemArn: aws.String(d.Get("fsx_filesystem_arn").(string)), + User: aws.String(d.Get("user").(string)), + Password: aws.String(d.Get("password").(string)), + SecurityGroupArns: expandStringSet(d.Get("security_group_arns").(*schema.Set)), + Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().DatasyncTags(), + } + + if v, ok := d.GetOk("subdirectory"); ok { + input.Subdirectory = aws.String(v.(string)) + } + + if v, ok := d.GetOk("domain"); ok { + input.Domain = aws.String(v.(string)) + } + + log.Printf("[DEBUG] Creating DataSync Location FsxWindows: %s", input) + output, err := conn.CreateLocationFsxWindows(input) + if err != nil { + return fmt.Errorf("error creating DataSync Location FsxWindows: %s", err) + } + + d.SetId(aws.StringValue(output.LocationArn)) + + return resourceAwsDataSyncLocationFsxWindowsRead(d, meta) +} + +func resourceAwsDataSyncLocationFsxWindowsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).datasyncconn + + input := &datasync.DescribeLocationFsxWindowsInput{ + LocationArn: aws.String(d.Id()), + } + + log.Printf("[DEBUG] Reading DataSync Location FsxWindows: %s", input) + output, err := conn.DescribeLocationFsxWindows(input) + + if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { + log.Printf("[WARN] DataSync Location FsxWindows %q not found - removing from state", d.Id()) + d.SetId("") + return nil + } + + if err != nil { + return fmt.Errorf("error reading DataSync Location FsxWindows (%s): %s", d.Id(), err) + } + + subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri)) + + if err != nil { + return fmt.Errorf("error parsing Location FsxWindows (%s) URI (%s): %s", d.Id(), aws.StringValue(output.LocationUri), err) + } + + d.Set("arn", output.LocationArn) + d.Set("security_group_arns", flattenStringSet(output.SecurityGroupArns)) + d.Set("subdirectory", subdirectory) + d.Set("uri", output.LocationUri) + d.Set("user", output.User) + d.Set("domain", output.Domain) + + if err := d.Set("creation_time", output.CreationTime.Format(time.RFC3339)); err != nil { + return fmt.Errorf("error setting creation_time: %s", err) + } + + tags, err := keyvaluetags.DatasyncListTags(conn, d.Id()) + + if err != nil { + return fmt.Errorf("error listing tags for DataSync Location FsxWindows (%s): %s", d.Id(), err) + } + + if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil { + return fmt.Errorf("error setting tags: %s", err) + } + + return nil +} + +func resourceAwsDataSyncLocationFsxWindowsUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).datasyncconn + + if d.HasChange("tags") { + o, n := d.GetChange("tags") + + if err := keyvaluetags.DatasyncUpdateTags(conn, d.Id(), o, n); err != nil { + return fmt.Errorf("error updating DataSync Location FsxWindows (%s) tags: %s", d.Id(), err) + } + } + + return resourceAwsDataSyncLocationFsxWindowsRead(d, meta) +} + +func resourceAwsDataSyncLocationFsxWindowsDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).datasyncconn + + input := &datasync.DeleteLocationInput{ + LocationArn: aws.String(d.Id()), + } + + log.Printf("[DEBUG] Deleting DataSync Location FsxWindows: %s", input) + _, err := conn.DeleteLocation(input) + + if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { + return nil + } + + if err != nil { + return fmt.Errorf("error deleting DataSync Location FsxWindows (%s): %s", d.Id(), err) + } + + return nil +} diff --git a/aws/resource_aws_datasync_location_fsx_windows_test.go b/aws/resource_aws_datasync_location_fsx_windows_test.go new file mode 100644 index 00000000000..a8540a9a4c3 --- /dev/null +++ b/aws/resource_aws_datasync_location_fsx_windows_test.go @@ -0,0 +1,421 @@ +package aws + +import ( + "errors" + "fmt" + "log" + "regexp" + "strings" + "testing" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/datasync" + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func init() { + resource.AddTestSweepers("aws_datasync_location_fsx_windows", &resource.Sweeper{ + Name: "aws_datasync_location_fsx_windows", + F: testSweepDataSyncLocationFsxWindows, + }) +} + +func testSweepDataSyncLocationFsxWindows(region string) error { + client, err := sharedClientForRegion(region) + if err != nil { + return fmt.Errorf("error getting client: %s", err) + } + conn := client.(*AWSClient).datasyncconn + + input := &datasync.ListLocationsInput{} + for { + output, err := conn.ListLocations(input) + + if testSweepSkipSweepError(err) { + log.Printf("[WARN] Skipping DataSync Location FSX Windows sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("Error retrieving DataSync Location FSX Windows: %s", err) + } + + if len(output.Locations) == 0 { + log.Print("[DEBUG] No DataSync Location FSX Windowss to sweep") + return nil + } + + for _, location := range output.Locations { + uri := aws.StringValue(location.LocationUri) + if !strings.HasPrefix(uri, "FsxWindows://") { + log.Printf("[INFO] Skipping DataSync Location FSX Windows: %s", uri) + continue + } + log.Printf("[INFO] Deleting DataSync Location FSX Windows: %s", uri) + input := &datasync.DeleteLocationInput{ + LocationArn: location.LocationArn, + } + + _, err := conn.DeleteLocation(input) + + if isAWSErr(err, "InvalidRequestException", "not found") { + continue + } + + if err != nil { + log.Printf("[ERROR] Failed to delete DataSync Location FSX Windows (%s): %s", uri, err) + } + } + + if aws.StringValue(output.NextToken) == "" { + break + } + + input.NextToken = output.NextToken + } + + return nil +} + +func TestAccAWSDataSyncLocationFsxWindows_basic(t *testing.T) { + var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_datasync_location_fsx_windows.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSDataSyncLocationFsxWindowsDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSDataSyncLocationFsxWindowsConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows1), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "datasync", regexp.MustCompile(`location/loc-.+`)), + resource.TestCheckResourceAttr(resourceName, "subdirectory", "/"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + resource.TestMatchResourceAttr(resourceName, "uri", regexp.MustCompile(`^FsxWindows://.+/`)), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"password"}, + }, + }, + }) +} + +func TestAccAWSDataSyncLocationFsxWindows_disappears(t *testing.T) { + var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_datasync_location_fsx_windows.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSDataSyncLocationFsxWindowsDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSDataSyncLocationFsxWindowsConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows1), + testAccCheckAWSDataSyncLocationFsxWindowsDisappears(&locationFsxWindows1), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func TestAccAWSDataSyncLocationFsxWindows_Subdirectory(t *testing.T) { + rName := acctest.RandomWithPrefix("tf-acc-test") + var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput + resourceName := "aws_datasync_location_fsx_windows.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSDataSyncLocationFsxWindowsDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSDataSyncLocationFsxWindowsConfigSubdirectory(rName, "/subdirectory1/"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows1), + resource.TestCheckResourceAttr(resourceName, "subdirectory", "/subdirectory1/"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"password"}, + }, + }, + }) +} + +func TestAccAWSDataSyncLocationFsxWindows_Tags(t *testing.T) { + var locationFsxWindows1, locationFsxWindows2, locationFsxWindows3 datasync.DescribeLocationFsxWindowsOutput + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_datasync_location_fsx_windows.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSDataSyncLocationFsxWindowsDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSDataSyncLocationFsxWindowsConfigTags1(rName, "key1", "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows1), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"password"}, + }, + { + Config: testAccAWSDataSyncLocationFsxWindowsConfigTags2(rName, "key1", "value1updated", "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows2), + testAccCheckAWSDataSyncLocationFsxWindowsNotRecreated(&locationFsxWindows1, &locationFsxWindows2), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccAWSDataSyncLocationFsxWindowsConfigTags1(rName, "key1", "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows3), + testAccCheckAWSDataSyncLocationFsxWindowsNotRecreated(&locationFsxWindows2, &locationFsxWindows3), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + ), + }, + }, + }) +} + +func testAccCheckAWSDataSyncLocationFsxWindowsDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).datasyncconn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_datasync_location_fsx_windows" { + continue + } + + input := &datasync.DescribeLocationFsxWindowsInput{ + LocationArn: aws.String(rs.Primary.ID), + } + + _, err := conn.DescribeLocationFsxWindows(input) + + if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { + return nil + } + + if err != nil { + return err + } + } + + return nil +} + +func testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName string, locationFsxWindows *datasync.DescribeLocationFsxWindowsOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + conn := testAccProvider.Meta().(*AWSClient).datasyncconn + input := &datasync.DescribeLocationFsxWindowsInput{ + LocationArn: aws.String(rs.Primary.ID), + } + + output, err := conn.DescribeLocationFsxWindows(input) + + if err != nil { + return err + } + + if output == nil { + return fmt.Errorf("Location %q does not exist", rs.Primary.ID) + } + + *locationFsxWindows = *output + + return nil + } +} + +func testAccCheckAWSDataSyncLocationFsxWindowsDisappears(location *datasync.DescribeLocationFsxWindowsOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).datasyncconn + + input := &datasync.DeleteLocationInput{ + LocationArn: location.LocationArn, + } + + _, err := conn.DeleteLocation(input) + + return err + } +} + +func testAccCheckAWSDataSyncLocationFsxWindowsNotRecreated(i, j *datasync.DescribeLocationFsxWindowsOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + if aws.TimeValue(i.CreationTime) != aws.TimeValue(j.CreationTime) { + return errors.New("DataSync Location FSX Windows was recreated") + } + + return nil + } +} + +func testAccAWSDataSyncLocationFsxWindowsConfigBase(rName string) string { + return fmt.Sprintf(` +data "aws_ami" "aws-thinstaller" { + most_recent = true + owners = ["amazon"] + + filter { + name = "name" + values = ["aws-thinstaller-*"] + } +} + +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = "tf-acc-test-datasync-location-FsxWindows" + } +} + +resource "aws_subnet" "test" { + cidr_block = "10.0.0.0/24" + vpc_id = "${aws_vpc.test.id}" + + tags = { + Name = "tf-acc-test-datasync-location-FsxWindows" + } +} + +resource "aws_internet_gateway" "test" { + vpc_id = "${aws_vpc.test.id}" + + tags = { + Name = "tf-acc-test-datasync-location-FsxWindows" + } +} + +resource "aws_route_table" "test" { + vpc_id = "${aws_vpc.test.id}" + + route { + cidr_block = "0.0.0.0/0" + gateway_id = "${aws_internet_gateway.test.id}" + } + + tags = { + Name = "tf-acc-test-datasync-location-FsxWindows" + } +} + +resource "aws_route_table_association" "test" { + subnet_id = "${aws_subnet.test.id}" + route_table_id = "${aws_route_table.test.id}" +} + +resource "aws_security_group" "test" { + vpc_id = "${aws_vpc.test.id}" + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "tf-acc-test-datasync-location-FsxWindows" + } +} + +resource "aws_instance" "test" { + depends_on = ["aws_internet_gateway.test"] + + ami = "${data.aws_ami.aws-thinstaller.id}" + associate_public_ip_address = true + + # Default instance type from sync.sh + instance_type = "c5.2xlarge" + vpc_security_group_ids = ["${aws_security_group.test.id}"] + subnet_id = "${aws_subnet.test.id}" + + tags = { + Name = "tf-acc-test-datasync-location-FsxWindows" + } +} + +resource "aws_datasync_agent" "test" { + ip_address = "${aws_instance.test.public_ip}" + name = %q +} +`, rName) +} + +func testAccAWSDataSyncLocationFsxWindowsConfig(rName string) string { + return testAccAWSDataSyncLocationFsxWindowsConfigBase(rName) + fmt.Sprintf(` +resource "aws_datasync_location_fsx_windows" "test" { +} +`) +} + +func testAccAWSDataSyncLocationFsxWindowsConfigSubdirectory(rName, subdirectory string) string { + return testAccAWSDataSyncLocationFsxWindowsConfigBase(rName) + fmt.Sprintf(` +resource "aws_datasync_location_fsx_windows" "test" { + server_hostname = "example.com" + subdirectory = %q +} +`, subdirectory) +} + +func testAccAWSDataSyncLocationFsxWindowsConfigTags1(rName, key1, value1 string) string { + return testAccAWSDataSyncLocationFsxWindowsConfigBase(rName) + fmt.Sprintf(` +resource "aws_datasync_location_fsx_windows" "test" { + tags = { + %[1]q = %[2]q + } +} +`, key1, value1) +} + +func testAccAWSDataSyncLocationFsxWindowsConfigTags2(rName, key1, value1, key2, value2 string) string { + return testAccAWSDataSyncLocationFsxWindowsConfigBase(rName) + fmt.Sprintf(` +resource "aws_datasync_location_fsx_windows" "test" { + tags = { + %[1]q = %[2]q + %[3]q = %[4]q + } +} +`, key1, value1, key2, value2) +} From 4260a3bc680b0fb1d87e4866421ce95c6bd85b58 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 4 Apr 2020 23:38:57 +0300 Subject: [PATCH 02/23] add validations --- ...ource_aws_datasync_location_fsx_windows.go | 33 ++-- ..._aws_datasync_location_fsx_windows_test.go | 154 ++++-------------- 2 files changed, 53 insertions(+), 134 deletions(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows.go b/aws/resource_aws_datasync_location_fsx_windows.go index 7eb9be2d55e..112c91965e3 100644 --- a/aws/resource_aws_datasync_location_fsx_windows.go +++ b/aws/resource_aws_datasync_location_fsx_windows.go @@ -8,6 +8,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/datasync" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" ) @@ -33,34 +34,40 @@ func resourceAwsDataSyncLocationFsxWindows() *schema.Resource { ValidateFunc: validateArn, }, "password": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Sensitive: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + Sensitive: true, + ValidateFunc: validation.StringLenBetween(1, 104), }, "user": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(1, 104), }, "domain": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(1, 253), }, "security_group_arns": { Type: schema.TypeSet, Required: true, ForceNew: true, + MinItems: 1, + MaxItems: 5, Elem: &schema.Schema{ Type: schema.TypeString, ValidateFunc: validateArn, }, }, "subdirectory": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(1, 4096), }, "tags": tagsSchema(), "uri": { diff --git a/aws/resource_aws_datasync_location_fsx_windows_test.go b/aws/resource_aws_datasync_location_fsx_windows_test.go index a8540a9a4c3..96d1f5183e4 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_test.go +++ b/aws/resource_aws_datasync_location_fsx_windows_test.go @@ -10,7 +10,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/datasync" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" ) @@ -81,7 +80,6 @@ func testSweepDataSyncLocationFsxWindows(region string) error { func TestAccAWSDataSyncLocationFsxWindows_basic(t *testing.T) { var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput - rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_datasync_location_fsx_windows.test" resource.ParallelTest(t, resource.TestCase{ @@ -90,7 +88,7 @@ func TestAccAWSDataSyncLocationFsxWindows_basic(t *testing.T) { CheckDestroy: testAccCheckAWSDataSyncLocationFsxWindowsDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSDataSyncLocationFsxWindowsConfig(rName), + Config: testAccAWSDataSyncLocationFsxWindowsConfig(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows1), testAccMatchResourceAttrRegionalARN(resourceName, "arn", "datasync", regexp.MustCompile(`location/loc-.+`)), @@ -111,7 +109,6 @@ func TestAccAWSDataSyncLocationFsxWindows_basic(t *testing.T) { func TestAccAWSDataSyncLocationFsxWindows_disappears(t *testing.T) { var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput - rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_datasync_location_fsx_windows.test" resource.ParallelTest(t, resource.TestCase{ @@ -120,7 +117,7 @@ func TestAccAWSDataSyncLocationFsxWindows_disappears(t *testing.T) { CheckDestroy: testAccCheckAWSDataSyncLocationFsxWindowsDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSDataSyncLocationFsxWindowsConfig(rName), + Config: testAccAWSDataSyncLocationFsxWindowsConfig(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows1), testAccCheckAWSDataSyncLocationFsxWindowsDisappears(&locationFsxWindows1), @@ -132,7 +129,6 @@ func TestAccAWSDataSyncLocationFsxWindows_disappears(t *testing.T) { } func TestAccAWSDataSyncLocationFsxWindows_Subdirectory(t *testing.T) { - rName := acctest.RandomWithPrefix("tf-acc-test") var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput resourceName := "aws_datasync_location_fsx_windows.test" @@ -142,7 +138,7 @@ func TestAccAWSDataSyncLocationFsxWindows_Subdirectory(t *testing.T) { CheckDestroy: testAccCheckAWSDataSyncLocationFsxWindowsDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSDataSyncLocationFsxWindowsConfigSubdirectory(rName, "/subdirectory1/"), + Config: testAccAWSDataSyncLocationFsxWindowsConfigSubdirectory("/subdirectory1/"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows1), resource.TestCheckResourceAttr(resourceName, "subdirectory", "/subdirectory1/"), @@ -160,7 +156,6 @@ func TestAccAWSDataSyncLocationFsxWindows_Subdirectory(t *testing.T) { func TestAccAWSDataSyncLocationFsxWindows_Tags(t *testing.T) { var locationFsxWindows1, locationFsxWindows2, locationFsxWindows3 datasync.DescribeLocationFsxWindowsOutput - rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_datasync_location_fsx_windows.test" resource.ParallelTest(t, resource.TestCase{ @@ -169,7 +164,7 @@ func TestAccAWSDataSyncLocationFsxWindows_Tags(t *testing.T) { CheckDestroy: testAccCheckAWSDataSyncLocationFsxWindowsDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSDataSyncLocationFsxWindowsConfigTags1(rName, "key1", "value1"), + Config: testAccAWSDataSyncLocationFsxWindowsConfigTags1("key1", "value1"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows1), resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), @@ -183,7 +178,7 @@ func TestAccAWSDataSyncLocationFsxWindows_Tags(t *testing.T) { ImportStateVerifyIgnore: []string{"password"}, }, { - Config: testAccAWSDataSyncLocationFsxWindowsConfigTags2(rName, "key1", "value1updated", "key2", "value2"), + Config: testAccAWSDataSyncLocationFsxWindowsConfigTags2("key1", "value1updated", "key2", "value2"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows2), testAccCheckAWSDataSyncLocationFsxWindowsNotRecreated(&locationFsxWindows1, &locationFsxWindows2), @@ -193,7 +188,7 @@ func TestAccAWSDataSyncLocationFsxWindows_Tags(t *testing.T) { ), }, { - Config: testAccAWSDataSyncLocationFsxWindowsConfigTags1(rName, "key1", "value1"), + Config: testAccAWSDataSyncLocationFsxWindowsConfigTags1("key1", "value1"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows3), testAccCheckAWSDataSyncLocationFsxWindowsNotRecreated(&locationFsxWindows2, &locationFsxWindows3), @@ -283,125 +278,37 @@ func testAccCheckAWSDataSyncLocationFsxWindowsNotRecreated(i, j *datasync.Descri } } -func testAccAWSDataSyncLocationFsxWindowsConfigBase(rName string) string { - return fmt.Sprintf(` -data "aws_ami" "aws-thinstaller" { - most_recent = true - owners = ["amazon"] - - filter { - name = "name" - values = ["aws-thinstaller-*"] - } -} - -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = "tf-acc-test-datasync-location-FsxWindows" - } -} - -resource "aws_subnet" "test" { - cidr_block = "10.0.0.0/24" - vpc_id = "${aws_vpc.test.id}" - - tags = { - Name = "tf-acc-test-datasync-location-FsxWindows" - } -} - -resource "aws_internet_gateway" "test" { - vpc_id = "${aws_vpc.test.id}" - - tags = { - Name = "tf-acc-test-datasync-location-FsxWindows" - } -} - -resource "aws_route_table" "test" { - vpc_id = "${aws_vpc.test.id}" - - route { - cidr_block = "0.0.0.0/0" - gateway_id = "${aws_internet_gateway.test.id}" - } - - tags = { - Name = "tf-acc-test-datasync-location-FsxWindows" - } -} - -resource "aws_route_table_association" "test" { - subnet_id = "${aws_subnet.test.id}" - route_table_id = "${aws_route_table.test.id}" -} - -resource "aws_security_group" "test" { - vpc_id = "${aws_vpc.test.id}" - - egress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - } - - ingress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - } - - tags = { - Name = "tf-acc-test-datasync-location-FsxWindows" - } -} - -resource "aws_instance" "test" { - depends_on = ["aws_internet_gateway.test"] - - ami = "${data.aws_ami.aws-thinstaller.id}" - associate_public_ip_address = true - - # Default instance type from sync.sh - instance_type = "c5.2xlarge" - vpc_security_group_ids = ["${aws_security_group.test.id}"] - subnet_id = "${aws_subnet.test.id}" - - tags = { - Name = "tf-acc-test-datasync-location-FsxWindows" - } -} - -resource "aws_datasync_agent" "test" { - ip_address = "${aws_instance.test.public_ip}" - name = %q -} -`, rName) -} - -func testAccAWSDataSyncLocationFsxWindowsConfig(rName string) string { - return testAccAWSDataSyncLocationFsxWindowsConfigBase(rName) + fmt.Sprintf(` +func testAccAWSDataSyncLocationFsxWindowsConfig() string { + return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` resource "aws_datasync_location_fsx_windows" "test" { + fsx_filesystem_arn = "${aws_fsx_windows_file_system.test.arn}" + user = "SomeUser" + password = "SuperSecretPassw0rd" + security_group_arns = ["${aws_security_group.test1.arn}"] } `) } -func testAccAWSDataSyncLocationFsxWindowsConfigSubdirectory(rName, subdirectory string) string { - return testAccAWSDataSyncLocationFsxWindowsConfigBase(rName) + fmt.Sprintf(` +func testAccAWSDataSyncLocationFsxWindowsConfigSubdirectory(subdirectory string) string { + return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` resource "aws_datasync_location_fsx_windows" "test" { - server_hostname = "example.com" - subdirectory = %q + fsx_filesystem_arn = "${aws_fsx_windows_file_system.test.arn}" + user = "SomeUser" + password = "SuperSecretPassw0rd" + security_group_arns = ["${aws_security_group.test1.arn}"] + subdirectory = %q } `, subdirectory) } -func testAccAWSDataSyncLocationFsxWindowsConfigTags1(rName, key1, value1 string) string { - return testAccAWSDataSyncLocationFsxWindowsConfigBase(rName) + fmt.Sprintf(` +func testAccAWSDataSyncLocationFsxWindowsConfigTags1(key1, value1 string) string { + return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` resource "aws_datasync_location_fsx_windows" "test" { + fsx_filesystem_arn = "${aws_fsx_windows_file_system.test.arn}" + user = "SomeUser" + password = "SuperSecretPassw0rd" + security_group_arns = ["${aws_security_group.test1.arn}"] + tags = { %[1]q = %[2]q } @@ -409,9 +316,14 @@ resource "aws_datasync_location_fsx_windows" "test" { `, key1, value1) } -func testAccAWSDataSyncLocationFsxWindowsConfigTags2(rName, key1, value1, key2, value2 string) string { - return testAccAWSDataSyncLocationFsxWindowsConfigBase(rName) + fmt.Sprintf(` +func testAccAWSDataSyncLocationFsxWindowsConfigTags2(key1, value1, key2, value2 string) string { + return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` resource "aws_datasync_location_fsx_windows" "test" { + fsx_filesystem_arn = "${aws_fsx_windows_file_system.test.arn}" + user = "SomeUser" + password = "SuperSecretPassw0rd" + security_group_arns = ["${aws_security_group.test1.arn}"] + tags = { %[1]q = %[2]q %[3]q = %[4]q From 546f1bb7748eae0b0e3184c9d39558bef4a059c5 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 4 Apr 2020 23:40:37 +0300 Subject: [PATCH 03/23] add new resource to provider --- aws/provider.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/provider.go b/aws/provider.go index 34e5c292584..96a1710ca6b 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -491,6 +491,7 @@ func Provider() *schema.Provider { "aws_datasync_location_nfs": resourceAwsDataSyncLocationNfs(), "aws_datasync_location_s3": resourceAwsDataSyncLocationS3(), "aws_datasync_location_smb": resourceAwsDataSyncLocationSmb(), + "aws_datasync_location_fsx_windows": resourceAwsDataSyncLocationFsxWindows(), "aws_datasync_task": resourceAwsDataSyncTask(), "aws_dax_cluster": resourceAwsDaxCluster(), "aws_dax_parameter_group": resourceAwsDaxParameterGroup(), From 011d58c89c36fd316604ac86187b7892d4cb1402 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 5 Apr 2020 00:38:47 +0300 Subject: [PATCH 04/23] fix uri regex --- aws/resource_aws_datasync_location_fsx_windows_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows_test.go b/aws/resource_aws_datasync_location_fsx_windows_test.go index 96d1f5183e4..b28e1ee1b19 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_test.go +++ b/aws/resource_aws_datasync_location_fsx_windows_test.go @@ -94,7 +94,7 @@ func TestAccAWSDataSyncLocationFsxWindows_basic(t *testing.T) { testAccMatchResourceAttrRegionalARN(resourceName, "arn", "datasync", regexp.MustCompile(`location/loc-.+`)), resource.TestCheckResourceAttr(resourceName, "subdirectory", "/"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - resource.TestMatchResourceAttr(resourceName, "uri", regexp.MustCompile(`^FsxWindows://.+/`)), + resource.TestMatchResourceAttr(resourceName, "uri", regexp.MustCompile(`^fsxw://.+/`)), ), }, { From becf8c19ebe6bf8e357bad95c25dcb625d1ed2e0 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 5 Apr 2020 00:42:42 +0300 Subject: [PATCH 05/23] fix test --- aws/resource_aws_datasync_location_fsx_windows_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aws/resource_aws_datasync_location_fsx_windows_test.go b/aws/resource_aws_datasync_location_fsx_windows_test.go index b28e1ee1b19..b2971649cba 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_test.go +++ b/aws/resource_aws_datasync_location_fsx_windows_test.go @@ -81,6 +81,7 @@ func testSweepDataSyncLocationFsxWindows(region string) error { func TestAccAWSDataSyncLocationFsxWindows_basic(t *testing.T) { var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput resourceName := "aws_datasync_location_fsx_windows.test" + fsResourceName := "aws_fsx_windows_file_system.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, @@ -92,9 +93,11 @@ func TestAccAWSDataSyncLocationFsxWindows_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows1), testAccMatchResourceAttrRegionalARN(resourceName, "arn", "datasync", regexp.MustCompile(`location/loc-.+`)), + resource.TestCheckResourceAttrPair(resourceName, "fsx_filesystem_arn", fsResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "subdirectory", "/"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestMatchResourceAttr(resourceName, "uri", regexp.MustCompile(`^fsxw://.+/`)), + resource.TestCheckResourceAttrSet(resourceName, "creation_time"), ), }, { From d74fc3ee27d3fe0c6bceb6244cb3be41d0d8ff3d Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 5 Apr 2020 09:32:02 +0300 Subject: [PATCH 06/23] add option to import fsx arn --- ...ource_aws_datasync_location_fsx_windows.go | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows.go b/aws/resource_aws_datasync_location_fsx_windows.go index 112c91965e3..1fabc6341a7 100644 --- a/aws/resource_aws_datasync_location_fsx_windows.go +++ b/aws/resource_aws_datasync_location_fsx_windows.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "strings" "time" "github.com/aws/aws-sdk-go/aws" @@ -66,6 +67,7 @@ func resourceAwsDataSyncLocationFsxWindows() *schema.Resource { "subdirectory": { Type: schema.TypeString, Optional: true, + Computed: true, ForceNew: true, ValidateFunc: validation.StringLenBetween(1, 4096), }, @@ -84,9 +86,10 @@ func resourceAwsDataSyncLocationFsxWindows() *schema.Resource { func resourceAwsDataSyncLocationFsxWindowsCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).datasyncconn + fsxArn := d.Get("fsx_filesystem_arn").(string) input := &datasync.CreateLocationFsxWindowsInput{ - FsxFilesystemArn: aws.String(d.Get("fsx_filesystem_arn").(string)), + FsxFilesystemArn: aws.String(fsxArn), User: aws.String(d.Get("user").(string)), Password: aws.String(d.Get("password").(string)), SecurityGroupArns: expandStringSet(d.Get("security_group_arns").(*schema.Set)), @@ -107,29 +110,33 @@ func resourceAwsDataSyncLocationFsxWindowsCreate(d *schema.ResourceData, meta in return fmt.Errorf("error creating DataSync Location FsxWindows: %s", err) } - d.SetId(aws.StringValue(output.LocationArn)) + d.SetId(fmt.Sprintf("%s:%s", aws.StringValue(output.LocationArn), fsxArn)) return resourceAwsDataSyncLocationFsxWindowsRead(d, meta) } func resourceAwsDataSyncLocationFsxWindowsRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).datasyncconn + locationArn, fsxArn, err := decodeAwsDataSyncLocationFsxWindowsID(d.Id()) + if err != nil { + return err + } input := &datasync.DescribeLocationFsxWindowsInput{ - LocationArn: aws.String(d.Id()), + LocationArn: aws.String(locationArn), } - log.Printf("[DEBUG] Reading DataSync Location FsxWindows: %s", input) + log.Printf("[DEBUG] Reading DataSync Location Fsx Windows: %s", input) output, err := conn.DescribeLocationFsxWindows(input) if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { - log.Printf("[WARN] DataSync Location FsxWindows %q not found - removing from state", d.Id()) + log.Printf("[WARN] DataSync Location Fsx Windows %q not found - removing from state", locationArn) d.SetId("") return nil } if err != nil { - return fmt.Errorf("error reading DataSync Location FsxWindows (%s): %s", d.Id(), err) + return fmt.Errorf("error reading DataSync Location Fsx Windows (%s): %s", locationArn, err) } subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri)) @@ -139,6 +146,7 @@ func resourceAwsDataSyncLocationFsxWindowsRead(d *schema.ResourceData, meta inte } d.Set("arn", output.LocationArn) + d.Set("fsx_filesystem_arn", fsxArn) d.Set("security_group_arns", flattenStringSet(output.SecurityGroupArns)) d.Set("subdirectory", subdirectory) d.Set("uri", output.LocationUri) @@ -152,7 +160,7 @@ func resourceAwsDataSyncLocationFsxWindowsRead(d *schema.ResourceData, meta inte tags, err := keyvaluetags.DatasyncListTags(conn, d.Id()) if err != nil { - return fmt.Errorf("error listing tags for DataSync Location FsxWindows (%s): %s", d.Id(), err) + return fmt.Errorf("error listing tags for DataSync Location Fsx Windows (%s): %s", d.Id(), err) } if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil { @@ -164,12 +172,16 @@ func resourceAwsDataSyncLocationFsxWindowsRead(d *schema.ResourceData, meta inte func resourceAwsDataSyncLocationFsxWindowsUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).datasyncconn + locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsID(d.Id()) + if err != nil { + return err + } if d.HasChange("tags") { o, n := d.GetChange("tags") - if err := keyvaluetags.DatasyncUpdateTags(conn, d.Id(), o, n); err != nil { - return fmt.Errorf("error updating DataSync Location FsxWindows (%s) tags: %s", d.Id(), err) + if err := keyvaluetags.DatasyncUpdateTags(conn, locationArn, o, n); err != nil { + return fmt.Errorf("error updating DataSync Location FsxWindows (%s) tags: %s", locationArn, err) } } @@ -178,21 +190,35 @@ func resourceAwsDataSyncLocationFsxWindowsUpdate(d *schema.ResourceData, meta in func resourceAwsDataSyncLocationFsxWindowsDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).datasyncconn + locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsID(d.Id()) + if err != nil { + return err + } input := &datasync.DeleteLocationInput{ - LocationArn: aws.String(d.Id()), + LocationArn: aws.String(locationArn), } log.Printf("[DEBUG] Deleting DataSync Location FsxWindows: %s", input) - _, err := conn.DeleteLocation(input) + _, err = conn.DeleteLocation(input) if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { return nil } if err != nil { - return fmt.Errorf("error deleting DataSync Location FsxWindows (%s): %s", d.Id(), err) + return fmt.Errorf("error deleting DataSync Location Fsx Windows (%s): %s", locationArn, err) } return nil } + +func decodeAwsDataSyncLocationFsxWindowsID(id string) (string, string, error) { + parts := strings.Split(id, ":") + + if len(parts) != 2 { + return "", "", fmt.Errorf("Unexpected format of ID (%q), expected DataSyncLocationArn:FsxArn", id) + } + + return parts[0], parts[1], nil +} From 6733a8da3ef16d64d1b2b44bee13a3200222173e Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 5 Apr 2020 15:00:16 +0300 Subject: [PATCH 07/23] add fsx arn --- ...ource_aws_datasync_location_fsx_windows.go | 6 +++--- ..._aws_datasync_location_fsx_windows_test.go | 20 ++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows.go b/aws/resource_aws_datasync_location_fsx_windows.go index 1fabc6341a7..4da78f1bcd5 100644 --- a/aws/resource_aws_datasync_location_fsx_windows.go +++ b/aws/resource_aws_datasync_location_fsx_windows.go @@ -110,7 +110,7 @@ func resourceAwsDataSyncLocationFsxWindowsCreate(d *schema.ResourceData, meta in return fmt.Errorf("error creating DataSync Location FsxWindows: %s", err) } - d.SetId(fmt.Sprintf("%s:%s", aws.StringValue(output.LocationArn), fsxArn)) + d.SetId(fmt.Sprintf("%s#%s", aws.StringValue(output.LocationArn), fsxArn)) return resourceAwsDataSyncLocationFsxWindowsRead(d, meta) } @@ -157,7 +157,7 @@ func resourceAwsDataSyncLocationFsxWindowsRead(d *schema.ResourceData, meta inte return fmt.Errorf("error setting creation_time: %s", err) } - tags, err := keyvaluetags.DatasyncListTags(conn, d.Id()) + tags, err := keyvaluetags.DatasyncListTags(conn, locationArn) if err != nil { return fmt.Errorf("error listing tags for DataSync Location Fsx Windows (%s): %s", d.Id(), err) @@ -214,7 +214,7 @@ func resourceAwsDataSyncLocationFsxWindowsDelete(d *schema.ResourceData, meta in } func decodeAwsDataSyncLocationFsxWindowsID(id string) (string, string, error) { - parts := strings.Split(id, ":") + parts := strings.Split(id, "#") if len(parts) != 2 { return "", "", fmt.Errorf("Unexpected format of ID (%q), expected DataSyncLocationArn:FsxArn", id) diff --git a/aws/resource_aws_datasync_location_fsx_windows_test.go b/aws/resource_aws_datasync_location_fsx_windows_test.go index b2971649cba..dadb8de41c8 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_test.go +++ b/aws/resource_aws_datasync_location_fsx_windows_test.go @@ -48,7 +48,7 @@ func testSweepDataSyncLocationFsxWindows(region string) error { for _, location := range output.Locations { uri := aws.StringValue(location.LocationUri) - if !strings.HasPrefix(uri, "FsxWindows://") { + if !strings.HasPrefix(uri, "fsxw://") { log.Printf("[INFO] Skipping DataSync Location FSX Windows: %s", uri) continue } @@ -59,7 +59,7 @@ func testSweepDataSyncLocationFsxWindows(region string) error { _, err := conn.DeleteLocation(input) - if isAWSErr(err, "InvalidRequestException", "not found") { + if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { continue } @@ -211,11 +211,16 @@ func testAccCheckAWSDataSyncLocationFsxWindowsDestroy(s *terraform.State) error continue } + locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsID(rs.Primary.ID) + if err != nil { + return err + } + input := &datasync.DescribeLocationFsxWindowsInput{ - LocationArn: aws.String(rs.Primary.ID), + LocationArn: aws.String(locationArn), } - _, err := conn.DescribeLocationFsxWindows(input) + _, err = conn.DescribeLocationFsxWindows(input) if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { return nil @@ -236,9 +241,14 @@ func testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName string, locati return fmt.Errorf("Not found: %s", resourceName) } + locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsID(rs.Primary.ID) + if err != nil { + return err + } + conn := testAccProvider.Meta().(*AWSClient).datasyncconn input := &datasync.DescribeLocationFsxWindowsInput{ - LocationArn: aws.String(rs.Primary.ID), + LocationArn: aws.String(locationArn), } output, err := conn.DescribeLocationFsxWindows(input) From d671ebd4e249a1c49453523b53ec8e705844b714 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 5 Apr 2020 19:05:51 +0300 Subject: [PATCH 08/23] add docs --- ...atasync_location_fsx_windows.html.markdown | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 website/docs/r/datasync_location_fsx_windows.html.markdown diff --git a/website/docs/r/datasync_location_fsx_windows.html.markdown b/website/docs/r/datasync_location_fsx_windows.html.markdown new file mode 100644 index 00000000000..1597cf66d84 --- /dev/null +++ b/website/docs/r/datasync_location_fsx_windows.html.markdown @@ -0,0 +1,51 @@ +--- +subcategory: "DataSync" +layout: "aws" +page_title: "AWS: aws_datasync_location_fsx_windows" +description: |- + Manages an FSx Windows Location within AWS DataSync. +--- + +# Resource: aws_datasync_location_fsx_windows + +Manages an AWS DataSync FSx Windows Location. + +## Example Usage + +```hcl +resource "aws_datasync_location_fsx_windows" "example" { + fsx_filesystem_arn = "${aws_fsx_windows_file_system.example.arn}" + user = "SomeUser" + password = "SuperSecretPassw0rd" + security_group_arns = ["${aws_security_group.test1.arn}"] +} +``` + +## Argument Reference + +The following arguments are supported: + +* `fsx_filesystem_arn` - (Required) The Amazon Resource Name (ARN) for the FSx for Windows file system. +* `password` - (Required) The password of the user who has the permissions to access files and folders in the FSx for Windows file system. +* `user` - (Required) The user who has the permissions to access files and folders in the FSx for Windows file system. +* `domain` - (Optional) The name of the Windows domain that the FSx for Windows server belongs to. +* `security_group_arns` - (Optional) The Amazon Resource Names (ARNs) of the security groups that are to use to configure the FSx for Windows file system. +* `subdirectory` - (Optional) Subdirectory to perform actions as source or destination. +* `tags` - (Optional) Key-value pairs of resource tags to assign to the DataSync Location. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - Amazon Resource Name (ARN) of the DataSync Location. +* `arn` - Amazon Resource Name (ARN) of the DataSync Location. +* `uri` - The URL of the FSx for Windows location that was described. +* `creation_time` - The time that the FSx for Windows location was created. + +## Import + +`aws_datasync_location_fsx_windows` can be imported by using the `DataSync-ARN#FSx-Windows-ARN`, e.g. + +``` +$ terraform import aws_datasync_location_fsx_windows.example arn:aws:datasync:us-west-2:123456789012:location/loc-12345678901234567#arn:aws:fsx:us-west-2:476956259333:file-system/fs-08e04cd442c1bb94a +``` From e961ede32f947c077d1b12f3638de9108ea5f3a5 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 5 Apr 2020 19:47:50 +0300 Subject: [PATCH 09/23] fix lint (?) --- aws/provider.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/provider.go b/aws/provider.go index 96a1710ca6b..445f0f5249e 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -488,10 +488,10 @@ func Provider() *schema.Provider { "aws_datapipeline_pipeline": resourceAwsDataPipelinePipeline(), "aws_datasync_agent": resourceAwsDataSyncAgent(), "aws_datasync_location_efs": resourceAwsDataSyncLocationEfs(), + "aws_datasync_location_fsx_windows": resourceAwsDataSyncLocationFsxWindows(), "aws_datasync_location_nfs": resourceAwsDataSyncLocationNfs(), "aws_datasync_location_s3": resourceAwsDataSyncLocationS3(), "aws_datasync_location_smb": resourceAwsDataSyncLocationSmb(), - "aws_datasync_location_fsx_windows": resourceAwsDataSyncLocationFsxWindows(), "aws_datasync_task": resourceAwsDataSyncTask(), "aws_dax_cluster": resourceAwsDaxCluster(), "aws_dax_parameter_group": resourceAwsDaxParameterGroup(), From 550a2f19cc6cb4ae9649a58a1563d62d62fd24cd Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Mon, 6 Apr 2020 00:42:58 +0300 Subject: [PATCH 10/23] fix lint (?) --- ...ource_aws_datasync_location_fsx_windows.go | 224 ------------------ 1 file changed, 224 deletions(-) delete mode 100644 aws/resource_aws_datasync_location_fsx_windows.go diff --git a/aws/resource_aws_datasync_location_fsx_windows.go b/aws/resource_aws_datasync_location_fsx_windows.go deleted file mode 100644 index 4da78f1bcd5..00000000000 --- a/aws/resource_aws_datasync_location_fsx_windows.go +++ /dev/null @@ -1,224 +0,0 @@ -package aws - -import ( - "fmt" - "log" - "strings" - "time" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/datasync" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" -) - -func resourceAwsDataSyncLocationFsxWindows() *schema.Resource { - return &schema.Resource{ - Create: resourceAwsDataSyncLocationFsxWindowsCreate, - Read: resourceAwsDataSyncLocationFsxWindowsRead, - Update: resourceAwsDataSyncLocationFsxWindowsUpdate, - Delete: resourceAwsDataSyncLocationFsxWindowsDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "arn": { - Type: schema.TypeString, - Computed: true, - }, - "fsx_filesystem_arn": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validateArn, - }, - "password": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Sensitive: true, - ValidateFunc: validation.StringLenBetween(1, 104), - }, - "user": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringLenBetween(1, 104), - }, - "domain": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringLenBetween(1, 253), - }, - "security_group_arns": { - Type: schema.TypeSet, - Required: true, - ForceNew: true, - MinItems: 1, - MaxItems: 5, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validateArn, - }, - }, - "subdirectory": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ValidateFunc: validation.StringLenBetween(1, 4096), - }, - "tags": tagsSchema(), - "uri": { - Type: schema.TypeString, - Computed: true, - }, - "creation_time": { - Type: schema.TypeString, - Computed: true, - }, - }, - } -} - -func resourceAwsDataSyncLocationFsxWindowsCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).datasyncconn - fsxArn := d.Get("fsx_filesystem_arn").(string) - - input := &datasync.CreateLocationFsxWindowsInput{ - FsxFilesystemArn: aws.String(fsxArn), - User: aws.String(d.Get("user").(string)), - Password: aws.String(d.Get("password").(string)), - SecurityGroupArns: expandStringSet(d.Get("security_group_arns").(*schema.Set)), - Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().DatasyncTags(), - } - - if v, ok := d.GetOk("subdirectory"); ok { - input.Subdirectory = aws.String(v.(string)) - } - - if v, ok := d.GetOk("domain"); ok { - input.Domain = aws.String(v.(string)) - } - - log.Printf("[DEBUG] Creating DataSync Location FsxWindows: %s", input) - output, err := conn.CreateLocationFsxWindows(input) - if err != nil { - return fmt.Errorf("error creating DataSync Location FsxWindows: %s", err) - } - - d.SetId(fmt.Sprintf("%s#%s", aws.StringValue(output.LocationArn), fsxArn)) - - return resourceAwsDataSyncLocationFsxWindowsRead(d, meta) -} - -func resourceAwsDataSyncLocationFsxWindowsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).datasyncconn - locationArn, fsxArn, err := decodeAwsDataSyncLocationFsxWindowsID(d.Id()) - if err != nil { - return err - } - - input := &datasync.DescribeLocationFsxWindowsInput{ - LocationArn: aws.String(locationArn), - } - - log.Printf("[DEBUG] Reading DataSync Location Fsx Windows: %s", input) - output, err := conn.DescribeLocationFsxWindows(input) - - if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { - log.Printf("[WARN] DataSync Location Fsx Windows %q not found - removing from state", locationArn) - d.SetId("") - return nil - } - - if err != nil { - return fmt.Errorf("error reading DataSync Location Fsx Windows (%s): %s", locationArn, err) - } - - subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri)) - - if err != nil { - return fmt.Errorf("error parsing Location FsxWindows (%s) URI (%s): %s", d.Id(), aws.StringValue(output.LocationUri), err) - } - - d.Set("arn", output.LocationArn) - d.Set("fsx_filesystem_arn", fsxArn) - d.Set("security_group_arns", flattenStringSet(output.SecurityGroupArns)) - d.Set("subdirectory", subdirectory) - d.Set("uri", output.LocationUri) - d.Set("user", output.User) - d.Set("domain", output.Domain) - - if err := d.Set("creation_time", output.CreationTime.Format(time.RFC3339)); err != nil { - return fmt.Errorf("error setting creation_time: %s", err) - } - - tags, err := keyvaluetags.DatasyncListTags(conn, locationArn) - - if err != nil { - return fmt.Errorf("error listing tags for DataSync Location Fsx Windows (%s): %s", d.Id(), err) - } - - if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil { - return fmt.Errorf("error setting tags: %s", err) - } - - return nil -} - -func resourceAwsDataSyncLocationFsxWindowsUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).datasyncconn - locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsID(d.Id()) - if err != nil { - return err - } - - if d.HasChange("tags") { - o, n := d.GetChange("tags") - - if err := keyvaluetags.DatasyncUpdateTags(conn, locationArn, o, n); err != nil { - return fmt.Errorf("error updating DataSync Location FsxWindows (%s) tags: %s", locationArn, err) - } - } - - return resourceAwsDataSyncLocationFsxWindowsRead(d, meta) -} - -func resourceAwsDataSyncLocationFsxWindowsDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).datasyncconn - locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsID(d.Id()) - if err != nil { - return err - } - - input := &datasync.DeleteLocationInput{ - LocationArn: aws.String(locationArn), - } - - log.Printf("[DEBUG] Deleting DataSync Location FsxWindows: %s", input) - _, err = conn.DeleteLocation(input) - - if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { - return nil - } - - if err != nil { - return fmt.Errorf("error deleting DataSync Location Fsx Windows (%s): %s", locationArn, err) - } - - return nil -} - -func decodeAwsDataSyncLocationFsxWindowsID(id string) (string, string, error) { - parts := strings.Split(id, "#") - - if len(parts) != 2 { - return "", "", fmt.Errorf("Unexpected format of ID (%q), expected DataSyncLocationArn:FsxArn", id) - } - - return parts[0], parts[1], nil -} From 20e3a6b1ca3e15460149d2a7db701eff7a98458a Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Mon, 6 Apr 2020 00:49:51 +0300 Subject: [PATCH 11/23] fix lint (?) --- ...ource_aws_datasync_location_fsx_windows.go | 224 ++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 aws/resource_aws_datasync_location_fsx_windows.go diff --git a/aws/resource_aws_datasync_location_fsx_windows.go b/aws/resource_aws_datasync_location_fsx_windows.go new file mode 100644 index 00000000000..4da78f1bcd5 --- /dev/null +++ b/aws/resource_aws_datasync_location_fsx_windows.go @@ -0,0 +1,224 @@ +package aws + +import ( + "fmt" + "log" + "strings" + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/datasync" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" +) + +func resourceAwsDataSyncLocationFsxWindows() *schema.Resource { + return &schema.Resource{ + Create: resourceAwsDataSyncLocationFsxWindowsCreate, + Read: resourceAwsDataSyncLocationFsxWindowsRead, + Update: resourceAwsDataSyncLocationFsxWindowsUpdate, + Delete: resourceAwsDataSyncLocationFsxWindowsDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "fsx_filesystem_arn": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateArn, + }, + "password": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Sensitive: true, + ValidateFunc: validation.StringLenBetween(1, 104), + }, + "user": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(1, 104), + }, + "domain": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(1, 253), + }, + "security_group_arns": { + Type: schema.TypeSet, + Required: true, + ForceNew: true, + MinItems: 1, + MaxItems: 5, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validateArn, + }, + }, + "subdirectory": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(1, 4096), + }, + "tags": tagsSchema(), + "uri": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceAwsDataSyncLocationFsxWindowsCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).datasyncconn + fsxArn := d.Get("fsx_filesystem_arn").(string) + + input := &datasync.CreateLocationFsxWindowsInput{ + FsxFilesystemArn: aws.String(fsxArn), + User: aws.String(d.Get("user").(string)), + Password: aws.String(d.Get("password").(string)), + SecurityGroupArns: expandStringSet(d.Get("security_group_arns").(*schema.Set)), + Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().DatasyncTags(), + } + + if v, ok := d.GetOk("subdirectory"); ok { + input.Subdirectory = aws.String(v.(string)) + } + + if v, ok := d.GetOk("domain"); ok { + input.Domain = aws.String(v.(string)) + } + + log.Printf("[DEBUG] Creating DataSync Location FsxWindows: %s", input) + output, err := conn.CreateLocationFsxWindows(input) + if err != nil { + return fmt.Errorf("error creating DataSync Location FsxWindows: %s", err) + } + + d.SetId(fmt.Sprintf("%s#%s", aws.StringValue(output.LocationArn), fsxArn)) + + return resourceAwsDataSyncLocationFsxWindowsRead(d, meta) +} + +func resourceAwsDataSyncLocationFsxWindowsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).datasyncconn + locationArn, fsxArn, err := decodeAwsDataSyncLocationFsxWindowsID(d.Id()) + if err != nil { + return err + } + + input := &datasync.DescribeLocationFsxWindowsInput{ + LocationArn: aws.String(locationArn), + } + + log.Printf("[DEBUG] Reading DataSync Location Fsx Windows: %s", input) + output, err := conn.DescribeLocationFsxWindows(input) + + if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { + log.Printf("[WARN] DataSync Location Fsx Windows %q not found - removing from state", locationArn) + d.SetId("") + return nil + } + + if err != nil { + return fmt.Errorf("error reading DataSync Location Fsx Windows (%s): %s", locationArn, err) + } + + subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri)) + + if err != nil { + return fmt.Errorf("error parsing Location FsxWindows (%s) URI (%s): %s", d.Id(), aws.StringValue(output.LocationUri), err) + } + + d.Set("arn", output.LocationArn) + d.Set("fsx_filesystem_arn", fsxArn) + d.Set("security_group_arns", flattenStringSet(output.SecurityGroupArns)) + d.Set("subdirectory", subdirectory) + d.Set("uri", output.LocationUri) + d.Set("user", output.User) + d.Set("domain", output.Domain) + + if err := d.Set("creation_time", output.CreationTime.Format(time.RFC3339)); err != nil { + return fmt.Errorf("error setting creation_time: %s", err) + } + + tags, err := keyvaluetags.DatasyncListTags(conn, locationArn) + + if err != nil { + return fmt.Errorf("error listing tags for DataSync Location Fsx Windows (%s): %s", d.Id(), err) + } + + if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil { + return fmt.Errorf("error setting tags: %s", err) + } + + return nil +} + +func resourceAwsDataSyncLocationFsxWindowsUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).datasyncconn + locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsID(d.Id()) + if err != nil { + return err + } + + if d.HasChange("tags") { + o, n := d.GetChange("tags") + + if err := keyvaluetags.DatasyncUpdateTags(conn, locationArn, o, n); err != nil { + return fmt.Errorf("error updating DataSync Location FsxWindows (%s) tags: %s", locationArn, err) + } + } + + return resourceAwsDataSyncLocationFsxWindowsRead(d, meta) +} + +func resourceAwsDataSyncLocationFsxWindowsDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).datasyncconn + locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsID(d.Id()) + if err != nil { + return err + } + + input := &datasync.DeleteLocationInput{ + LocationArn: aws.String(locationArn), + } + + log.Printf("[DEBUG] Deleting DataSync Location FsxWindows: %s", input) + _, err = conn.DeleteLocation(input) + + if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { + return nil + } + + if err != nil { + return fmt.Errorf("error deleting DataSync Location Fsx Windows (%s): %s", locationArn, err) + } + + return nil +} + +func decodeAwsDataSyncLocationFsxWindowsID(id string) (string, string, error) { + parts := strings.Split(id, "#") + + if len(parts) != 2 { + return "", "", fmt.Errorf("Unexpected format of ID (%q), expected DataSyncLocationArn:FsxArn", id) + } + + return parts[0], parts[1], nil +} From df140ba0f97338c8c4007e9862ae7337619ac268 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Tue, 7 Apr 2020 17:40:44 +0300 Subject: [PATCH 12/23] rename to add `file_system` suffix --- aws/provider.go | 2 +- ...async_location_fsx_windows_file_system.go} | 40 +++++++++---------- ..._location_fsx_windows_file_system_test.go} | 36 ++++++++--------- ...ion_fsx_windows_file_system.html.markdown} | 10 ++--- 4 files changed, 44 insertions(+), 44 deletions(-) rename aws/{resource_aws_datasync_location_fsx_windows.go => resource_aws_datasync_location_fsx_windows_file_system.go} (74%) rename aws/{resource_aws_datasync_location_fsx_windows_test.go => resource_aws_datasync_location_fsx_windows_file_system_test.go} (88%) rename website/docs/r/{datasync_location_fsx_windows.html.markdown => datasync_location_fsx_windows_file_system.html.markdown} (76%) diff --git a/aws/provider.go b/aws/provider.go index 445f0f5249e..6d5d20e8ab3 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -488,7 +488,7 @@ func Provider() *schema.Provider { "aws_datapipeline_pipeline": resourceAwsDataPipelinePipeline(), "aws_datasync_agent": resourceAwsDataSyncAgent(), "aws_datasync_location_efs": resourceAwsDataSyncLocationEfs(), - "aws_datasync_location_fsx_windows": resourceAwsDataSyncLocationFsxWindows(), + "aws_datasync_location_fsx_windows_file_system": resourceAwsDataSyncLocationFsxWindowsFileSystem(), "aws_datasync_location_nfs": resourceAwsDataSyncLocationNfs(), "aws_datasync_location_s3": resourceAwsDataSyncLocationS3(), "aws_datasync_location_smb": resourceAwsDataSyncLocationSmb(), diff --git a/aws/resource_aws_datasync_location_fsx_windows.go b/aws/resource_aws_datasync_location_fsx_windows_file_system.go similarity index 74% rename from aws/resource_aws_datasync_location_fsx_windows.go rename to aws/resource_aws_datasync_location_fsx_windows_file_system.go index 4da78f1bcd5..bb1f1b0919a 100644 --- a/aws/resource_aws_datasync_location_fsx_windows.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system.go @@ -13,12 +13,12 @@ import ( "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" ) -func resourceAwsDataSyncLocationFsxWindows() *schema.Resource { +func resourceAwsDataSyncLocationFsxWindowsFileSystem() *schema.Resource { return &schema.Resource{ - Create: resourceAwsDataSyncLocationFsxWindowsCreate, - Read: resourceAwsDataSyncLocationFsxWindowsRead, - Update: resourceAwsDataSyncLocationFsxWindowsUpdate, - Delete: resourceAwsDataSyncLocationFsxWindowsDelete, + Create: resourceAwsDataSyncLocationFsxWindowsFileSystemCreate, + Read: resourceAwsDataSyncLocationFsxWindowsFileSystemRead, + Update: resourceAwsDataSyncLocationFsxWindowsFileSystemUpdate, + Delete: resourceAwsDataSyncLocationFsxWindowsFileSystemDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -84,7 +84,7 @@ func resourceAwsDataSyncLocationFsxWindows() *schema.Resource { } } -func resourceAwsDataSyncLocationFsxWindowsCreate(d *schema.ResourceData, meta interface{}) error { +func resourceAwsDataSyncLocationFsxWindowsFileSystemCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).datasyncconn fsxArn := d.Get("fsx_filesystem_arn").(string) @@ -104,20 +104,20 @@ func resourceAwsDataSyncLocationFsxWindowsCreate(d *schema.ResourceData, meta in input.Domain = aws.String(v.(string)) } - log.Printf("[DEBUG] Creating DataSync Location FsxWindows: %s", input) + log.Printf("[DEBUG] Creating DataSync Location Fsx Windows File System: %s", input) output, err := conn.CreateLocationFsxWindows(input) if err != nil { - return fmt.Errorf("error creating DataSync Location FsxWindows: %s", err) + return fmt.Errorf("error creating DataSync Location Fsx Windows File System: %s", err) } d.SetId(fmt.Sprintf("%s#%s", aws.StringValue(output.LocationArn), fsxArn)) - return resourceAwsDataSyncLocationFsxWindowsRead(d, meta) + return resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d, meta) } -func resourceAwsDataSyncLocationFsxWindowsRead(d *schema.ResourceData, meta interface{}) error { +func resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).datasyncconn - locationArn, fsxArn, err := decodeAwsDataSyncLocationFsxWindowsID(d.Id()) + locationArn, fsxArn, err := decodeAwsDataSyncLocationFsxWindowsFileSystemID(d.Id()) if err != nil { return err } @@ -142,7 +142,7 @@ func resourceAwsDataSyncLocationFsxWindowsRead(d *schema.ResourceData, meta inte subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri)) if err != nil { - return fmt.Errorf("error parsing Location FsxWindows (%s) URI (%s): %s", d.Id(), aws.StringValue(output.LocationUri), err) + return fmt.Errorf("error parsing Location Fsx Windows File System (%s) URI (%s): %s", d.Id(), aws.StringValue(output.LocationUri), err) } d.Set("arn", output.LocationArn) @@ -170,9 +170,9 @@ func resourceAwsDataSyncLocationFsxWindowsRead(d *schema.ResourceData, meta inte return nil } -func resourceAwsDataSyncLocationFsxWindowsUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceAwsDataSyncLocationFsxWindowsFileSystemUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).datasyncconn - locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsID(d.Id()) + locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsFileSystemID(d.Id()) if err != nil { return err } @@ -181,16 +181,16 @@ func resourceAwsDataSyncLocationFsxWindowsUpdate(d *schema.ResourceData, meta in o, n := d.GetChange("tags") if err := keyvaluetags.DatasyncUpdateTags(conn, locationArn, o, n); err != nil { - return fmt.Errorf("error updating DataSync Location FsxWindows (%s) tags: %s", locationArn, err) + return fmt.Errorf("error updating DataSync Location Fsx Windows File System (%s) tags: %s", locationArn, err) } } - return resourceAwsDataSyncLocationFsxWindowsRead(d, meta) + return resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d, meta) } -func resourceAwsDataSyncLocationFsxWindowsDelete(d *schema.ResourceData, meta interface{}) error { +func resourceAwsDataSyncLocationFsxWindowsFileSystemDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).datasyncconn - locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsID(d.Id()) + locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsFileSystemID(d.Id()) if err != nil { return err } @@ -199,7 +199,7 @@ func resourceAwsDataSyncLocationFsxWindowsDelete(d *schema.ResourceData, meta in LocationArn: aws.String(locationArn), } - log.Printf("[DEBUG] Deleting DataSync Location FsxWindows: %s", input) + log.Printf("[DEBUG] Deleting DataSync Location Fsx Windows File System: %s", input) _, err = conn.DeleteLocation(input) if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { @@ -213,7 +213,7 @@ func resourceAwsDataSyncLocationFsxWindowsDelete(d *schema.ResourceData, meta in return nil } -func decodeAwsDataSyncLocationFsxWindowsID(id string) (string, string, error) { +func decodeAwsDataSyncLocationFsxWindowsFileSystemID(id string) (string, string, error) { parts := strings.Split(id, "#") if len(parts) != 2 { diff --git a/aws/resource_aws_datasync_location_fsx_windows_test.go b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go similarity index 88% rename from aws/resource_aws_datasync_location_fsx_windows_test.go rename to aws/resource_aws_datasync_location_fsx_windows_file_system_test.go index dadb8de41c8..aa45bdac400 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_test.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go @@ -15,8 +15,8 @@ import ( ) func init() { - resource.AddTestSweepers("aws_datasync_location_fsx_windows", &resource.Sweeper{ - Name: "aws_datasync_location_fsx_windows", + resource.AddTestSweepers("aws_datasync_location_fsx_windows_file_system", &resource.Sweeper{ + Name: "aws_datasync_location_fsx_windows_file_system", F: testSweepDataSyncLocationFsxWindows, }) } @@ -42,17 +42,17 @@ func testSweepDataSyncLocationFsxWindows(region string) error { } if len(output.Locations) == 0 { - log.Print("[DEBUG] No DataSync Location FSX Windowss to sweep") + log.Print("[DEBUG] No DataSync Location FSX Windows File System to sweep") return nil } for _, location := range output.Locations { uri := aws.StringValue(location.LocationUri) if !strings.HasPrefix(uri, "fsxw://") { - log.Printf("[INFO] Skipping DataSync Location FSX Windows: %s", uri) + log.Printf("[INFO] Skipping DataSync Location FSX Windows File System: %s", uri) continue } - log.Printf("[INFO] Deleting DataSync Location FSX Windows: %s", uri) + log.Printf("[INFO] Deleting DataSync Location FSX Windows File System: %s", uri) input := &datasync.DeleteLocationInput{ LocationArn: location.LocationArn, } @@ -80,7 +80,7 @@ func testSweepDataSyncLocationFsxWindows(region string) error { func TestAccAWSDataSyncLocationFsxWindows_basic(t *testing.T) { var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput - resourceName := "aws_datasync_location_fsx_windows.test" + resourceName := "aws_datasync_location_fsx_windows_file_system.test" fsResourceName := "aws_fsx_windows_file_system.test" resource.ParallelTest(t, resource.TestCase{ @@ -112,7 +112,7 @@ func TestAccAWSDataSyncLocationFsxWindows_basic(t *testing.T) { func TestAccAWSDataSyncLocationFsxWindows_disappears(t *testing.T) { var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput - resourceName := "aws_datasync_location_fsx_windows.test" + resourceName := "aws_datasync_location_fsx_windows_file_system.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, @@ -133,7 +133,7 @@ func TestAccAWSDataSyncLocationFsxWindows_disappears(t *testing.T) { func TestAccAWSDataSyncLocationFsxWindows_Subdirectory(t *testing.T) { var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput - resourceName := "aws_datasync_location_fsx_windows.test" + resourceName := "aws_datasync_location_fsx_windows_file_system.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, @@ -159,7 +159,7 @@ func TestAccAWSDataSyncLocationFsxWindows_Subdirectory(t *testing.T) { func TestAccAWSDataSyncLocationFsxWindows_Tags(t *testing.T) { var locationFsxWindows1, locationFsxWindows2, locationFsxWindows3 datasync.DescribeLocationFsxWindowsOutput - resourceName := "aws_datasync_location_fsx_windows.test" + resourceName := "aws_datasync_location_fsx_windows_file_system.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, @@ -207,11 +207,11 @@ func testAccCheckAWSDataSyncLocationFsxWindowsDestroy(s *terraform.State) error conn := testAccProvider.Meta().(*AWSClient).datasyncconn for _, rs := range s.RootModule().Resources { - if rs.Type != "aws_datasync_location_fsx_windows" { + if rs.Type != "aws_datasync_location_fsx_windows_file_system" { continue } - locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsID(rs.Primary.ID) + locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsFileSystemID(rs.Primary.ID) if err != nil { return err } @@ -241,7 +241,7 @@ func testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName string, locati return fmt.Errorf("Not found: %s", resourceName) } - locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsID(rs.Primary.ID) + locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsFileSystemID(rs.Primary.ID) if err != nil { return err } @@ -284,7 +284,7 @@ func testAccCheckAWSDataSyncLocationFsxWindowsDisappears(location *datasync.Desc func testAccCheckAWSDataSyncLocationFsxWindowsNotRecreated(i, j *datasync.DescribeLocationFsxWindowsOutput) resource.TestCheckFunc { return func(s *terraform.State) error { if aws.TimeValue(i.CreationTime) != aws.TimeValue(j.CreationTime) { - return errors.New("DataSync Location FSX Windows was recreated") + return errors.New("DataSync Location FSX Windows File System was recreated") } return nil @@ -293,7 +293,7 @@ func testAccCheckAWSDataSyncLocationFsxWindowsNotRecreated(i, j *datasync.Descri func testAccAWSDataSyncLocationFsxWindowsConfig() string { return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` -resource "aws_datasync_location_fsx_windows" "test" { +resource "aws_datasync_location_fsx_windows_file_system" "test" { fsx_filesystem_arn = "${aws_fsx_windows_file_system.test.arn}" user = "SomeUser" password = "SuperSecretPassw0rd" @@ -304,19 +304,19 @@ resource "aws_datasync_location_fsx_windows" "test" { func testAccAWSDataSyncLocationFsxWindowsConfigSubdirectory(subdirectory string) string { return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` -resource "aws_datasync_location_fsx_windows" "test" { +resource "aws_datasync_location_fsx_windows_file_system" "test" { fsx_filesystem_arn = "${aws_fsx_windows_file_system.test.arn}" user = "SomeUser" password = "SuperSecretPassw0rd" security_group_arns = ["${aws_security_group.test1.arn}"] - subdirectory = %q + subdirectory = %[1]q } `, subdirectory) } func testAccAWSDataSyncLocationFsxWindowsConfigTags1(key1, value1 string) string { return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` -resource "aws_datasync_location_fsx_windows" "test" { +resource "aws_datasync_location_fsx_windows_file_system" "test" { fsx_filesystem_arn = "${aws_fsx_windows_file_system.test.arn}" user = "SomeUser" password = "SuperSecretPassw0rd" @@ -331,7 +331,7 @@ resource "aws_datasync_location_fsx_windows" "test" { func testAccAWSDataSyncLocationFsxWindowsConfigTags2(key1, value1, key2, value2 string) string { return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` -resource "aws_datasync_location_fsx_windows" "test" { +resource "aws_datasync_location_fsx_windows_file_system" "test" { fsx_filesystem_arn = "${aws_fsx_windows_file_system.test.arn}" user = "SomeUser" password = "SuperSecretPassw0rd" diff --git a/website/docs/r/datasync_location_fsx_windows.html.markdown b/website/docs/r/datasync_location_fsx_windows_file_system.html.markdown similarity index 76% rename from website/docs/r/datasync_location_fsx_windows.html.markdown rename to website/docs/r/datasync_location_fsx_windows_file_system.html.markdown index 1597cf66d84..8d7f67b8156 100644 --- a/website/docs/r/datasync_location_fsx_windows.html.markdown +++ b/website/docs/r/datasync_location_fsx_windows_file_system.html.markdown @@ -1,19 +1,19 @@ --- subcategory: "DataSync" layout: "aws" -page_title: "AWS: aws_datasync_location_fsx_windows" +page_title: "AWS: aws_datasync_location_fsx_windows_file_system" description: |- Manages an FSx Windows Location within AWS DataSync. --- -# Resource: aws_datasync_location_fsx_windows +# Resource: aws_datasync_location_fsx_windows_file_system Manages an AWS DataSync FSx Windows Location. ## Example Usage ```hcl -resource "aws_datasync_location_fsx_windows" "example" { +resource "aws_datasync_location_fsx_windows_file_system" "example" { fsx_filesystem_arn = "${aws_fsx_windows_file_system.example.arn}" user = "SomeUser" password = "SuperSecretPassw0rd" @@ -44,8 +44,8 @@ In addition to all arguments above, the following attributes are exported: ## Import -`aws_datasync_location_fsx_windows` can be imported by using the `DataSync-ARN#FSx-Windows-ARN`, e.g. +`aws_datasync_location_fsx_windows_file_system` can be imported by using the `DataSync-ARN#FSx-Windows-ARN`, e.g. ``` -$ terraform import aws_datasync_location_fsx_windows.example arn:aws:datasync:us-west-2:123456789012:location/loc-12345678901234567#arn:aws:fsx:us-west-2:476956259333:file-system/fs-08e04cd442c1bb94a +$ terraform import aws_datasync_location_fsx_windows_file_system.example arn:aws:datasync:us-west-2:123456789012:location/loc-12345678901234567#arn:aws:fsx:us-west-2:476956259333:file-system/fs-08e04cd442c1bb94a ``` From 847e7b25efcdafdc7edf693b713dfe6827726509 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 24 May 2020 09:14:07 +0300 Subject: [PATCH 13/23] disappears test + ignore tags --- ..._datasync_location_fsx_windows_file_system.go | 4 +++- ...sync_location_fsx_windows_file_system_test.go | 16 +--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system.go b/aws/resource_aws_datasync_location_fsx_windows_file_system.go index bb1f1b0919a..29dcb66370d 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system.go @@ -117,6 +117,8 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemCreate(d *schema.ResourceDat func resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).datasyncconn + ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig + locationArn, fsxArn, err := decodeAwsDataSyncLocationFsxWindowsFileSystemID(d.Id()) if err != nil { return err @@ -163,7 +165,7 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d *schema.ResourceData, return fmt.Errorf("error listing tags for DataSync Location Fsx Windows (%s): %s", d.Id(), err) } - if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil { + if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { return fmt.Errorf("error setting tags: %s", err) } diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go index aa45bdac400..1823002c25f 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go @@ -123,7 +123,7 @@ func TestAccAWSDataSyncLocationFsxWindows_disappears(t *testing.T) { Config: testAccAWSDataSyncLocationFsxWindowsConfig(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows1), - testAccCheckAWSDataSyncLocationFsxWindowsDisappears(&locationFsxWindows1), + testAccCheckResourceDisappears(testAccProvider, resourceAwsDataSyncLocationFsxWindowsFileSystem(), resourceName), ), ExpectNonEmptyPlan: true, }, @@ -267,20 +267,6 @@ func testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName string, locati } } -func testAccCheckAWSDataSyncLocationFsxWindowsDisappears(location *datasync.DescribeLocationFsxWindowsOutput) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).datasyncconn - - input := &datasync.DeleteLocationInput{ - LocationArn: location.LocationArn, - } - - _, err := conn.DeleteLocation(input) - - return err - } -} - func testAccCheckAWSDataSyncLocationFsxWindowsNotRecreated(i, j *datasync.DescribeLocationFsxWindowsOutput) resource.TestCheckFunc { return func(s *terraform.State) error { if aws.TimeValue(i.CreationTime) != aws.TimeValue(j.CreationTime) { From 2aefb31636d04921113178c18fb1ac9ad662d784 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Wed, 29 Jul 2020 00:43:50 +0300 Subject: [PATCH 14/23] use %w for errors --- ...urce_aws_datasync_location_fsx_windows_file_system_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go index 1823002c25f..c6db0fe9d7d 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go @@ -24,7 +24,7 @@ func init() { func testSweepDataSyncLocationFsxWindows(region string) error { client, err := sharedClientForRegion(region) if err != nil { - return fmt.Errorf("error getting client: %s", err) + return fmt.Errorf("error getting client: %w", err) } conn := client.(*AWSClient).datasyncconn @@ -38,7 +38,7 @@ func testSweepDataSyncLocationFsxWindows(region string) error { } if err != nil { - return fmt.Errorf("Error retrieving DataSync Location FSX Windows: %s", err) + return fmt.Errorf("error retrieving DataSync Location FSX Windows: %w", err) } if len(output.Locations) == 0 { From 00161991b29b94255f77d236198f7c1edfa60f60 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Wed, 29 Jul 2020 00:52:22 +0300 Subject: [PATCH 15/23] use %w for errors --- ...tasync_location_fsx_windows_file_system.go | 21 +++++++++++-------- ...c_location_fsx_windows_file_system_test.go | 19 +++-------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system.go b/aws/resource_aws_datasync_location_fsx_windows_file_system.go index 29dcb66370d..95a5a682b8c 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system.go @@ -107,7 +107,7 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemCreate(d *schema.ResourceDat log.Printf("[DEBUG] Creating DataSync Location Fsx Windows File System: %s", input) output, err := conn.CreateLocationFsxWindows(input) if err != nil { - return fmt.Errorf("error creating DataSync Location Fsx Windows File System: %s", err) + return fmt.Errorf("error creating DataSync Location Fsx Windows File System: %w", err) } d.SetId(fmt.Sprintf("%s#%s", aws.StringValue(output.LocationArn), fsxArn)) @@ -138,35 +138,38 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d *schema.ResourceData, } if err != nil { - return fmt.Errorf("error reading DataSync Location Fsx Windows (%s): %s", locationArn, err) + return fmt.Errorf("error reading DataSync Location Fsx Windows (%s): %w", locationArn, err) } subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri)) if err != nil { - return fmt.Errorf("error parsing Location Fsx Windows File System (%s) URI (%s): %s", d.Id(), aws.StringValue(output.LocationUri), err) + return fmt.Errorf("error parsing Location Fsx Windows File System (%s) URI (%s): %w", d.Id(), aws.StringValue(output.LocationUri), err) } d.Set("arn", output.LocationArn) d.Set("fsx_filesystem_arn", fsxArn) - d.Set("security_group_arns", flattenStringSet(output.SecurityGroupArns)) d.Set("subdirectory", subdirectory) d.Set("uri", output.LocationUri) d.Set("user", output.User) d.Set("domain", output.Domain) + if err := d.Set("security_group_arns", flattenStringSet(output.SecurityGroupArns)); err != nil { + return fmt.Errorf("error setting security_group_arns: %w", err) + } + if err := d.Set("creation_time", output.CreationTime.Format(time.RFC3339)); err != nil { - return fmt.Errorf("error setting creation_time: %s", err) + return fmt.Errorf("error setting creation_time: %w", err) } tags, err := keyvaluetags.DatasyncListTags(conn, locationArn) if err != nil { - return fmt.Errorf("error listing tags for DataSync Location Fsx Windows (%s): %s", d.Id(), err) + return fmt.Errorf("error listing tags for DataSync Location Fsx Windows (%s): %w", d.Id(), err) } if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return fmt.Errorf("error setting tags: %s", err) + return fmt.Errorf("error setting tags: %w", err) } return nil @@ -183,7 +186,7 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemUpdate(d *schema.ResourceDat o, n := d.GetChange("tags") if err := keyvaluetags.DatasyncUpdateTags(conn, locationArn, o, n); err != nil { - return fmt.Errorf("error updating DataSync Location Fsx Windows File System (%s) tags: %s", locationArn, err) + return fmt.Errorf("error updating DataSync Location Fsx Windows File System (%s) tags: %w", locationArn, err) } } @@ -209,7 +212,7 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemDelete(d *schema.ResourceDat } if err != nil { - return fmt.Errorf("error deleting DataSync Location Fsx Windows (%s): %s", locationArn, err) + return fmt.Errorf("error deleting DataSync Location Fsx Windows (%s): %w", locationArn, err) } return nil diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go index c6db0fe9d7d..d95ffd263f7 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go @@ -1,7 +1,6 @@ package aws import ( - "errors" "fmt" "log" "regexp" @@ -158,7 +157,7 @@ func TestAccAWSDataSyncLocationFsxWindows_Subdirectory(t *testing.T) { } func TestAccAWSDataSyncLocationFsxWindows_Tags(t *testing.T) { - var locationFsxWindows1, locationFsxWindows2, locationFsxWindows3 datasync.DescribeLocationFsxWindowsOutput + var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput resourceName := "aws_datasync_location_fsx_windows_file_system.test" resource.ParallelTest(t, resource.TestCase{ @@ -183,8 +182,7 @@ func TestAccAWSDataSyncLocationFsxWindows_Tags(t *testing.T) { { Config: testAccAWSDataSyncLocationFsxWindowsConfigTags2("key1", "value1updated", "key2", "value2"), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows2), - testAccCheckAWSDataSyncLocationFsxWindowsNotRecreated(&locationFsxWindows1, &locationFsxWindows2), + testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows1), resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), @@ -193,8 +191,7 @@ func TestAccAWSDataSyncLocationFsxWindows_Tags(t *testing.T) { { Config: testAccAWSDataSyncLocationFsxWindowsConfigTags1("key1", "value1"), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows3), - testAccCheckAWSDataSyncLocationFsxWindowsNotRecreated(&locationFsxWindows2, &locationFsxWindows3), + testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName, &locationFsxWindows1), resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), ), @@ -267,16 +264,6 @@ func testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName string, locati } } -func testAccCheckAWSDataSyncLocationFsxWindowsNotRecreated(i, j *datasync.DescribeLocationFsxWindowsOutput) resource.TestCheckFunc { - return func(s *terraform.State) error { - if aws.TimeValue(i.CreationTime) != aws.TimeValue(j.CreationTime) { - return errors.New("DataSync Location FSX Windows File System was recreated") - } - - return nil - } -} - func testAccAWSDataSyncLocationFsxWindowsConfig() string { return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` resource "aws_datasync_location_fsx_windows_file_system" "test" { From 0c63de7a6cd0b04a050196d751962ad2c89a1d33 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 2 Aug 2020 10:25:47 +0300 Subject: [PATCH 16/23] refactor id and state --- ...tasync_location_fsx_windows_file_system.go | 57 ++++++++----------- ...c_location_fsx_windows_file_system_test.go | 30 +++++----- 2 files changed, 40 insertions(+), 47 deletions(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system.go b/aws/resource_aws_datasync_location_fsx_windows_file_system.go index 95a5a682b8c..e0214b9214b 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system.go @@ -20,7 +20,20 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystem() *schema.Resource { Update: resourceAwsDataSyncLocationFsxWindowsFileSystemUpdate, Delete: resourceAwsDataSyncLocationFsxWindowsFileSystemDelete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + idParts := strings.Split(d.Id(), "#") + if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { + return nil, fmt.Errorf("Unexpected format of ID (%q), expected DataSyncLocationArn#FsxArn", d.Id()) + } + + DSArn := idParts[0] + FSxArn := idParts[1] + + d.Set("fsx_filesystem_arn", FSxArn) + d.SetId(DSArn) + + return []*schema.ResourceData{d}, nil + }, }, Schema: map[string]*schema.Schema{ @@ -119,26 +132,21 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d *schema.ResourceData, conn := meta.(*AWSClient).datasyncconn ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig - locationArn, fsxArn, err := decodeAwsDataSyncLocationFsxWindowsFileSystemID(d.Id()) - if err != nil { - return err - } - input := &datasync.DescribeLocationFsxWindowsInput{ - LocationArn: aws.String(locationArn), + LocationArn: aws.String(d.Id()), } log.Printf("[DEBUG] Reading DataSync Location Fsx Windows: %s", input) output, err := conn.DescribeLocationFsxWindows(input) if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { - log.Printf("[WARN] DataSync Location Fsx Windows %q not found - removing from state", locationArn) + log.Printf("[WARN] DataSync Location Fsx Windows %q not found - removing from state", d.Id()) d.SetId("") return nil } if err != nil { - return fmt.Errorf("error reading DataSync Location Fsx Windows (%s): %w", locationArn, err) + return fmt.Errorf("error reading DataSync Location Fsx Windows (%s): %w", d.Id(), err) } subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri)) @@ -148,7 +156,6 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d *schema.ResourceData, } d.Set("arn", output.LocationArn) - d.Set("fsx_filesystem_arn", fsxArn) d.Set("subdirectory", subdirectory) d.Set("uri", output.LocationUri) d.Set("user", output.User) @@ -162,7 +169,7 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d *schema.ResourceData, return fmt.Errorf("error setting creation_time: %w", err) } - tags, err := keyvaluetags.DatasyncListTags(conn, locationArn) + tags, err := keyvaluetags.DatasyncListTags(conn, d.Id()) if err != nil { return fmt.Errorf("error listing tags for DataSync Location Fsx Windows (%s): %w", d.Id(), err) @@ -177,16 +184,12 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d *schema.ResourceData, func resourceAwsDataSyncLocationFsxWindowsFileSystemUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).datasyncconn - locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsFileSystemID(d.Id()) - if err != nil { - return err - } if d.HasChange("tags") { o, n := d.GetChange("tags") - if err := keyvaluetags.DatasyncUpdateTags(conn, locationArn, o, n); err != nil { - return fmt.Errorf("error updating DataSync Location Fsx Windows File System (%s) tags: %w", locationArn, err) + if err := keyvaluetags.DatasyncUpdateTags(conn, d.Id(), o, n); err != nil { + return fmt.Errorf("error updating DataSync Location Fsx Windows File System (%s) tags: %w", d.Id(), err) } } @@ -195,35 +198,21 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemUpdate(d *schema.ResourceDat func resourceAwsDataSyncLocationFsxWindowsFileSystemDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).datasyncconn - locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsFileSystemID(d.Id()) - if err != nil { - return err - } input := &datasync.DeleteLocationInput{ - LocationArn: aws.String(locationArn), + LocationArn: aws.String(d.Id()), } log.Printf("[DEBUG] Deleting DataSync Location Fsx Windows File System: %s", input) - _, err = conn.DeleteLocation(input) + _, err := conn.DeleteLocation(input) if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { return nil } if err != nil { - return fmt.Errorf("error deleting DataSync Location Fsx Windows (%s): %w", locationArn, err) + return fmt.Errorf("error deleting DataSync Location Fsx Windows (%s): %w", d.Id(), err) } return nil } - -func decodeAwsDataSyncLocationFsxWindowsFileSystemID(id string) (string, string, error) { - parts := strings.Split(id, "#") - - if len(parts) != 2 { - return "", "", fmt.Errorf("Unexpected format of ID (%q), expected DataSyncLocationArn:FsxArn", id) - } - - return parts[0], parts[1], nil -} diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go index d95ffd263f7..24bad8d3bbf 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go @@ -103,6 +103,7 @@ func TestAccAWSDataSyncLocationFsxWindows_basic(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, + ImportStateIdFunc: testAccWSDataSyncLocationFsxWindowsImportStateIdFunc(resourceName), ImportStateVerifyIgnore: []string{"password"}, }, }, @@ -150,6 +151,7 @@ func TestAccAWSDataSyncLocationFsxWindows_Subdirectory(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, + ImportStateIdFunc: testAccWSDataSyncLocationFsxWindowsImportStateIdFunc(resourceName), ImportStateVerifyIgnore: []string{"password"}, }, }, @@ -177,6 +179,7 @@ func TestAccAWSDataSyncLocationFsxWindows_Tags(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, + ImportStateIdFunc: testAccWSDataSyncLocationFsxWindowsImportStateIdFunc(resourceName), ImportStateVerifyIgnore: []string{"password"}, }, { @@ -208,16 +211,11 @@ func testAccCheckAWSDataSyncLocationFsxWindowsDestroy(s *terraform.State) error continue } - locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsFileSystemID(rs.Primary.ID) - if err != nil { - return err - } - input := &datasync.DescribeLocationFsxWindowsInput{ - LocationArn: aws.String(locationArn), + LocationArn: aws.String(rs.Primary.ID), } - _, err = conn.DescribeLocationFsxWindows(input) + _, err := conn.DescribeLocationFsxWindows(input) if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { return nil @@ -238,14 +236,9 @@ func testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName string, locati return fmt.Errorf("Not found: %s", resourceName) } - locationArn, _, err := decodeAwsDataSyncLocationFsxWindowsFileSystemID(rs.Primary.ID) - if err != nil { - return err - } - conn := testAccProvider.Meta().(*AWSClient).datasyncconn input := &datasync.DescribeLocationFsxWindowsInput{ - LocationArn: aws.String(locationArn), + LocationArn: aws.String(rs.Primary.ID), } output, err := conn.DescribeLocationFsxWindows(input) @@ -264,6 +257,17 @@ func testAccCheckAWSDataSyncLocationFsxWindowsExists(resourceName string, locati } } +func testAccWSDataSyncLocationFsxWindowsImportStateIdFunc(resourceName string) resource.ImportStateIdFunc { + return func(s *terraform.State) (string, error) { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return "", fmt.Errorf("Not found: %s", resourceName) + } + + return fmt.Sprintf("%s#%s", rs.Primary.ID, rs.Primary.Attributes["fsx_filesystem_arn"]), nil + } +} + func testAccAWSDataSyncLocationFsxWindowsConfig() string { return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` resource "aws_datasync_location_fsx_windows_file_system" "test" { From 3ee9e77e59cbce6a44b961748c4b7aaf969a839d Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Sun, 2 Aug 2020 10:27:27 +0300 Subject: [PATCH 17/23] Update website/docs/r/datasync_location_fsx_windows_file_system.html.markdown Co-authored-by: Kit Ewbank --- .../r/datasync_location_fsx_windows_file_system.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/datasync_location_fsx_windows_file_system.html.markdown b/website/docs/r/datasync_location_fsx_windows_file_system.html.markdown index 8d7f67b8156..744f1d22687 100644 --- a/website/docs/r/datasync_location_fsx_windows_file_system.html.markdown +++ b/website/docs/r/datasync_location_fsx_windows_file_system.html.markdown @@ -29,7 +29,7 @@ The following arguments are supported: * `password` - (Required) The password of the user who has the permissions to access files and folders in the FSx for Windows file system. * `user` - (Required) The user who has the permissions to access files and folders in the FSx for Windows file system. * `domain` - (Optional) The name of the Windows domain that the FSx for Windows server belongs to. -* `security_group_arns` - (Optional) The Amazon Resource Names (ARNs) of the security groups that are to use to configure the FSx for Windows file system. +* `security_group_arns` - (Optional) The Amazon Resource Names (ARNs) of the security groups used to configure the FSx for Windows file system. * `subdirectory` - (Optional) Subdirectory to perform actions as source or destination. * `tags` - (Optional) Key-value pairs of resource tags to assign to the DataSync Location. From 9d2f26a708bb1652ae321267f33586c2f10e8fa2 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Sun, 2 Aug 2020 23:40:13 +0300 Subject: [PATCH 18/23] Update aws/resource_aws_datasync_location_fsx_windows_file_system.go Co-authored-by: Kit Ewbank --- aws/resource_aws_datasync_location_fsx_windows_file_system.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system.go b/aws/resource_aws_datasync_location_fsx_windows_file_system.go index e0214b9214b..baeec486a10 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system.go @@ -123,7 +123,7 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemCreate(d *schema.ResourceDat return fmt.Errorf("error creating DataSync Location Fsx Windows File System: %w", err) } - d.SetId(fmt.Sprintf("%s#%s", aws.StringValue(output.LocationArn), fsxArn)) + d.SetId(aws.StringValue(output.LocationArn)) return resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d, meta) } From 00f5543005b65f5beb035f8b9988d6940c08283d Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 2 Aug 2020 23:42:48 +0300 Subject: [PATCH 19/23] tf 12 docs --- .../datasync_location_fsx_windows_file_system.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/r/datasync_location_fsx_windows_file_system.html.markdown b/website/docs/r/datasync_location_fsx_windows_file_system.html.markdown index 744f1d22687..3d7b3a581a5 100644 --- a/website/docs/r/datasync_location_fsx_windows_file_system.html.markdown +++ b/website/docs/r/datasync_location_fsx_windows_file_system.html.markdown @@ -14,10 +14,10 @@ Manages an AWS DataSync FSx Windows Location. ```hcl resource "aws_datasync_location_fsx_windows_file_system" "example" { - fsx_filesystem_arn = "${aws_fsx_windows_file_system.example.arn}" + fsx_filesystem_arn = aws_fsx_windows_file_system.example.arn user = "SomeUser" password = "SuperSecretPassw0rd" - security_group_arns = ["${aws_security_group.test1.arn}"] + security_group_arns = [aws_security_group.example.arn] } ``` @@ -29,7 +29,7 @@ The following arguments are supported: * `password` - (Required) The password of the user who has the permissions to access files and folders in the FSx for Windows file system. * `user` - (Required) The user who has the permissions to access files and folders in the FSx for Windows file system. * `domain` - (Optional) The name of the Windows domain that the FSx for Windows server belongs to. -* `security_group_arns` - (Optional) The Amazon Resource Names (ARNs) of the security groups used to configure the FSx for Windows file system. +* `security_group_arns` - (Optional) The Amazon Resource Names (ARNs) of the security groups that are to use to configure the FSx for Windows file system. * `subdirectory` - (Optional) Subdirectory to perform actions as source or destination. * `tags` - (Optional) Key-value pairs of resource tags to assign to the DataSync Location. From 7ce9d4fa8dc8063f3efb8898c217a50bb1926fb4 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 2 Aug 2020 23:44:11 +0300 Subject: [PATCH 20/23] tf 12 test config --- ...sync_location_fsx_windows_file_system_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go index 24bad8d3bbf..cebb6094f95 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go @@ -271,10 +271,10 @@ func testAccWSDataSyncLocationFsxWindowsImportStateIdFunc(resourceName string) r func testAccAWSDataSyncLocationFsxWindowsConfig() string { return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` resource "aws_datasync_location_fsx_windows_file_system" "test" { - fsx_filesystem_arn = "${aws_fsx_windows_file_system.test.arn}" + fsx_filesystem_arn = aws_fsx_windows_file_system.test.arn user = "SomeUser" password = "SuperSecretPassw0rd" - security_group_arns = ["${aws_security_group.test1.arn}"] + security_group_arns = [aws_security_group.test1.arn] } `) } @@ -282,10 +282,10 @@ resource "aws_datasync_location_fsx_windows_file_system" "test" { func testAccAWSDataSyncLocationFsxWindowsConfigSubdirectory(subdirectory string) string { return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` resource "aws_datasync_location_fsx_windows_file_system" "test" { - fsx_filesystem_arn = "${aws_fsx_windows_file_system.test.arn}" + fsx_filesystem_arn = aws_fsx_windows_file_system.test.arn user = "SomeUser" password = "SuperSecretPassw0rd" - security_group_arns = ["${aws_security_group.test1.arn}"] + security_group_arns = [aws_security_group.test1.arn] subdirectory = %[1]q } `, subdirectory) @@ -294,10 +294,10 @@ resource "aws_datasync_location_fsx_windows_file_system" "test" { func testAccAWSDataSyncLocationFsxWindowsConfigTags1(key1, value1 string) string { return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` resource "aws_datasync_location_fsx_windows_file_system" "test" { - fsx_filesystem_arn = "${aws_fsx_windows_file_system.test.arn}" + fsx_filesystem_arn = aws_fsx_windows_file_system.test.arn user = "SomeUser" password = "SuperSecretPassw0rd" - security_group_arns = ["${aws_security_group.test1.arn}"] + security_group_arns = [aws_security_group.test1.arn] tags = { %[1]q = %[2]q @@ -309,10 +309,10 @@ resource "aws_datasync_location_fsx_windows_file_system" "test" { func testAccAWSDataSyncLocationFsxWindowsConfigTags2(key1, value1, key2, value2 string) string { return testAccAwsFsxWindowsFileSystemConfigSecurityGroupIds1() + fmt.Sprintf(` resource "aws_datasync_location_fsx_windows_file_system" "test" { - fsx_filesystem_arn = "${aws_fsx_windows_file_system.test.arn}" + fsx_filesystem_arn = aws_fsx_windows_file_system.test.arn user = "SomeUser" password = "SuperSecretPassw0rd" - security_group_arns = ["${aws_security_group.test1.arn}"] + security_group_arns = [aws_security_group.test1.arn] tags = { %[1]q = %[2]q From 912c0f7f122de6183930f8007afad2fb277ab14a Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 2 Aug 2020 23:49:41 +0300 Subject: [PATCH 21/23] lower case for test names --- ...urce_aws_datasync_location_fsx_windows_file_system_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go index cebb6094f95..6db7d9cad67 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go @@ -131,7 +131,7 @@ func TestAccAWSDataSyncLocationFsxWindows_disappears(t *testing.T) { }) } -func TestAccAWSDataSyncLocationFsxWindows_Subdirectory(t *testing.T) { +func TestAccAWSDataSyncLocationFsxWindows_subdirectory(t *testing.T) { var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput resourceName := "aws_datasync_location_fsx_windows_file_system.test" @@ -158,7 +158,7 @@ func TestAccAWSDataSyncLocationFsxWindows_Subdirectory(t *testing.T) { }) } -func TestAccAWSDataSyncLocationFsxWindows_Tags(t *testing.T) { +func TestAccAWSDataSyncLocationFsxWindows_tags(t *testing.T) { var locationFsxWindows1 datasync.DescribeLocationFsxWindowsOutput resourceName := "aws_datasync_location_fsx_windows_file_system.test" From 1a67e6c8e88f56cb2a743adea26eb6d5adeaae8a Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 15 Aug 2020 00:44:08 +0300 Subject: [PATCH 22/23] v2 --- aws/resource_aws_datasync_location_fsx_windows_file_system.go | 4 ++-- ...urce_aws_datasync_location_fsx_windows_file_system_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system.go b/aws/resource_aws_datasync_location_fsx_windows_file_system.go index baeec486a10..d43619f5ae2 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system.go @@ -8,8 +8,8 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/datasync" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" ) diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go index 6db7d9cad67..3c5be0c7d92 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system_test.go @@ -9,8 +9,8 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/datasync" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) func init() { From 572e0f7046e173c505f034438dc691422d2951f4 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 22 Aug 2020 00:40:46 +0300 Subject: [PATCH 23/23] use %#v for complex types in logs --- ...esource_aws_datasync_location_fsx_windows_file_system.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_datasync_location_fsx_windows_file_system.go b/aws/resource_aws_datasync_location_fsx_windows_file_system.go index d43619f5ae2..c3a85982ad2 100644 --- a/aws/resource_aws_datasync_location_fsx_windows_file_system.go +++ b/aws/resource_aws_datasync_location_fsx_windows_file_system.go @@ -117,7 +117,7 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemCreate(d *schema.ResourceDat input.Domain = aws.String(v.(string)) } - log.Printf("[DEBUG] Creating DataSync Location Fsx Windows File System: %s", input) + log.Printf("[DEBUG] Creating DataSync Location Fsx Windows File System: %#v", input) output, err := conn.CreateLocationFsxWindows(input) if err != nil { return fmt.Errorf("error creating DataSync Location Fsx Windows File System: %w", err) @@ -136,7 +136,7 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d *schema.ResourceData, LocationArn: aws.String(d.Id()), } - log.Printf("[DEBUG] Reading DataSync Location Fsx Windows: %s", input) + log.Printf("[DEBUG] Reading DataSync Location Fsx Windows: %#v", input) output, err := conn.DescribeLocationFsxWindows(input) if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") { @@ -203,7 +203,7 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemDelete(d *schema.ResourceDat LocationArn: aws.String(d.Id()), } - log.Printf("[DEBUG] Deleting DataSync Location Fsx Windows File System: %s", input) + log.Printf("[DEBUG] Deleting DataSync Location Fsx Windows File System: %#v", input) _, err := conn.DeleteLocation(input) if isAWSErr(err, datasync.ErrCodeInvalidRequestException, "not found") {