Skip to content

Commit 3588fdf

Browse files
authored
Merge pull request #45488 from tabito-hara/td-aws_organizations-add_S3_BEDROCK_policies
[Docs/Tests] aws_organizations_organization/aws_organizations_policy: Add tests and update documentation for `S3_POLICY` and `BEDROCK_POLICY`
2 parents 22266d2 + 61e5aa9 commit 3588fdf

File tree

5 files changed

+194
-2
lines changed

5 files changed

+194
-2
lines changed

internal/service/organizations/organization_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,24 @@ func testAccOrganization_EnabledPolicyTypes(t *testing.T) {
256256
resource.TestCheckResourceAttr(resourceName, "enabled_policy_types.0", string(awstypes.PolicyTypeUpgradeRolloutPolicy)),
257257
),
258258
},
259+
{
260+
Config: testAccOrganizationConfig_enabledPolicyTypes1(string(awstypes.PolicyTypeS3Policy)),
261+
Check: resource.ComposeTestCheckFunc(
262+
testAccCheckOrganizationExists(ctx, resourceName, &organization),
263+
resource.TestCheckResourceAttr(resourceName, "aws_service_access_principals.#", "0"),
264+
resource.TestCheckResourceAttr(resourceName, "enabled_policy_types.#", "1"),
265+
resource.TestCheckResourceAttr(resourceName, "enabled_policy_types.0", string(awstypes.PolicyTypeS3Policy)),
266+
),
267+
},
268+
{
269+
Config: testAccOrganizationConfig_enabledPolicyTypes1(string(awstypes.PolicyTypeBedrockPolicy)),
270+
Check: resource.ComposeTestCheckFunc(
271+
testAccCheckOrganizationExists(ctx, resourceName, &organization),
272+
resource.TestCheckResourceAttr(resourceName, "aws_service_access_principals.#", "0"),
273+
resource.TestCheckResourceAttr(resourceName, "enabled_policy_types.#", "1"),
274+
resource.TestCheckResourceAttr(resourceName, "enabled_policy_types.0", string(awstypes.PolicyTypeBedrockPolicy)),
275+
),
276+
},
259277
{
260278
ResourceName: resourceName,
261279
ImportState: true,

internal/service/organizations/organizations_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ func TestAccOrganizations_serial(t *testing.T) {
7777
"Type_SecurityHub": testAccPolicy_type_SecurityHub,
7878
"Type_Inspector": testAccPolicy_type_Inspector,
7979
"Type_UpgradeRollout": testAccPolicy_type_UpgradeRollout,
80+
"Type_S3": testAccPolicy_type_S3,
81+
"Type_Bedrock": testAccPolicy_type_Bedrock,
8082
"ImportAwsManagedPolicy": testAccPolicy_importManagedPolicy,
8183
"Identity": testAccOrganizationsPolicy_IdentitySerial,
8284
},

internal/service/organizations/policy_test.go

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,78 @@ func testAccPolicy_type_UpgradeRollout(t *testing.T) {
565565
})
566566
}
567567

