Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F organization policy #30920

Merged
merged 57 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
279a31c
Adding ListPoliciesForTarget and test files
danielw-aws Apr 11, 2023
eaa3633
adding website documentation
danielw-aws Apr 11, 2023
db2b26e
changed naming on constant and fixed tests
danielw-aws Apr 11, 2023
0d7510a
attempted to fix test
danielw-aws Apr 11, 2023
551941f
fixed linter issues in web documents
danielw-aws Apr 11, 2023
ed89223
fixed indents
danielw-aws Apr 11, 2023
a77fafe
added newline at end
danielw-aws Apr 11, 2023
f74e589
changed Testing function name
danielw-aws Apr 12, 2023
dea20af
Changed testing variable name
danielw-aws Apr 12, 2023
b383759
fixed resource data
danielw-aws Apr 12, 2023
5867dac
changed resource block to data block in test
danielw-aws Apr 12, 2023
2b76ed0
added required filter
danielw-aws Apr 12, 2023
d0954bf
added filter to test harness
danielw-aws Apr 12, 2023
324c4e7
fixed findPoliciesForTarget variables
danielw-aws Apr 12, 2023
8066a9a
attempting fix on test
danielw-aws Apr 12, 2023
d2d5559
second attempt at fixing filter
danielw-aws Apr 12, 2023
f1d0e22
third attempt at fixing filter
danielw-aws Apr 12, 2023
4492701
added change log text
danielw-aws Apr 12, 2023
46d084b
Merge branch 'hashicorp:main' into f-organizational-policies
danielw-aws Apr 12, 2023
2213bb5
updated website docs to reflect data source code changes
danielw-aws Apr 12, 2023
2534f31
adding initial file versions for organizations policy data source
danielw-aws Apr 13, 2023
7991db8
fixed wrong import
danielw-aws Apr 13, 2023
42c73f7
added diags var
danielw-aws Apr 13, 2023
f3a045d
fixed errors
danielw-aws Apr 13, 2023
9c2b50b
fixed organizations connection
danielw-aws Apr 13, 2023
f0a101d
fixed Describe Policy with Context call
danielw-aws Apr 13, 2023
bd7e7ac
function variables needs a comma between them
danielw-aws Apr 13, 2023
bb79adb
fixing Describe call
danielw-aws Apr 13, 2023
8055472
fixing Describe call v2
danielw-aws Apr 13, 2023
4e77cee
changed err in describe polciy with context function
danielw-aws Apr 14, 2023
e033e7d
fixed output
danielw-aws Apr 14, 2023
9bf8f1b
attempting to fix describe policy call
danielw-aws Apr 14, 2023
c3580d8
cleaned up the function to return the data
danielw-aws Apr 17, 2023
3d95de9
removed comma
danielw-aws Apr 17, 2023
8645f11
fixed policyID var
danielw-aws Apr 17, 2023
30d5a17
fixed error
danielw-aws Apr 17, 2023
6b50f5b
used correct API call
danielw-aws Apr 17, 2023
5a0a7ca
changed input to correct input
danielw-aws Apr 17, 2023
10e035f
fixed context->content and changed AWSManaged to bool value. Fixed or…
danielw-aws Apr 17, 2023
ab10492
fixed organaizational policies data source
danielw-aws Apr 17, 2023
3975847
fixing website docs
danielw-aws Apr 17, 2023
39acec7
fixed website docs
danielw-aws Apr 20, 2023
d88e0f5
got linter working
danielw-aws Apr 20, 2023
33d5057
deleted other branches files
danielw-aws Apr 20, 2023
7c2ece5
Added change log for current feature removed other extraneous files
danielw-aws Apr 20, 2023
b20c72c
fixed test
danielw-aws Apr 20, 2023
87e6e2e
fixed policy in test
danielw-aws Apr 20, 2023
218bf74
fixed name in test
danielw-aws Apr 20, 2023
747e838
created testing off of a new resource
Apr 24, 2023
9581098
typo in tests
Apr 25, 2023
03b1661
removed extra check destroy function
Apr 26, 2023
af8cc81
Merge branch 'main' into HEAD
ewbankkit May 5, 2023
03582a0
Fix terrafmt errors.
ewbankkit May 5, 2023
dea064a
Fix semgrep 'ci.helper-schema-ResourceData-Set-extraneous-value-point…
ewbankkit May 5, 2023
a7315b5
Run 'make gen'.
ewbankkit May 5, 2023
9332e42
d/aws_organizations_policy: Alphabetize attributes.
ewbankkit May 5, 2023
5131fca
Fix semgrep 'ci.organizations-in-func-name'.
ewbankkit May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/15398.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-datasource
aws_organization_policy
```
76 changes: 76 additions & 0 deletions internal/service/organizations/policy_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package organizations

import (
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/organizations"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
)

// @SDKDataSource("aws_organizations_policy")
func DataSourcePolicy() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourcePolicyRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"aws_managed": {
Type: schema.TypeBool,
Computed: true,
},
"content": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"policy_id": {
Type: schema.TypeString,
Required: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).OrganizationsConn()

policyID := d.Get("policy_id").(string)
input := &organizations.DescribePolicyInput{
PolicyId: aws.String(policyID),
}

output, err := conn.DescribePolicyWithContext(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Organizations Policy (%s): %s", policyID, err)
}

d.SetId(aws.StringValue(output.Policy.PolicySummary.Id))
d.Set("arn", output.Policy.PolicySummary.Arn)
d.Set("aws_managed", output.Policy.PolicySummary.AwsManaged)
d.Set("content", output.Policy.Content)
d.Set("description", output.Policy.PolicySummary.Description)
d.Set("name", output.Policy.PolicySummary.Name)
d.Set("type", output.Policy.PolicySummary.Type)

return diags
}
69 changes: 69 additions & 0 deletions internal/service/organizations/policy_data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package organizations_test

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/organizations"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func TestAccOrganizationsPolicyDataSource_UnattachedPolicy(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_organizations_policy.test"
dataSourceName := "data.aws_organizations_policy.test"

resource.Test(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckOrganizationsAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, organizations.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccPolicyDataSourceConfig_unattachedPolicy(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(resourceName, "id", dataSourceName, "policy_id"),
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"),
resource.TestCheckResourceAttrPair(resourceName, "content", dataSourceName, "content"),
resource.TestCheckResourceAttrPair(resourceName, "type", dataSourceName, "type"),
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"),
),
},
},
})
}

func testAccPolicyDataSourceConfig_unattachedPolicy(rName string) string {
return fmt.Sprintf(`
resource "aws_organizations_organization" "test" {
feature_set = "ALL"
enabled_policy_types = "ALL"
}

