@@ -159,7 +159,7 @@ func testAccDomainAssociation_update(t *testing.T) {
159159 resource .TestCheckTypeSetElemNestedAttrs (resourceName , "sub_domain.*" , map [string ]string {
160160 "branch_name" : rName ,
161161 names .AttrPrefix : "" ,
162- // "verified": acctest.CtTrue, // Even though we're waiting for verification, this isn't getting verified
162+ "verified" : acctest .CtTrue ,
163163 }),
164164 resource .TestCheckTypeSetElemNestedAttrs (resourceName , "sub_domain.*" , map [string ]string {
165165 "branch_name" : fmt .Sprintf ("%s-2" , rName ),
@@ -309,6 +309,59 @@ func testAccDomainAssociation_certificateSettings_Custom(t *testing.T) {
309309 })
310310}
311311
312+ func testAccDomainAssociation_CreateWithSubdomain (t * testing.T ) {
313+ ctx := acctest .Context (t )
314+ key := "AMPLIFY_DOMAIN_NAME"
315+ domainName := os .Getenv (key )
316+ if domainName == "" {
317+ t .Skipf ("Environment variable %s is not set" , key )
318+ }
319+
320+ var domain types.DomainAssociation
321+ rName := sdkacctest .RandomWithPrefix (acctest .ResourcePrefix )
322+ resourceName := "aws_amplify_domain_association.test"
323+
324+ resource .Test (t , resource.TestCase {
325+ PreCheck : func () { acctest .PreCheck (ctx , t ); testAccPreCheck (t ) },
326+ ErrorCheck : acctest .ErrorCheck (t , names .AmplifyServiceID ),
327+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
328+ CheckDestroy : testAccCheckDomainAssociationDestroy (ctx ),
329+ Steps : []resource.TestStep {
330+ {
331+ Config : testAccDomainAssociationConfig_WithSubdomain (rName , domainName , true ),
332+ Check : resource .ComposeAggregateTestCheckFunc (
333+ testAccCheckDomainAssociationExists (ctx , resourceName , & domain ),
334+ acctest .MatchResourceAttrRegionalARN (ctx , resourceName , names .AttrARN , "amplify" , regexache .MustCompile (fmt .Sprintf (`apps/.+/domains/%s$` , domainName ))),
335+ resource .TestCheckResourceAttr (resourceName , "certificate_settings.#" , "1" ),
336+ resource .TestCheckResourceAttrSet (resourceName , "certificate_settings.0.certificate_verification_dns_record" ),
337+ resource .TestCheckResourceAttr (resourceName , "certificate_settings.0.custom_certificate_arn" , "" ),
338+ resource .TestCheckResourceAttr (resourceName , "certificate_settings.0.type" , "AMPLIFY_MANAGED" ),
339+ resource .TestCheckResourceAttr (resourceName , names .AttrDomainName , domainName ),
340+ resource .TestCheckResourceAttr (resourceName , "enable_auto_sub_domain" , acctest .CtFalse ),
341+ resource .TestCheckResourceAttr (resourceName , "sub_domain.#" , "2" ),
342+ resource .TestCheckTypeSetElemNestedAttrs (resourceName , "sub_domain.*" , map [string ]string {
343+ "branch_name" : rName ,
344+ names .AttrPrefix : "" ,
345+ "verified" : acctest .CtTrue , // Even though we're waiting for verification, this isn't getting verified
346+ }),
347+ resource .TestCheckTypeSetElemNestedAttrs (resourceName , "sub_domain.*" , map [string ]string {
348+ "branch_name" : rName ,
349+ names .AttrPrefix : "www" ,
350+ // "verified": acctest.CtTrue, // Even though we're waiting for verification, this isn't getting verified
351+ }),
352+ resource .TestCheckResourceAttr (resourceName , "wait_for_verification" , acctest .CtTrue ),
353+ ),
354+ },
355+ {
356+ ResourceName : resourceName ,
357+ ImportState : true ,
358+ ImportStateVerify : true ,
359+ ImportStateVerifyIgnore : []string {"wait_for_verification" },
360+ },
361+ },
362+ })
363+ }
364+
312365func testAccCheckDomainAssociationExists (ctx context.Context , n string , v * types.DomainAssociation ) resource.TestCheckFunc {
313366 return func (s * terraform.State ) error {
314367 rs , ok := s .RootModule ().Resources [n ]
@@ -513,6 +566,36 @@ resource "aws_acm_certificate_validation" "test" {
513566 ` , rName , domainName , enableAutoSubDomain , waitForVerification ))
514567}
515568
569+ func testAccDomainAssociationConfig_WithSubdomain (rName , domainName string , waitForVerification bool ) string {
570+ return fmt .Sprintf (`
571+ resource "aws_amplify_domain_association" "test" {
572+ app_id = aws_amplify_app.test.id
573+ domain_name = %[2]q
574+
575+ sub_domain {
576+ branch_name = aws_amplify_branch.test.branch_name
577+ prefix = ""
578+ }
579+
580+ sub_domain {
581+ branch_name = aws_amplify_branch.test.branch_name
582+ prefix = "www"
583+ }
584+
585+ wait_for_verification = %[3]t
586+ }
587+
588+ resource "aws_amplify_app" "test" {
589+ name = %[1]q
590+ }
591+
592+ resource "aws_amplify_branch" "test" {
593+ app_id = aws_amplify_app.test.id
594+ branch_name = %[1]q
595+ }
596+ ` , rName , domainName , waitForVerification )
597+ }
598+
516599// In practice, we don't seem to need to wait for the Domain Association to be `AVAILABLE` for the purposes of deploying infrastructure.
517600// Since subsequent modifications to a Domain Association cannot occur until it is `AVAILABLE`, wait during tests.
518601func domainAssociationStatusAvailablePreConfig (ctx context.Context , t * testing.T , app * types.App , domain * types.DomainAssociation ) func () {
0 commit comments