568+
func testAccPolicy_type_S3(t *testing.T) {
569+
ctx := acctest.Context(t)
570+
var policy awstypes.Policy
571+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
572+
resourceName := "aws_organizations_policy.test"
573+
// Reference: https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_s3_syntax.html
574+
s3PolicyContent := `{
575+
"s3_attributes": {
576+
"public_access_block_configuration": {
577+
"@@assign": "all"
578+
}
579+
}
580+
}`
581+
582+
resource.Test(t, resource.TestCase{
583+
PreCheck: func() {
584+
acctest.PreCheck(ctx, t)
585+
acctest.PreCheckOrganizationManagementAccount(ctx, t)
586+
},
587+
ErrorCheck: acctest.ErrorCheck(t, names.OrganizationsServiceID),
588+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
589+
CheckDestroy: testAccCheckPolicyDestroy(ctx),
590+
Steps: []resource.TestStep{
591+
{
592+
Config: testAccPolicyConfig_type(rName, s3PolicyContent, string(awstypes.PolicyTypeS3Policy)),
593+
Check: resource.ComposeTestCheckFunc(
594+
testAccCheckPolicyExists(ctx, resourceName, &policy),
595+
resource.TestCheckResourceAttr(resourceName, names.AttrType, string(awstypes.PolicyTypeS3Policy)),
596+
),
597+
},
598+
{
599+
ResourceName: resourceName,
600+
ImportState: true,
601+
ImportStateVerify: true,
602+
ImportStateVerifyIgnore: []string{names.AttrSkipDestroy},
603+
},
604+
},
605+
})
606+
}
607+
608+
func testAccPolicy_type_Bedrock(t *testing.T) {
609+
ctx := acctest.Context(t)
610+
var policy awstypes.Policy
611+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
612+
resourceName := "aws_organizations_policy.test"
613+
614+
resource.Test(t, resource.TestCase{
615+
PreCheck: func() {
616+
acctest.PreCheck(ctx, t)
617+
acctest.PreCheckOrganizationManagementAccount(ctx, t)
618+
},
619+
ErrorCheck: acctest.ErrorCheck(t, names.OrganizationsServiceID),
620+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
621+
CheckDestroy: testAccCheckPolicyDestroy(ctx),
622+
Steps: []resource.TestStep{
623+
{
624+
Config: testAccPolicyConfig_type_Bedrock(rName),
625+
Check: resource.ComposeTestCheckFunc(
626+
testAccCheckPolicyExists(ctx, resourceName, &policy),
627+
resource.TestCheckResourceAttr(resourceName, names.AttrType, string(awstypes.PolicyTypeBedrockPolicy)),
628+
),
629+
},
630+
{
631+
ResourceName: resourceName,
632+
ImportState: true,
633+
ImportStateVerify: true,
634+
ImportStateVerifyIgnore: []string{names.AttrSkipDestroy},
635+
},
636+
},
637+
})
638+
}
639+
568640
func testAccPolicy_importManagedPolicy(t *testing.T) {
569641
ctx := acctest.Context(t)
570642
resourceName := "aws_organizations_policy.test"
@@ -784,6 +856,104 @@ resource "aws_organizations_policy" "test" {
784856
`, strconv.Quote(content), rName, policyType)
785857
}
786858

859+
func testAccPolicyConfig_type_Bedrock(rName string) string {
860+
return fmt.Sprintf(`
861+
data "aws_region" "current" {}
862+
863+
resource "aws_bedrock_guardrail" "test" {
864+
name = %[1]q
865+
blocked_input_messaging = "test"
866+
blocked_outputs_messaging = "test"
867+
description = "test"
868+
869+
content_policy_config {
870+
filters_config {
871+
input_strength = "MEDIUM"
872+
output_strength = "MEDIUM"
873+
type = "HATE"
874+
}
875+
filters_config {
876+
input_strength = "HIGH"
877+
output_strength = "HIGH"
878+
type = "VIOLENCE"
879+
}
880+
}
881+
882+
contextual_grounding_policy_config {
883+
filters_config {
884+
threshold = 0.4
885+
type = "GROUNDING"
886+
}
887+
}
888+
889+
sensitive_information_policy_config {
890+
pii_entities_config {
891+
action = "BLOCK"
892+
type = "NAME"
893+
}
894+
pii_entities_config {
895+
action = "BLOCK"
896+
type = "DRIVER_ID"
897+
}
898+
pii_entities_config {
899+
action = "ANONYMIZE"
900+
type = "USERNAME"
901+
}
902+
regexes_config {
903+
action = "BLOCK"
904+
description = "example regex"
905+
name = "regex_example"
906+
pattern = "^\\d{3}-\\d{2}-\\d{4}$"
907+
}
908+
}
909+
910+
topic_policy_config {
911+
topics_config {
912+
name = "investment_topic"
913+
examples = ["Where should I invest my money ?"]
914+
type = "DENY"
915+
definition = "Investment advice refers to inquiries, guidance, or recommendations regarding the management or allocation of funds or assets with the goal of generating returns ."
916+
}
917+
}
918+
919+
word_policy_config {
920+
managed_word_lists_config {
921+
type = "PROFANITY"
922+
}
923+
words_config {
924+
text = "HATE"
925+
}
926+
}
927+
}
928+
929+
resource "aws_bedrock_guardrail_version" "test" {
930+
guardrail_arn = aws_bedrock_guardrail.test.guardrail_arn
931+
}
932+
933+
resource "aws_organizations_policy" "test" {
934+
# Reference: https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_bedrock_syntax.html
935+
content = jsonencode({
936+
"bedrock" : {
937+
"guardrail_inference" : {
938+
(data.aws_region.current.region) : {
939+
"config_1" : {
940+
"identifier" : {
941+
"@@assign" : "${aws_bedrock_guardrail.test.guardrail_arn}:${aws_bedrock_guardrail_version.test.version}"
942+
},
943+
"input_tags" : {
944+
"@@assign" : "honor"
945+
}
946+
}
947+
}
948+
}
949+
}
950+
})
951+
name = %[1]q
952+
type = "BEDROCK_POLICY"
953+
}
954+
`, rName)
955+
}
956+
787957
func testAccPolicyConfig_skipDestroy(rName, content string) string {
788958
return fmt.Sprintf(`
789959
resource "aws_organizations_policy" "test" {

website/docs/r/organizations_organization.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ resource "aws_organizations_organization" "org" {
3232
This resource supports the following arguments:
3333

3434
* `aws_service_access_principals` - (Optional) List of AWS service principal names for which you want to enable integration with your organization. This is typically in the form of a URL, such as service-abbreviation.amazonaws.com. Organization must have `feature_set` set to `ALL`. Some services do not support enablement via this endpoint, see [warning in aws docs](https://docs.aws.amazon.com/organizations/latest/APIReference/API_EnableAWSServiceAccess.html).
35-
* `enabled_policy_types` - (Optional) List of Organizations policy types to enable in the Organization Root. Organization must have `feature_set` set to `ALL`. For additional information about valid policy types (e.g., `AISERVICES_OPT_OUT_POLICY`, `BACKUP_POLICY`, `CHATBOT_POLICY`, `DECLARATIVE_POLICY_EC2`, `INSPECTOR_POLICY`, `RESOURCE_CONTROL_POLICY`, `SECURITYHUB_POLICY`, `SERVICE_CONTROL_POLICY`, `TAG_POLICY` and `UPGRADE_ROLLOUT_POLICY`), see the [AWS Organizations API Reference](https://docs.aws.amazon.com/organizations/latest/APIReference/API_EnablePolicyType.html). To enable `INSPECTOR_POLICY`, `aws_service_access_principals` must include `inspector2.amazonaws.com`. To enable `SECURITYHUB_POLICY`, `aws_service_access_principals` must include `securityhub.amazonaws.com`.
35+
* `enabled_policy_types` - (Optional) List of Organizations policy types to enable in the Organization Root. Organization must have `feature_set` set to `ALL`. For additional information about valid policy types (e.g., `AISERVICES_OPT_OUT_POLICY`, `BACKUP_POLICY`, `BEDROCK_POLICY`, `CHATBOT_POLICY`, `DECLARATIVE_POLICY_EC2`, `INSPECTOR_POLICY`, `RESOURCE_CONTROL_POLICY`, `S3_POLICY`, `SECURITYHUB_POLICY`, `SERVICE_CONTROL_POLICY`, `TAG_POLICY` and `UPGRADE_ROLLOUT_POLICY`), see the [AWS Organizations API Reference](https://docs.aws.amazon.com/organizations/latest/APIReference/API_EnablePolicyType.html). To enable `INSPECTOR_POLICY`, `aws_service_access_principals` must include `inspector2.amazonaws.com`. To enable `SECURITYHUB_POLICY`, `aws_service_access_principals` must include `securityhub.amazonaws.com`.
3636
* `feature_set` - (Optional) Specify `ALL` (default) or `CONSOLIDATED_BILLING`.
3737

3838
## Attribute Reference

website/docs/r/organizations_policy.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,19 @@ This resource supports the following arguments:
3535
For example, if you create a [service control policy (SCP)](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html), this string must be JSON text that specifies the permissions that admins in attached accounts can delegate to their users, groups, and roles.
3636
For more information about the AI Services opt-out Policy syntax, see the [AI Services opt-out Policy Syntax documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out_syntax.html).
3737
For more information about the Backup Policy syntax, see the [Backup Policy Syntax documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup_syntax.html).
38+
For more information about the Bedrock Policy syntax, see the [Bedrock Policy Syntax documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_bedrock_syntax.html).
3839
For more information about the Chatbot Policy syntax, see the [Chatbot Policy Syntax documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_chatbot_syntax.html).
3940
For more information about the Declarative Policy syntax, see the [Declarative Policy Syntax documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_declarative_syntax.html).
4041
For more information about the Inspector Policy syntax, see the [Inspector Policy Syntax documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_inspector_syntax.html).
4142
For more information about the RCP syntax, see the [Resource Control Policy Syntax documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_rcps_syntax.html).
43+
For more information about the S3 Policy syntax, see the [S3 Policy Syntax documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_s3_syntax.html).
4244
For more information about the Security Hub Policy syntax, see the [Security Hub Policy Syntax documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_security_hub_syntax.html). For more information about the SCP syntax, see the [Service Control Policy Syntax documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_reference_scp-syntax.html).
4345
For more information on the Tag Policy syntax, see the [Tag Policy Syntax documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_example-tag-policies.html).
4446
For more information about the Upgrade Rollout Policy syntax, see the [Upgrade Rollout Policy Syntax documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_upgrade_syntax.html).
4547
* `name` - (Required) The friendly name to assign to the policy.
4648
* `description` - (Optional) A description to assign to the policy.
4749
* `skip_destroy` - (Optional) If set to `true`, destroy will **not** delete the policy and instead just remove the resource from state. This can be useful in situations where the policies (and the associated attachment) must be preserved to meet the AWS minimum requirement of 1 attached policy.
48-
* `type` - (Optional) The type of policy to create. Valid values are `AISERVICES_OPT_OUT_POLICY`, `BACKUP_POLICY`, `CHATBOT_POLICY`, `DECLARATIVE_POLICY_EC2`, `INSPECTOR_POLICY`, `RESOURCE_CONTROL_POLICY` (RCP), `SECURITYHUB_POLICY`, `SERVICE_CONTROL_POLICY` (SCP), `TAG_POLICY`, and `UPGRADE_ROLLOUT_POLICY`. Defaults to `SERVICE_CONTROL_POLICY`.
50+
* `type` - (Optional) The type of policy to create. Valid values are `AISERVICES_OPT_OUT_POLICY`, `BACKUP_POLICY`, `BEDROCK_POLICY`, `CHATBOT_POLICY`, `DECLARATIVE_POLICY_EC2`, `INSPECTOR_POLICY`, `RESOURCE_CONTROL_POLICY` (RCP), `S3_POLICY`, `SECURITYHUB_POLICY`, `SERVICE_CONTROL_POLICY` (SCP), `TAG_POLICY`, and `UPGRADE_ROLLOUT_POLICY`. Defaults to `SERVICE_CONTROL_POLICY`.
4951
* `tags` - (Optional) Key-value map of resource tags. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
5052

5153
## Attribute Reference

0 commit comments

Comments
 (0)