@@ -209,6 +209,62 @@ func TestAccFISExperimentTemplate_spot(t *testing.T) {
209
209
})
210
210
}
211
211
212
+ func TestAccFISExperimentTemplate_eks (t * testing.T ) {
213
+ ctx := acctest .Context (t )
214
+ if testing .Short () {
215
+ t .Skip ("skipping long-running test in short mode" )
216
+ }
217
+ rName := sdkacctest .RandomWithPrefix (acctest .ResourcePrefix )
218
+ resourceName := "aws_fis_experiment_template.test"
219
+ var conf types.ExperimentTemplate
220
+
221
+ resource .ParallelTest (t , resource.TestCase {
222
+ PreCheck : func () { acctest .PreCheck (ctx , t ) },
223
+ ErrorCheck : acctest .ErrorCheck (t , fis .ServiceID ),
224
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
225
+ CheckDestroy : testAccCheckExperimentTemplateDestroy (ctx ),
226
+ Steps : []resource.TestStep {
227
+ {
228
+ Config : testAccExperimentTemplateConfig_eks (rName , "kubernetes custom resource creation" , "k8s-pod-delete" , "k8s pod delete" , "aws:eks:inject-kubernetes-custom-resource" , "Cluster" , "kubernetes-custom-resource-creation-target" , "kubernetesApiVersion" , "litmuschaos.io/v1alpha1" , "kubernetesKind" , "ChaosEngine" , "kubernetesNamespace" , "observability" , "kubernetesSpec" , "{\" engineState\" :\" active\" ,\" appinfo\" :{\" appns\" :\" observability\" ,\" applabel\" :\" app=nginx\" ,\" appkind\" :\" deployment\" },\" chaosServiceAccount\" :\" pod-delete-sa\" ,\" experiments\" :[{\" name\" :\" pod-delete\" ,\" spec\" :{\" components\" :{\" env\" :[{\" name\" :\" TOTAL_CHAOS_DURATION\" ,\" value\" :\" 60\" },{\" name\" :\" CHAOS_INTERVAL\" ,\" value\" :\" 60\" },{\" name\" :\" PODS_AFFECTED_PERC\" ,\" value\" :\" 30\" }]},\" probe\" :[]}}],\" annotationCheck\" :\" false\" }" , "maxDuration" , "PT2M" , "aws:eks:cluster" , "ALL" , "env" , "test" ),
229
+ Check : resource .ComposeTestCheckFunc (
230
+ testAccExperimentTemplateExists (ctx , resourceName , & conf ),
231
+ resource .TestCheckResourceAttr (resourceName , "description" , "kubernetes custom resource creation" ),
232
+ resource .TestCheckResourceAttrPair (resourceName , "role_arn" , "aws_iam_role.test_fis" , "arn" ),
233
+ resource .TestCheckResourceAttr (resourceName , "stop_condition.0.source" , "none" ),
234
+ resource .TestCheckResourceAttr (resourceName , "stop_condition.0.value" , "" ),
235
+ resource .TestCheckResourceAttr (resourceName , "stop_condition.#" , "1" ),
236
+ resource .TestCheckResourceAttr (resourceName , "action.0.name" , "k8s-pod-delete" ),
237
+ resource .TestCheckResourceAttr (resourceName , "action.0.description" , "k8s pod delete" ),
238
+ resource .TestCheckResourceAttr (resourceName , "action.0.action_id" , "aws:eks:inject-kubernetes-custom-resource" ),
239
+ resource .TestCheckResourceAttr (resourceName , "action.0.parameter.#" , "5" ),
240
+ resource .TestCheckResourceAttr (resourceName , "action.0.parameter.0.key" , "kubernetesApiVersion" ),
241
+ resource .TestCheckResourceAttr (resourceName , "action.0.parameter.0.value" , "litmuschaos.io/v1alpha1" ),
242
+ resource .TestCheckResourceAttr (resourceName , "action.0.parameter.1.key" , "kubernetesKind" ),
243
+ resource .TestCheckResourceAttr (resourceName , "action.0.parameter.1.value" , "ChaosEngine" ),
244
+ resource .TestCheckResourceAttr (resourceName , "action.0.parameter.2.key" , "kubernetesNamespace" ),
245
+ resource .TestCheckResourceAttr (resourceName , "action.0.parameter.2.value" , "observability" ),
246
+ resource .TestCheckResourceAttr (resourceName , "action.0.parameter.3.key" , "kubernetesSpec" ),
247
+ resource .TestCheckResourceAttr (resourceName , "action.0.parameter.3.value" , "{\" engineState\" :\" active\" ,\" appinfo\" :{\" appns\" :\" observability\" ,\" applabel\" :\" app=nginx\" ,\" appkind\" :\" deployment\" },\" chaosServiceAccount\" :\" pod-delete-sa\" ,\" experiments\" :[{\" name\" :\" pod-delete\" ,\" spec\" :{\" components\" :{\" env\" :[{\" name\" :\" TOTAL_CHAOS_DURATION\" ,\" value\" :\" 60\" },{\" name\" :\" CHAOS_INTERVAL\" ,\" value\" :\" 60\" },{\" name\" :\" PODS_AFFECTED_PERC\" ,\" value\" :\" 30\" }]},\" probe\" :[]}}],\" annotationCheck\" :\" false\" }" ),
248
+ resource .TestCheckResourceAttr (resourceName , "action.0.parameter.4.key" , "maxDuration" ),
249
+ resource .TestCheckResourceAttr (resourceName , "action.0.parameter.4.value" , "PT2M" ),
250
+ resource .TestCheckResourceAttr (resourceName , "action.0.start_after.#" , "0" ),
251
+ resource .TestCheckResourceAttr (resourceName , "action.0.target.0.key" , "Cluster" ),
252
+ resource .TestCheckResourceAttr (resourceName , "action.0.target.0.value" , "kubernetes-custom-resource-creation-target" ),
253
+ resource .TestCheckResourceAttr (resourceName , "action.0.target.#" , "1" ),
254
+ resource .TestCheckResourceAttr (resourceName , "action.#" , "1" ),
255
+ resource .TestCheckResourceAttr (resourceName , "target.0.name" , "kubernetes-custom-resource-creation-target" ),
256
+ resource .TestCheckResourceAttr (resourceName , "target.0.resource_type" , "aws:eks:cluster" ),
257
+ resource .TestCheckResourceAttr (resourceName , "target.0.selection_mode" , "ALL" ),
258
+ resource .TestCheckResourceAttr (resourceName , "target.0.filter.#" , "0" ),
259
+ resource .TestCheckResourceAttrPair (resourceName , "target.0.resource_arns.0" , "aws_eks_cluster.test" , "arn" ),
260
+ resource .TestCheckResourceAttr (resourceName , "target.0.resource_tag.#" , "0" ),
261
+ resource .TestCheckResourceAttr (resourceName , "target.#" , "1" ),
262
+ ),
263
+ },
264
+ },
265
+ })
266
+ }
267
+
212
268
func testAccExperimentTemplateExists (ctx context.Context , resourceName string , config * types.ExperimentTemplate ) resource.TestCheckFunc {
213
269
return func (s * terraform.State ) error {
214
270
rs , ok := s .RootModule ().Resources [resourceName ]
@@ -373,3 +429,148 @@ resource "aws_fis_experiment_template" "test" {
373
429
}
374
430
` , rName , desc , actionName , actionDesc , actionID , actionTargetK , actionTargetV , paramK , paramV , targetResType , targetSelectMode , targetResTagK , targetResTagV )
375
431
}
432
+ func testAccExperimentTemplateConfig_baseEKSCluster (rName string ) string {
433
+ return acctest .ConfigCompose (acctest .ConfigAvailableAZsNoOptIn (), fmt .Sprintf (`
434
+ data "aws_partition" "current" {}
435
+
436
+ resource "aws_iam_role" "test" {
437
+ name = %[1]q
438
+
439
+ assume_role_policy = <<POLICY
440
+ {
441
+ "Version": "2012-10-17",
442
+ "Statement": [
443
+ {
444
+ "Effect": "Allow",
445
+ "Principal": {
446
+ "Service": "eks.${data.aws_partition.current.dns_suffix}"
447
+ },
448
+ "Action": "sts:AssumeRole"
449
+ }
450
+ ]
451
+ }
452
+ POLICY
453
+ }
454
+
455
+ resource "aws_iam_role_policy_attachment" "test-AmazonEKSClusterPolicy" {
456
+ policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonEKSClusterPolicy"
457
+ role = aws_iam_role.test.name
458
+ }
459
+
460
+ resource "aws_vpc" "test" {
461
+ cidr_block = "10.0.0.0/16"
462
+
463
+ assign_generated_ipv6_cidr_block = true
464
+
465
+ tags = {
466
+ Name = %[1]q
467
+ "kubernetes.io/cluster/%[1]s" = "shared"
468
+ }
469
+ }
470
+
471
+ resource "aws_subnet" "test" {
472
+ count = 2
473
+
474
+ availability_zone = data.aws_availability_zones.available.names[count.index]
475
+ cidr_block = "10.0.${count.index}.0/24"
476
+ vpc_id = aws_vpc.test.id
477
+
478
+ ipv6_cidr_block = cidrsubnet(aws_vpc.test.ipv6_cidr_block, 8, count.index)
479
+ assign_ipv6_address_on_creation = true
480
+
481
+ tags = {
482
+ Name = %[1]q
483
+ "kubernetes.io/cluster/%[1]s" = "shared"
484
+ }
485
+ }
486
+
487
+ resource "aws_eks_cluster" "test" {
488
+ name = %[1]q
489
+ role_arn = aws_iam_role.test.arn
490
+
491
+ vpc_config {
492
+ subnet_ids = aws_subnet.test[*].id
493
+ }
494
+
495
+ depends_on = [aws_iam_role_policy_attachment.test-AmazonEKSClusterPolicy]
496
+ }
497
+ ` , rName ))
498
+ }
499
+
500
+ func testAccExperimentTemplateConfig_eks (rName , desc , actionName , actionDesc , actionID , actionTargetK , actionTargetV , paramK1 , paramV1 , paramK2 , paramV2 , paramK3 , paramV3 , paramK4 , paramV4 , paramK5 , paramV5 , targetResType , targetSelectMode , targetResTagK , targetResTagV string ) string {
501
+ return acctest .ConfigCompose (testAccExperimentTemplateConfig_baseEKSCluster (rName ), fmt .Sprintf (`
502
+ resource "aws_iam_role" "test_fis" {
503
+ name = %[1]q
504
+
505
+ assume_role_policy = jsonencode({
506
+ Statement = [{
507
+ Action = "sts:AssumeRole"
508
+ Effect = "Allow"
509
+ Principal = {
510
+ Service = [
511
+ "fis.${data.aws_partition.current.dns_suffix}",
512
+ ]
513
+ }
514
+ }]
515
+ Version = "2012-10-17"
516
+ })
517
+ }
518
+
519
+ resource "aws_fis_experiment_template" "test" {
520
+ description = %[2]q
521
+ role_arn = aws_iam_role.test_fis.arn
522
+
523
+ stop_condition {
524
+ source = "none"
525
+ }
526
+
527
+ action {
528
+ name = %[3]q
529
+ description = %[4]q
530
+ action_id = %[5]q
531
+
532
+ target {
533
+ key = %[6]q
534
+ value = %[7]q
535
+ }
536
+
537
+ parameter {
538
+ key = %[8]q
539
+ value = %[9]q
540
+ }
541
+
542
+ parameter {
543
+ key = %[10]q
544
+ value = %[11]q
545
+ }
546
+
547
+ parameter {
548
+ key = %[12]q
549
+ value = %[13]q
550
+ }
551
+
552
+ parameter {
553
+ key = %[14]q
554
+ value = %[15]q
555
+ }
556
+
557
+ parameter {
558
+ key = %[16]q
559
+ value = %[17]q
560
+ }
561
+ }
562
+
563
+ target {
564
+ name = %[7]q
565
+ resource_type = %[18]q
566
+ selection_mode = %[19]q
567
+
568
+ resource_arns = tolist([aws_eks_cluster.test.arn])
569
+ }
570
+
571
+ tags = {
572
+ Name = %[1]q
573
+ }
574
+ }
575
+ ` , rName + "-fis" , desc , actionName , actionDesc , actionID , actionTargetK , actionTargetV , paramK1 , paramV1 , paramK2 , paramV2 , paramK3 , paramV3 , paramK4 , paramV4 , paramK5 , paramV5 , targetResType , targetSelectMode , targetResTagK , targetResTagV ))
576
+ }
0 commit comments