resource "aws_organizations_policy" "test" {
depends_on = [aws_organizations_organization.test]

content = <<EOF
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "*",
"Resource": "*"
}
}
EOF

name = %[1]q
}

data "aws_organizations_policy" "test" {
policy_id = aws_organizations_policy.test.id
}
`, rName)
}
4 changes: 4 additions & 0 deletions internal/service/organizations/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions website/docs/d/organizations_policy.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
subcategory: "Organizations"
layout: "aws"
page_title: "AWS: aws_organizations_policy"
description: |-
Terraform data source for managing an AWS Organizations Policy.
---

# Data Source: aws_organizations_policy

Terraform data source for managing an AWS Organizations Policy.

## Example Usage

### Basic Usage

```terraform
data "aws_organizations_organization" "current" {}

data "aws_organizations_oorganizational_policies" "current" {
target_id = data.aws_organizations_organization.current.roots[0].id
filter = "SERVICE_CONTROL_POLICY"
}
data "aws_organizational_policies" "test" {
policy_id = data.aws_organizations_organizational_policies.current.policies[0].id
}
```

## Argument Reference

The following arguments are required:

* `policy_id` - (Required) The unique identifier (ID) of the policy that you want more details on. Policy id starts with a "p-" followed by 8-28 lowercase or uppercase letters, digits, and underscores.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `arn` - The Amazon Resource Name of the policy.
* `aws_managed` - Indicates if a policy is an AWS managed policy.
* `content` - The text content of the policy.
* `description` - The description of the policy.
* `name` - The friendly name of the policy.
* `type` - The type of policy values can be `SERVICE_CONTROL_POLICY | TAG_POLICY | BACKUP_POLICY | AISERVICES_OPT_OUT_POLICY`