Skip to content

Commit 30ff7df

Browse files
authored
Merge pull request #7611 from hashicorp/b-iam-policy-document-fixes
provider/aws: Fix data.aws_iam_policy_document IDs
2 parents 821d9d8 + 28438da commit 30ff7df

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

builtin/providers/aws/data_source_aws_iam_policy_document.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ func dataSourceAwsIamPolicyDocument() *schema.Resource {
2424
Read: dataSourceAwsIamPolicyDocumentRead,
2525

2626
Schema: map[string]*schema.Schema{
27-
"id": &schema.Schema{
27+
"policy_id": {
2828
Type: schema.TypeString,
2929
Optional: true,
3030
},
31-
"statement": &schema.Schema{
32-
Type: schema.TypeSet,
31+
"statement": {
32+
Type: schema.TypeList,
3333
Required: true,
3434
Elem: &schema.Resource{
3535
Schema: map[string]*schema.Schema{
36-
"id": &schema.Schema{
36+
"sid": {
3737
Type: schema.TypeString,
3838
Optional: true,
3939
},
40-
"effect": &schema.Schema{
40+
"effect": {
4141
Type: schema.TypeString,
4242
Optional: true,
4343
Default: "Allow",
@@ -48,20 +48,20 @@ func dataSourceAwsIamPolicyDocument() *schema.Resource {
4848
"not_resources": setOfString,
4949
"principals": dataSourceAwsIamPolicyPrincipalSchema(),
5050
"not_principals": dataSourceAwsIamPolicyPrincipalSchema(),
51-
"condition": &schema.Schema{
51+
"condition": {
5252
Type: schema.TypeSet,
5353
Optional: true,
5454
Elem: &schema.Resource{
5555
Schema: map[string]*schema.Schema{
56-
"test": &schema.Schema{
56+
"test": {
5757
Type: schema.TypeString,
5858
Required: true,
5959
},
60-
"variable": &schema.Schema{
60+
"variable": {
6161
Type: schema.TypeString,
6262
Required: true,
6363
},
64-
"values": &schema.Schema{
64+
"values": {
6565
Type: schema.TypeSet,
6666
Required: true,
6767
Elem: &schema.Schema{
@@ -74,7 +74,7 @@ func dataSourceAwsIamPolicyDocument() *schema.Resource {
7474
},
7575
},
7676
},
77-
"json": &schema.Schema{
77+
"json": {
7878
Type: schema.TypeString,
7979
Computed: true,
8080
},
@@ -87,11 +87,11 @@ func dataSourceAwsIamPolicyDocumentRead(d *schema.ResourceData, meta interface{}
8787
Version: "2012-10-17",
8888
}
8989

90-
if policyId, hasPolicyId := d.GetOk("id"); hasPolicyId {
90+
if policyId, hasPolicyId := d.GetOk("policy_id"); hasPolicyId {
9191
doc.Id = policyId.(string)
9292
}
9393

94-
var cfgStmts = d.Get("statement").(*schema.Set).List()
94+
var cfgStmts = d.Get("statement").([]interface{})
9595
stmts := make([]*IAMPolicyStatement, len(cfgStmts))
9696
doc.Statements = stmts
9797
for i, stmtI := range cfgStmts {
@@ -100,6 +100,10 @@ func dataSourceAwsIamPolicyDocumentRead(d *schema.ResourceData, meta interface{}
100100
Effect: cfgStmt["effect"].(string),
101101
}
102102

103+
if sid, ok := cfgStmt["sid"]; ok {
104+
stmt.Sid = sid.(string)
105+
}
106+
103107
if actions := cfgStmt["actions"].(*schema.Set).List(); len(actions) > 0 {
104108
stmt.Actions = iamPolicyDecodeConfigStringList(actions)
105109
}

builtin/providers/aws/data_source_aws_iam_policy_document_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestAccAWSIAMPolicyDocument(t *testing.T) {
1616
PreCheck: func() { testAccPreCheck(t) },
1717
Providers: testAccProviders,
1818
Steps: []resource.TestStep{
19-
resource.TestStep{
19+
{
2020
Config: testAccAWSIAMPolicyDocumentConfig,
2121
Check: resource.ComposeTestCheckFunc(
2222
testAccCheckStateValue(
@@ -52,7 +52,9 @@ func testAccCheckStateValue(id, name, value string) resource.TestCheckFunc {
5252

5353
var testAccAWSIAMPolicyDocumentConfig = `
5454
data "aws_iam_policy_document" "test" {
55+
policy_id = "policy_id"
5556
statement {
57+
sid = "1"
5658
actions = [
5759
"s3:ListAllMyBuckets",
5860
"s3:GetBucketLocation",
@@ -110,8 +112,10 @@ data "aws_iam_policy_document" "test" {
110112

111113
var testAccAWSIAMPolicyDocumentExpectedJSON = `{
112114
"Version": "2012-10-17",
115+
"Id": "policy_id",
113116
"Statement": [
114117
{
118+
"Sid": "1",
115119
"Effect": "Allow",
116120
"Action": [
117121
"s3:GetBucketLocation",

builtin/providers/aws/iam_policy_model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
)
66

77
type IAMPolicyDoc struct {
8-
Id string `json:",omitempty"`
98
Version string `json:",omitempty"`
9+
Id string `json:",omitempty"`
1010
Statements []*IAMPolicyStatement `json:"Statement"`
1111
}
1212

website/source/docs/providers/aws/d/iam_policy_document.html.markdown

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ such as the `aws_iam_policy` resource.
1717
```
1818
data "aws_iam_policy_document" "example" {
1919
statement {
20+
sid = "1"
2021
actions = [
2122
"s3:ListAllMyBuckets",
2223
"s3:GetBucketLocation",
@@ -71,14 +72,14 @@ valid to use literal JSON strings within your configuration, or to use the
7172

7273
The following arguments are supported:
7374

74-
* `id` (Optional) - An ID for the policy document.
75+
* `policy_id` (Optional) - An ID for the policy document.
7576
* `statement` (Required) - A nested configuration block (described below)
7677
configuring one *statement* to be included in the policy document.
7778

7879
Each document configuration must have one or more `statement` blocks, which
7980
each accept the following arguments:
8081

81-
* `id` (Optional) - An ID for the policy statement.
82+
* `sid` (Optional) - An ID for the policy statement.
8283
* `effect` (Optional) - Either "Allow" or "Deny", to specify whether this
8384
statement allows or denies the given actions. The default is "Allow".
8485
* `actions` (Optional) - A list of actions that this statement either allows

0 commit comments

Comments
 (0)