@@ -6,19 +6,23 @@ import (
66 "fmt"
77 "strings"
88 "time"
9- helper "github.com/cloudposse/test-helpers/pkg/atmos/component-helper"
10- awsHelper "github.com/cloudposse/test-helpers/pkg/aws"
119 "github.com/cloudposse/test-helpers/pkg/atmos"
1210 "github.com/cloudposse/test-helpers/pkg/helm"
13- "github.com/gruntwork-io/terratest/modules/aws"
14- "github.com/stretchr/testify/assert"
11+ awsHelper "github.com/cloudposse/test-helpers/pkg/aws"
12+ helper "github.com/cloudposse/test-helpers/pkg/atmos/component-helper"
13+ awsTerratest "github.com/gruntwork-io/terratest/modules/aws"
1514 "github.com/gruntwork-io/terratest/modules/random"
1615
16+ "github.com/stretchr/testify/assert"
17+
18+ "github.com/aws/aws-sdk-go-v2/aws"
19+ "github.com/aws/aws-sdk-go-v2/service/route53"
20+ "github.com/aws/aws-sdk-go-v2/service/route53/types"
1721 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1822 "k8s.io/apimachinery/pkg/runtime/schema"
1923 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
20- "k8s.io/client-go/dynamic"
2124
25+ "k8s.io/client-go/dynamic"
2226 "k8s.io/client-go/dynamic/dynamicinformer"
2327 "k8s.io/client-go/tools/cache"
2428)
@@ -179,9 +183,59 @@ func (s *ComponentSuite) TestBasic() {
179183 assert .Fail (s .T (), msg )
180184 }
181185
182- delegatedNSRecord := aws .GetRoute53Record (s .T (), defaultDNSZoneId , dnsRecordHostName , "A" , awsRegion )
186+ delegatedNSRecord := awsTerratest .GetRoute53Record (s .T (), defaultDNSZoneId , dnsRecordHostName , "A" , awsRegion )
183187 assert .Equal (s .T (), fmt .Sprintf ("%s." , dnsRecordHostName ), * delegatedNSRecord .Name )
184188
189+
190+ defer func () {
191+ route53Client , err := awsTerratest .NewRoute53ClientE (s .T (), awsRegion )
192+ if err != nil {
193+ return
194+ }
195+
196+ o , err := route53Client .ListResourceRecordSets (context .Background (), & route53.ListResourceRecordSetsInput {
197+ HostedZoneId : & defaultDNSZoneId ,
198+ MaxItems : aws .Int32 (100 ),
199+ })
200+ if err != nil {
201+ return
202+ }
203+
204+ var changes []types.Change
205+
206+ for _ , record := range o .ResourceRecordSets {
207+
208+ if record .Type == types .RRTypeNs || record .Type == types .RRTypeSoa {
209+ continue
210+ }
211+ // Build a deletion change for each record
212+ changes = append (changes , types.Change {
213+ Action : types .ChangeActionDelete ,
214+ ResourceRecordSet : & record ,
215+ })
216+ }
217+
218+ if len (changes ) == 0 {
219+ fmt .Println ("No deletable records found." )
220+ return
221+ }
222+
223+ // Prepare the change batch
224+ changeBatch := & types.ChangeBatch {
225+ Changes : changes ,
226+ }
227+
228+ // Call ChangeResourceRecordSets to delete the records
229+ changeInput := & route53.ChangeResourceRecordSetsInput {
230+ HostedZoneId : aws .String (defaultDNSZoneId ),
231+ ChangeBatch : changeBatch ,
232+ }
233+
234+ _ , err = route53Client .ChangeResourceRecordSets (context .Background (), changeInput )
235+ assert .NoError (s .T (), err )
236+
237+ }()
238+
185239 s .DriftTest (component , stack , & inputs )
186240}
187241
0 commit comments