@@ -409,6 +409,100 @@ func TestAccPolicy_ProjectID(t *testing.T) {
409
409
})
410
410
}
411
411
412
+ func TestAccPolicy_Condition (t * testing.T ) {
413
+ tt := acctest .NewTestTools (t )
414
+ defer tt .Cleanup ()
415
+ ctx := context .Background ()
416
+ project , iamAPIKey , terminateFakeSideProject , err := acctest .CreateFakeIAMManager (tt )
417
+ require .NoError (t , err )
418
+
419
+ resource .ParallelTest (t , resource.TestCase {
420
+ ProviderFactories : acctest .FakeSideProjectProviders (ctx , tt , project , iamAPIKey ),
421
+ CheckDestroy : resource .ComposeAggregateTestCheckFunc (
422
+ func (_ * terraform.State ) error {
423
+ return terminateFakeSideProject ()
424
+ },
425
+ testAccCheckIamPolicyDestroy (tt ),
426
+ ),
427
+ Steps : []resource.TestStep {
428
+ {
429
+ Config : fmt .Sprintf (`
430
+ resource "scaleway_iam_policy" "main" {
431
+ name = "tf_tests_policy_condition"
432
+ description = "a description"
433
+ no_principal = true
434
+ rule {
435
+ organization_id = "%s"
436
+ permission_set_names = ["AllProductsFullAccess"]
437
+ condition = "1 == 1"
438
+ }
439
+ provider = side
440
+ }
441
+ ` , project .OrganizationID ),
442
+ Check : resource .ComposeTestCheckFunc (
443
+ testAccCheckIamPolicyExists (tt , "scaleway_iam_policy.main" ),
444
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "name" , "tf_tests_policy_condition" ),
445
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "description" , "a description" ),
446
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "no_principal" , "true" ),
447
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "rule.0.organization_id" , project .OrganizationID ),
448
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "rule.0.permission_set_names.#" , "1" ),
449
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "rule.0.condition" , "1 == 1" ),
450
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "rule.0.permission_set_names.0" , "AllProductsFullAccess" ),
451
+ ),
452
+ },
453
+ {
454
+ Config : fmt .Sprintf (`
455
+ resource "scaleway_iam_policy" "main" {
456
+ name = "tf_tests_policy_condition"
457
+ description = "a description"
458
+ no_principal = true
459
+ rule {
460
+ project_ids = ["%s"]
461
+ permission_set_names = ["AllProductsFullAccess"]
462
+ condition = "request.user_agent == 'terraform-test'"
463
+ }
464
+ provider = side
465
+ }
466
+ ` , project .OrganizationID ),
467
+ Check : resource .ComposeTestCheckFunc (
468
+ testAccCheckIamPolicyExists (tt , "scaleway_iam_policy.main" ),
469
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "name" , "tf_tests_policy_condition" ),
470
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "description" , "a description" ),
471
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "no_principal" , "true" ),
472
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "rule.0.organization_id" , "" ),
473
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "rule.0.permission_set_names.#" , "1" ),
474
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "rule.0.condition" , "request.user_agent == 'terraform-test'" ),
475
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "rule.0.permission_set_names.0" , "AllProductsFullAccess" ),
476
+ ),
477
+ },
478
+ {
479
+ Config : fmt .Sprintf (`
480
+ resource "scaleway_iam_policy" "main" {
481
+ name = "tf_tests_policy_condition"
482
+ description = "a description"
483
+ no_principal = true
484
+ rule {
485
+ project_ids = ["%s"]
486
+ permission_set_names = ["AllProductsFullAccess"]
487
+ }
488
+ provider = side
489
+ }
490
+ ` , project .OrganizationID ),
491
+ Check : resource .ComposeTestCheckFunc (
492
+ testAccCheckIamPolicyExists (tt , "scaleway_iam_policy.main" ),
493
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "name" , "tf_tests_policy_condition" ),
494
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "description" , "a description" ),
495
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "no_principal" , "true" ),
496
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "rule.0.organization_id" , "" ),
497
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "rule.0.permission_set_names.#" , "1" ),
498
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "rule.0.condition" , "" ),
499
+ resource .TestCheckResourceAttr ("scaleway_iam_policy.main" , "rule.0.permission_set_names.0" , "AllProductsFullAccess" ),
500
+ ),
501
+ },
502
+ },
503
+ })
504
+ }
505
+
412
506
func TestAccPolicy_ChangeRulePrincipal (t * testing.T ) {
413
507
tt := acctest .NewTestTools (t )
414
508
defer tt .Cleanup ()
0 commit comments