Skip to content

Commit 866cacd

Browse files
author
ccushing
committed
Policy resource version_date bug fix
* converts field to string to obivate date format disagreement * add test case * unrelated addition to policy example for usage clarification
1 parent e294002 commit 866cacd

File tree

7 files changed

+28
-9
lines changed

7 files changed

+28
-9
lines changed

docs/examples/iam/policy/policy.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ resource "oci_identity_policy" "t" {
3131
name = "TFExamplePolicy"
3232
description = "automated test policy"
3333
compartment_id = "${oci_identity_compartment.t.id}"
34-
statements = ["Allow group ${oci_identity_group.t.name} to read instances in compartment ${oci_identity_compartment.t.name}"]
34+
statements = ["Allow group ${oci_identity_group.t.name} to inspect instances in compartment ${oci_identity_compartment.t.name}",
35+
"Allow group ${oci_identity_group.t.name} to read instances in compartment ${oci_identity_compartment.t.name}"]
3536
}
3637

3738
data "oci_identity_policies" "p" {
3839
compartment_id = "${oci_identity_compartment.t.id}"
40+
filter {
41+
name = "name"
42+
values = ["TFExamplePolicy"]
43+
}
3944
}
4045

4146
output "policy" {

provider/identity_policies_data_source.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func (s *IdentityPoliciesDataSourceCrud) SetData() {
113113

114114
policy["time_created"] = r.TimeCreated.String()
115115

116+
// TODO: see comment "pending spec/sdk versionDate solution" in identity_policy_resource.go
116117
if r.VersionDate != nil {
117118
policy["version_date"] = *r.VersionDate
118119
}

provider/identity_policy_resource.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010

1111
"github.com/hashicorp/terraform/helper/schema"
12-
oci_common "github.com/oracle/oci-go-sdk/common"
1312
oci_identity "github.com/oracle/oci-go-sdk/identity"
1413

1514
"github.com/oracle/terraform-provider-oci/crud"
@@ -195,9 +194,19 @@ func (s *PolicyResourceCrud) Create() error {
195194
}
196195

197196
if versionDate, ok := s.D.GetOkExists("version_date"); ok {
198-
tmp := versionDate.(oci_common.SDKTime)
197+
// one off change to go sdk policy.go:57 create_policy_details.go:36 and update_policy_details.go:29 to treat this as a string
198+
tmp := versionDate.(string)
199199
request.VersionDate = &tmp
200200
}
201+
// TODO: pending spec/sdk versionDate solution to support basic `date` types, some form of this code may be required here and in `Update()` below
202+
//if versionDate, ok := s.D.GetOkExists("version_date"); ok {
203+
// const scheme = `2006-01-02`
204+
// tmp, err := time.Parse(scheme, versionDate.(string))
205+
// if err != nil {
206+
// return err
207+
// }
208+
// request.VersionDate = &oci_common.SDKTime{Time: tmp}
209+
//}
201210

202211
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "identity")
203212

@@ -259,8 +268,9 @@ func (s *PolicyResourceCrud) Update() error {
259268
request.Statements = tmp
260269
}
261270

271+
// TODO: see comment "pending spec/sdk versionDate solution" above
262272
if versionDate, ok := s.D.GetOkExists("version_date"); ok {
263-
tmp := versionDate.(oci_common.SDKTime)
273+
tmp := versionDate.(string)
264274
request.VersionDate = &tmp
265275
}
266276

provider/identity_policy_resource_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (s *ResourceIdentityPolicyTestSuite) TestAccResourceIdentityPolicy_basic()
5353
compartment_id = "${oci_identity_compartment.t.id}"
5454
name = "p1-{{.token}}"
5555
description = "automated test policy"
56+
version_date = "2018-04-17"
5657
statements = ["Allow group ${oci_identity_group.t.name} to read instances in compartment ${oci_identity_compartment.t.name}"]
5758
}`, nil),
5859
Check: resource.ComposeTestCheckFunc(
@@ -66,7 +67,7 @@ func (s *ResourceIdentityPolicyTestSuite) TestAccResourceIdentityPolicy_basic()
6667
resource.TestCheckResourceAttr(s.ResourceName, "description", "automated test policy"),
6768
resource.TestCheckResourceAttr(s.ResourceName, "statements.#", "1"),
6869
resource.TestCheckResourceAttr(s.ResourceName, "state", string(identity.PolicyLifecycleStateActive)),
69-
resource.TestCheckNoResourceAttr(s.ResourceName, "version_date"),
70+
resource.TestCheckResourceAttr(s.ResourceName, "version_date", "2018-04-17"),
7071
resource.TestCheckNoResourceAttr(s.ResourceName, "inactive_state"),
7172
func(s *terraform.State) (err error) {
7273
policyHash, err = fromInstanceState(s, "oci_identity_policy.p", "policyHash")
@@ -81,14 +82,16 @@ func (s *ResourceIdentityPolicyTestSuite) TestAccResourceIdentityPolicy_basic()
8182
compartment_id = "${oci_identity_compartment.t.id}"
8283
name = "p2-{{.token}}"
8384
description = "automated test policy (updated)"
85+
version_date = "2018-04-18"
8486
statements = [
85-
"Allow group ${oci_identity_group.t.name} to read instances in compartment ${oci_identity_compartment.t.name}",
87+
"Allow group ${oci_identity_group.t.name} to inspect instances in compartment ${oci_identity_compartment.t.name}",
8688
"Allow group ${oci_identity_group.t.name} to read instances in compartment ${oci_identity_compartment.t.name}"
8789
]
8890
}`, nil),
8991
Check: resource.ComposeTestCheckFunc(
9092
resource.TestCheckResourceAttr(s.ResourceName, "name", "p2-"+s.Token),
9193
resource.TestCheckResourceAttr(s.ResourceName, "description", "automated test policy (updated)"),
94+
resource.TestCheckResourceAttr(s.ResourceName, "version_date", "2018-04-18"),
9295
resource.TestCheckResourceAttr(s.ResourceName, "statements.#", "2"),
9396
func(s *terraform.State) (err error) {
9497
newHash, err := fromInstanceState(s, "oci_identity_policy.p", "policyHash")

vendor/github.com/oracle/oci-go-sdk/identity/create_policy_details.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/oracle/oci-go-sdk/identity/policy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/oracle/oci-go-sdk/identity/update_policy_details.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)