Skip to content

Commit

Permalink
Fix testcase failure and added missing code after rebase. Incorporate…
Browse files Browse the repository at this point in the history
…d review comments
  • Loading branch information
Rajesh-Pirati committed May 17, 2022
1 parent 9fc8110 commit 0e06c9e
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func dataSourceIBMIAMAccessGroupPolicyRead(d *schema.ResourceData, meta interfac
}
d.SetId(accessGroupId)

if resp.Headers["Transaction-Id"][0] != "" {
if len(resp.Headers["Transaction-Id"]) > 0 && resp.Headers["Transaction-Id"][0] != "" {
d.Set("transaction_id", resp.Headers["Transaction-Id"][0])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func dataSourceIBMIAMAuthorizationPoliciesRead(d *schema.ResourceData, meta inte
d.SetId(time.Now().UTC().String())
d.Set("account_id", accountID)

if resp.Headers["Transaction-Id"][0] != "" {
if len(resp.Headers["Transaction-Id"]) > 0 && resp.Headers["Transaction-Id"][0] != "" {
d.Set("transaction_id", resp.Headers["Transaction-Id"][0])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func dataSourceIBMIAMServicePolicyRead(d *schema.ResourceData, meta interface{})
iamID := v.(string)
d.SetId(iamID)
}
if resp.Headers["Transaction-Id"][0] != "" {
if len(resp.Headers["Transaction-Id"]) > 0 && resp.Headers["Transaction-Id"][0] != "" {
d.Set("transaction_id", resp.Headers["Transaction-Id"][0])
}
d.Set("policies", servicePolicies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func dataSourceIBMIAMTrustedProfilePolicyRead(d *schema.ResourceData, meta inter
iamID := v.(string)
d.SetId(iamID)
}
if resp.Headers["Transaction-Id"][0] != "" {
if len(resp.Headers["Transaction-Id"]) > 0 && resp.Headers["Transaction-Id"][0] != "" {
d.Set("transaction_id", resp.Headers["Transaction-Id"][0])
}
d.Set("policies", profilePolicies)
Expand Down
6 changes: 1 addition & 5 deletions ibm/service/iampolicy/data_source_ibm_iam_user_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ func dataSourceIBMIAMUserPolicyRead(d *schema.ResourceData, meta interface{}) er
Type: core.StringPtr("access"),
}

if transactionID, ok := d.GetOk("transaction_id"); ok {
listPoliciesOptions.SetHeaders(map[string]string{"Transaction-Id": transactionID.(string)})
}

if v, ok := d.GetOk("sort"); ok {
listPoliciesOptions.Sort = core.StringPtr(v.(string))
}
Expand Down Expand Up @@ -193,7 +189,7 @@ func dataSourceIBMIAMUserPolicyRead(d *schema.ResourceData, meta interface{}) er
}
userPolicies = append(userPolicies, p)
}
if resp.Headers["Transaction-Id"][0] != "" {
if len(resp.Headers["Transaction-Id"]) > 0 && resp.Headers["Transaction-Id"][0] != "" {
d.Set("transaction_id", resp.Headers["Transaction-Id"][0])
}
d.SetId(userEmail)
Expand Down
4 changes: 4 additions & 0 deletions ibm/service/iampolicy/resource_ibm_iam_access_group_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ func resourceIBMIAMAccessGroupPolicyRead(d *schema.ResourceData, meta interface{
d.Set("description", *accessGroupPolicy.Description)
}

if len(res.Headers["Transaction-Id"]) > 0 && res.Headers["Transaction-Id"][0] != "" {
d.Set("transaction_id", res.Headers["Transaction-Id"][0])
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ func testAccCheckIBMIAMAccessGroupPolicyServiceSpecificRoles(name string) string
resource "ibm_iam_access_group_policy" "policy" {
access_group_id = ibm_iam_access_group.accgrp.id
roles = ["Satellite Link Source and Endpoint Controller"]
roles = ["Satellite Link Administrator"]
resource_attributes {
name = "resource"
value = "test*"
Expand Down
23 changes: 23 additions & 0 deletions ibm/service/iampolicy/resource_ibm_iam_authorization_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ func ResourceIBMIAMAuthorizationPolicy() *schema.Resource {
Optional: true,
Description: "Description of the Policy",
},

"transaction_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Set transactionID for debug",
},
},
}
}
Expand Down Expand Up @@ -347,6 +354,10 @@ func resourceIBMIAMAuthorizationPolicyCreate(d *schema.ResourceData, meta interf
createPolicyOptions.Description = &des
}

if transactionID, ok := d.GetOk("transaction_id"); ok {
createPolicyOptions.SetHeaders(map[string]string{"Transaction-Id": transactionID.(string)})
}

authPolicy, resp, err := iampapClient.CreatePolicy(createPolicyOptions)
if err != nil {
return fmt.Errorf("[ERROR] Error creating authorization policy: %s %s", err, resp)
Expand All @@ -368,6 +379,10 @@ func resourceIBMIAMAuthorizationPolicyRead(d *schema.ResourceData, meta interfac
PolicyID: core.StringPtr(d.Id()),
}

if transactionID, ok := d.GetOk("transaction_id"); ok {
getPolicyOptions.SetHeaders(map[string]string{"Transaction-Id": transactionID.(string)})
}

authorizationPolicy, resp, err := iampapClient.GetPolicy(getPolicyOptions)
if err != nil {
return fmt.Errorf("[ERROR] Error retrieving authorizationPolicy: %s %s", err, resp)
Expand All @@ -379,6 +394,9 @@ func resourceIBMIAMAuthorizationPolicyRead(d *schema.ResourceData, meta interfac
if authorizationPolicy.Description != nil {
d.Set("description", *authorizationPolicy.Description)
}
if len(resp.Headers["Transaction-Id"]) > 0 && resp.Headers["Transaction-Id"][0] != "" {
d.Set("transaction_id", resp.Headers["Transaction-Id"][0])
}
d.Set("roles", roles)
source := authorizationPolicy.Subjects[0]
target := authorizationPolicy.Resources[0]
Expand Down Expand Up @@ -415,6 +433,11 @@ func resourceIBMIAMAuthorizationPolicyDelete(d *schema.ResourceData, meta interf
deletePolicyOptions := &iampolicymanagementv1.DeletePolicyOptions{
PolicyID: core.StringPtr(authorizationPolicyID),
}

if transactionID, ok := d.GetOk("transaction_id"); ok {
deletePolicyOptions.SetHeaders(map[string]string{"Transaction-Id": transactionID.(string)})
}

resp, err := iampapClient.DeletePolicy(deletePolicyOptions)
if err != nil {
log.Printf(
Expand Down
6 changes: 5 additions & 1 deletion ibm/service/iampolicy/resource_ibm_iam_service_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ func resourceIBMIAMServicePolicyCreate(d *schema.ResourceData, meta interface{})
*servicePolicy.ID,
)

if transactionID, ok := d.GetOk("transaction_id"); ok {
getPolicyOptions.SetHeaders(map[string]string{"Transaction-Id": transactionID.(string)})
}

err = resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
policy, res, err := iamPolicyManagementClient.GetPolicy(getPolicyOptions)
Expand Down Expand Up @@ -397,7 +401,7 @@ func resourceIBMIAMServicePolicyRead(d *schema.ResourceData, meta interface{}) e
d.Set("description", *servicePolicy.Description)
}

if res.Headers["Transaction-Id"][0] != "" {
if len(res.Headers["Transaction-Id"]) > 0 && res.Headers["Transaction-Id"][0] != "" {
d.Set("transaction_id", res.Headers["Transaction-Id"][0])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ func resourceIBMIAMTrustedProfilePolicyCreate(d *schema.ResourceData, meta inter
*trustedProfilePolicy.ID,
)

if transactionID, ok := d.GetOk("transaction_id"); ok {
getPolicyOptions.SetHeaders(map[string]string{"Transaction-Id": transactionID.(string)})
}

err = resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
policy, res, err := iamPolicyManagementClient.GetPolicy(getPolicyOptions)
Expand Down Expand Up @@ -395,7 +399,7 @@ func resourceIBMIAMTrustedProfilePolicyRead(d *schema.ResourceData, meta interfa
if trustedProfilePolicy.Description != nil {
d.Set("description", *trustedProfilePolicy.Description)
}
if res.Headers["Transaction-Id"][0] != "" {
if len(res.Headers["Transaction-Id"]) > 0 && res.Headers["Transaction-Id"][0] != "" {
d.Set("transaction_id", res.Headers["Transaction-Id"][0])
}

Expand Down Expand Up @@ -498,6 +502,10 @@ func resourceIBMIAMTrustedProfilePolicyUpdate(d *schema.ResourceData, meta inter
updatePolicyOptions.Description = &des
}

if transactionID, ok := d.GetOk("transaction_id"); ok {
updatePolicyOptions.SetHeaders(map[string]string{"Transaction-Id": transactionID.(string)})
}

_, resp, err := iamPolicyManagementClient.UpdatePolicy(updatePolicyOptions)
if err != nil {
return fmt.Errorf("[ERROR] Error updating trusted profile policy: %s: %s", err, resp)
Expand Down
10 changes: 5 additions & 5 deletions ibm/service/iampolicy/resource_ibm_iam_user_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ func resourceIBMIAMUserPolicyCreate(d *schema.ResourceData, meta interface{}) er
PolicyID: userPolicy.ID,
}

if transactionID, ok := d.GetOk("transaction_id"); ok {
getPolicyOptions.SetHeaders(map[string]string{"Transaction-Id": transactionID.(string)})
}

err = resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
policy, res, err := iamPolicyManagementClient.GetPolicy(getPolicyOptions)
Expand Down Expand Up @@ -301,10 +305,6 @@ func resourceIBMIAMUserPolicyRead(d *schema.ResourceData, meta interface{}) erro
userEmail := parts[0]
userPolicyID := parts[1]

if err != nil {
return err
}

getPolicyOptions := &iampolicymanagementv1.GetPolicyOptions{
PolicyID: core.StringPtr(userPolicyID),
}
Expand Down Expand Up @@ -363,7 +363,7 @@ func resourceIBMIAMUserPolicyRead(d *schema.ResourceData, meta interface{}) erro
if userPolicy.Description != nil {
d.Set("description", *userPolicy.Description)
}
if res.Headers["Transaction-Id"][0] != "" {
if len(res.Headers["Transaction-Id"]) > 0 && res.Headers["Transaction-Id"][0] != "" {
d.Set("transaction_id", res.Headers["Transaction-Id"][0])
}

Expand Down
1 change: 1 addition & 0 deletions website/docs/d/iam_access_group_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ resource "ibm_iam_access_group_policy" "policy" {
data "ibm_iam_access_group_policy" "policy" {
access_group_id = ibm_iam_access_group_policy.policy.access_group_id
transaction_id = "terrformAccessGroupPolicy"
}
```
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/iam_service_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ resource "ibm_iam_service_policy" "policy" {
data "ibm_iam_service_policy" "testacc_ds_service_policy" {
iam_service_id = ibm_iam_service_policy.policy.iam_service_id
transaction_id = "terrformServicePolicy"
}
```
Expand All @@ -37,6 +38,7 @@ Review the argument references that you can specify for your data source.
- `iam_service_id` - (Required, String) The UUID of the service ID.
- `iam_id` - (Optional, String) IAM ID of the service ID. One of the `iam_service_id` or `iam_id` is required argument. You can use to get cross account service ID policy.
- `sort`- Optional - (String) The single field sort query for policies.
- `transaction_id`- (Optional, String) The TransactionID can be passed to your request for the tracking calls.

## Attribute reference

Expand Down
1 change: 1 addition & 0 deletions website/docs/d/iam_trusted_profile_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ resource "ibm_iam_trusted_profile_policy" "policy" {
data "ibm_iam_trusted_profile_policy" "policy" {
profile_id = ibm_iam_trusted_profile_policy.policy.profile_id
transaction_id = "terrformTrustedPolicy"
}
```
Expand Down
1 change: 0 additions & 1 deletion website/docs/r/iam_access_group_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ Review the argument references that you can specify for your resource.
- `value` - (Required, String) The value of an access management tag.
- `operator` - (Optional, String) Operator of an attribute. The default value is `stringEquals`.

- `tags` - (Optional, Array of strings) A list of tags that you want to add to the access group policy. **Note** `Tags` are managed locally and not stored on the IBM Cloud Service Endpoint at this moment.
- `transaction_id`- (Optional, String) The TransactionID can be passed to your request for tracking the calls.

## Attribute reference
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/iam_service_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Review the argument references that you can specify for your resource.
- `name` - (Required, String) The key of an access management tag.
- `value` - (Required, String) The value of an access management tag.
- `operator` - (Optional, String) Operator of an attribute. The default value is `stringEquals`.
- `tags` - (Optional, List of Strings) A list of tags with the service policy instance. **Note** Tags are managed locally and not stored in the IBM Cloud service endpoint at this moment.
- `transaction_id`- (Optional, String) The TransactionID can be passed to your request for tracking the calls.

## Attribute reference
Expand Down
1 change: 0 additions & 1 deletion website/docs/r/iam_trusted_profile_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ Review the argument references that you can specify for your resource.
- `value` - (Required, String) The value of an access management tag.
- `operator` - (Optional, String) Operator of an attribute. The default value is `stringEquals`.

- `tags` - (Optional, List of Strings) A list of tags with the trusted profile policy instance. **Note** Tags are managed locally and not stored in the IBM Cloud service endpoint at this moment.
- `transaction_id`- (Optional, String) The TransactionID can be passed to your request for tracking the calls.

## Attribute reference
Expand Down
1 change: 0 additions & 1 deletion website/docs/r/iam_user_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ Review the argument references that you can specify for your resource.
- `value` - (Required, String) The value of an access management tag.
- `operator` - (Optional, String) Operator of an attribute. The default value is `stringEquals`.

- `tags` (Optional, Array of Strings) A list of tags that are associated with the service policy instance. **Note** `Tags` are managed locally and not stored on the IBM Cloud Service Endpoint at this moment.
- `transaction_id`- (Optional, String) The TransactionID can be passed to your request for tracking the calls.

## Attribute reference
Expand Down

0 comments on commit 0e06c9e

Please sign in to comment.