diff --git a/aws/resource_aws_ssm_activation.go b/aws/resource_aws_ssm_activation.go index c23ca0eb2086..8fb58671d0bd 100644 --- a/aws/resource_aws_ssm_activation.go +++ b/aws/resource_aws_ssm_activation.go @@ -34,9 +34,10 @@ func resourceAwsSsmActivation() *schema.Resource { Computed: true, }, "expiration_date": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validateRFC3339TimeString, }, "iam_role": { Type: schema.TypeString, @@ -77,8 +78,9 @@ func resourceAwsSsmActivationCreate(d *schema.ResourceData, meta interface{}) er activationInput.Description = aws.String(d.Get("description").(string)) } - if _, ok := d.GetOk("expiration_date"); ok { - activationInput.ExpirationDate = aws.Time(d.Get("expiration_date").(time.Time)) + if v, ok := d.GetOk("expiration_date"); ok { + t, _ := time.Parse(time.RFC3339, v.(string)) + activationInput.ExpirationDate = aws.Time(t) } if _, ok := d.GetOk("iam_role"); ok { diff --git a/aws/resource_aws_ssm_activation_test.go b/aws/resource_aws_ssm_activation_test.go index 6e66671b62af..b41f09c6c5ad 100644 --- a/aws/resource_aws_ssm_activation_test.go +++ b/aws/resource_aws_ssm_activation_test.go @@ -2,7 +2,9 @@ package aws import ( "fmt" + "regexp" "testing" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ssm" @@ -29,6 +31,32 @@ func TestAccAWSSSMActivation_basic(t *testing.T) { }) } +func TestAccAWSSSMActivation_expirationDate(t *testing.T) { + rName := acctest.RandString(10) + expirationTime := time.Now().Add(48 * time.Hour) + expirationDateS := expirationTime.Format(time.RFC3339) + resourceName := "aws_ssm_activation.foo" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSSMActivationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSSMActivationConfig_expirationDate(rName, "2018-03-01"), + ExpectError: regexp.MustCompile(`cannot parse`), + }, + { + Config: testAccAWSSSMActivationConfig_expirationDate(rName, expirationDateS), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMActivationExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "expiration_date", expirationDateS), + ), + }, + }, + }) +} + func testAccCheckAWSSSMActivationExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -130,3 +158,39 @@ resource "aws_ssm_activation" "foo" { } `, rName, rName) } + +func testAccAWSSSMActivationConfig_expirationDate(rName, expirationDate string) string { + return fmt.Sprintf(` +resource "aws_iam_role" "test_role" { + name = "test_role-%[1]s" + assume_role_policy = <