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

IAM Policy Assignment: S2S Policy Assignments #5499

Merged
merged 13 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ require (
github.com/IBM/event-notifications-go-admin-sdk v0.6.1
github.com/IBM/eventstreams-go-sdk v1.4.0
github.com/IBM/go-sdk-core/v3 v3.2.4
github.com/IBM/go-sdk-core/v5 v5.17.3
github.com/IBM/go-sdk-core/v5 v5.17.4
github.com/IBM/ibm-cos-sdk-go v1.10.3
github.com/IBM/ibm-cos-sdk-go-config/v2 v2.1.0
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20211109141421-a4b61b05f7d1
github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta
github.com/IBM/keyprotect-go-client v0.14.0
github.com/IBM/logs-go-sdk v0.3.0
github.com/IBM/networking-go-sdk v0.47.1
github.com/IBM/platform-services-go-sdk v0.62.11
github.com/IBM/project-go-sdk v0.3.5
github.com/IBM/platform-services-go-sdk v0.64.3
github.com/IBM/project-go-sdk v0.3.4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rolling back to previous version shd n't override other services go sdk's verison

github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
github.com/IBM/scc-go-sdk/v5 v5.1.6
github.com/IBM/schematics-go-sdk v0.2.3
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ github.com/IBM/go-sdk-core/v5 v5.9.5/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV
github.com/IBM/go-sdk-core/v5 v5.10.2/go.mod h1:WZPFasUzsKab/2mzt29xPcfruSk5js2ywAPwW4VJjdI=
github.com/IBM/go-sdk-core/v5 v5.17.3 h1:CZSVCKzhQc/hRQZOtuEmi9dlNtWMnxJvOsPtQKP7cZ4=
github.com/IBM/go-sdk-core/v5 v5.17.3/go.mod h1:GatGZpxlo1KaxiRN6E10/rNgWtUtx1hN/GoHSCaSPKA=
github.com/IBM/go-sdk-core/v5 v5.17.4 h1:VGb9+mRrnS2HpHZFM5hy4J6ppIWnwNrw0G+tLSgcJLc=
github.com/IBM/go-sdk-core/v5 v5.17.4/go.mod h1:KsAAI7eStAWwQa4F96MLy+whYSh39JzNjklZRbN/8ns=
github.com/IBM/ibm-cos-sdk-go v1.10.3 h1:YfZSLqMiCrqDPbr3r+amY2sicIXlrd+3L5pok6QRXIQ=
github.com/IBM/ibm-cos-sdk-go v1.10.3/go.mod h1:T9x7pC47DUd5jD/TMFzlvly39P6EdW5wOemA78XEo2g=
github.com/IBM/ibm-cos-sdk-go-config/v2 v2.1.0 h1:U7EmXSfv7jtugRpTpOkPUmgS/xiNKtGfKVH3BGyC1hg=
Expand All @@ -162,8 +164,10 @@ github.com/IBM/networking-go-sdk v0.47.1 h1:Zqqu9CrZ86jkjMyuIJtBLLOE0D7YtirxnlFy
github.com/IBM/networking-go-sdk v0.47.1/go.mod h1:yF4XStkswGgVwQVqPUk6b4YTP0dVap52q8HDYwY4gXQ=
github.com/IBM/platform-services-go-sdk v0.62.11 h1:EGsiY90bM9M9sSdBVgpsX4QK1z99JZzedVDlrY2gzmc=
github.com/IBM/platform-services-go-sdk v0.62.11/go.mod h1:M26dloj9C48k9AjfMcKGsgH/acEjaUvxjVS8z41Q8dg=
github.com/IBM/project-go-sdk v0.3.5 h1:L+YClFUa14foS0B/hOOY9n7sIdsT5/XQicnXOyJSpyM=
github.com/IBM/project-go-sdk v0.3.5/go.mod h1:FOJM9ihQV3EEAY6YigcWiTNfVCThtdY8bLC/nhQHFvo=
github.com/IBM/platform-services-go-sdk v0.64.3 h1:AKDrLXjybG09i5MyqptY0UpyejeiYrTbdylDC7FQM1k=
github.com/IBM/platform-services-go-sdk v0.64.3/go.mod h1:6rYd3stLSnotYmZlxclw45EJPaQuLmh5f7c+Mg7rOg4=
github.com/IBM/project-go-sdk v0.3.4 h1:VJqGdrWZLlb+f5/fH5mcSpt8t0QoYEq4QgFWVnn8mCs=
github.com/IBM/project-go-sdk v0.3.4/go.mod h1:FOJM9ihQV3EEAY6YigcWiTNfVCThtdY8bLC/nhQHFvo=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5 h1:NPUhkoOCRuv3OFWt19PmwjXGGTKlvmbuPg9fUrBUNe4=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5/go.mod h1:b07XHUVh0XYnQE9s2mqgjYST1h9buaQNqN4EcKhOsX0=
github.com/IBM/sarama v1.41.2 h1:ZDBZfGPHAD4uuAtSv4U22fRZBgst0eEwGFzLj0fb85c=
Expand Down
54 changes: 0 additions & 54 deletions ibm/service/iampolicy/data_source_ibm_iam_policy_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,6 @@ func dataSourceIBMIAMPolicyAssignmentRead(context context.Context, d *schema.Res
return diag.FromErr(fmt.Errorf("error setting template: %s", err))
}
}
optionsMap, err := ResourceIBMPolicyAssignmentPolicyAssignmentV1OptionsToMap(policyAssignmentRecord.Options)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove options also from Schema

if err != nil {
return diag.FromErr(err)
}
if err = d.Set("options", []map[string]interface{}{optionsMap}); err != nil {
return diag.FromErr(fmt.Errorf("error setting options: %s", err))
}

if err = d.Set("href", policyAssignmentRecord.Href); err != nil {
return diag.FromErr(fmt.Errorf("error setting href: %s", err))
Expand All @@ -317,18 +310,10 @@ func dataSourceIBMIAMPolicyAssignmentRead(context context.Context, d *schema.Res
return diag.FromErr(fmt.Errorf("error setting created_at: %s", err))
}

if err = d.Set("created_by_id", policyAssignmentRecord.CreatedByID); err != nil {
return diag.FromErr(fmt.Errorf("error setting created_by_id: %s", err))
}

if err = d.Set("last_modified_at", flex.DateTimeToString(policyAssignmentRecord.LastModifiedAt)); err != nil {
return diag.FromErr(fmt.Errorf("error setting last_modified_at: %s", err))
}

if err = d.Set("last_modified_by_id", policyAssignmentRecord.LastModifiedByID); err != nil {
return diag.FromErr(fmt.Errorf("error setting last_modified_by_id: %s", err))
}

if err = d.Set("account_id", policyAssignmentRecord.AccountID); err != nil {
return diag.FromErr(fmt.Errorf("error setting account_id: %s", err))
}
Expand Down Expand Up @@ -474,45 +459,6 @@ func ResourceIBMPolicyAssignmentPolicyAssignmentV1ResourcesToMap(model *iampolic
}
return modelMap, nil
}
func ResourceIBMPolicyAssignmentPolicyAssignmentV1OptionsRootTemplateToMap(model *iampolicymanagementv1.PolicyAssignmentV1OptionsRootTemplate) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.ID != nil {
modelMap["id"] = *model.ID
}
if model.Version != nil {
modelMap["version"] = *model.Version
}
return modelMap, nil
}

func ResourceIBMPolicyAssignmentPolicyAssignmentV1OptionsRootToMap(model *iampolicymanagementv1.PolicyAssignmentV1OptionsRoot) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.RequesterID != nil {
modelMap["requester_id"] = *model.RequesterID
}
if model.AssignmentID != nil {
modelMap["assignment_id"] = *model.AssignmentID
}
if model.Template != nil {
templateMap, err := ResourceIBMPolicyAssignmentPolicyAssignmentV1OptionsRootTemplateToMap(model.Template)
if err != nil {
return modelMap, err
}
modelMap["template"] = []map[string]interface{}{templateMap}
}
return modelMap, nil
}

func ResourceIBMPolicyAssignmentPolicyAssignmentV1OptionsToMap(model *iampolicymanagementv1.PolicyAssignmentV1Options) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
rootMap, err := ResourceIBMPolicyAssignmentPolicyAssignmentV1OptionsRootToMap(model.Root)
if err != nil {
return modelMap, err
}
modelMap["root"] = []map[string]interface{}{rootMap}
return modelMap, nil
}

func DataSourceIBMPolicyAssignmentPolicyAssignmentV1Subject(model *iampolicymanagementv1.GetPolicyAssignmentResponseSubject) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.ID != nil {
Expand Down
73 changes: 1 addition & 72 deletions ibm/service/iampolicy/data_source_ibm_iam_policy_assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func ResourceIBMPolicyAssignmentAssignmentTargetDetailsToMap(model *iampolicyman
func ResourceIBMPolicyAssignmentResourceTargetDetailsToMap(model *iampolicymanagementv1.AssignmentTargetDetails) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.Type != nil {
modelMap["version"] = *model.Type
modelMap["type"] = *model.Type
}
if model.ID != nil {
modelMap["id"] = *model.ID
Expand All @@ -394,13 +394,6 @@ func DataSourceIBMPolicyAssignmentPolicyTemplateAssignmentItemsToMap(model iampo
}
modelMap["target"] = targetMap
}
if model.Options != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove options from Schema

optionsMap, err := DataSourceIBMPolicyAssignmentPolicyAssignmentV1OptionsToMap(model.Options)
if err != nil {
return modelMap, err
}
modelMap["options"] = []map[string]interface{}{optionsMap}
}
if model.ID != nil {
modelMap["id"] = *model.ID
}
Expand Down Expand Up @@ -476,45 +469,6 @@ func DataSourceIBMPolicyAssignmentAssignmentTargetDetailsToMap(model *iampolicym
return modelMap, nil
}

func DataSourceIBMPolicyAssignmentPolicyAssignmentV1OptionsToMap(model *iampolicymanagementv1.PolicyAssignmentV1Options) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
rootMap, err := DataSourceIBMPolicyAssignmentPolicyAssignmentV1OptionsRootToMap(model.Root)
if err != nil {
return modelMap, err
}
modelMap["root"] = []map[string]interface{}{rootMap}
return modelMap, nil
}

func DataSourceIBMPolicyAssignmentPolicyAssignmentV1OptionsRootToMap(model *iampolicymanagementv1.PolicyAssignmentV1OptionsRoot) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.RequesterID != nil {
modelMap["requester_id"] = *model.RequesterID
}
if model.AssignmentID != nil {
modelMap["assignment_id"] = *model.AssignmentID
}
if model.Template != nil {
templateMap, err := DataSourceIBMPolicyAssignmentPolicyAssignmentV1OptionsRootTemplateToMap(model.Template)
if err != nil {
return modelMap, err
}
modelMap["template"] = []map[string]interface{}{templateMap}
}
return modelMap, nil
}

func DataSourceIBMPolicyAssignmentPolicyAssignmentV1OptionsRootTemplateToMap(model *iampolicymanagementv1.PolicyAssignmentV1OptionsRootTemplate) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.ID != nil {
modelMap["id"] = *model.ID
}
if model.Version != nil {
modelMap["version"] = *model.Version
}
return modelMap, nil
}

func DataSourceIBMPolicyAssignmentPolicyAssignmentV1ResourcesToMap(model *iampolicymanagementv1.PolicyAssignmentV1Resources) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.Target != nil {
Expand Down Expand Up @@ -665,17 +619,6 @@ func DataSourceIBMPolicyAssignmentPolicyTemplateAssignmentItemsPolicyAssignmentT
if model.Target != nil {
modelMap["target"] = *model.Target
}
if model.Options != nil {
options := []map[string]interface{}{}
for _, optionsItem := range model.Options {
optionsItemMap, err := DataSourceIBMPolicyAssignmentPolicyAssignmentOptionsToMap(&optionsItem)
if err != nil {
return modelMap, err
}
options = append(options, optionsItemMap)
}
modelMap["options"] = options
}
if model.ID != nil {
modelMap["id"] = *model.ID
}
Expand Down Expand Up @@ -714,20 +657,6 @@ func DataSourceIBMPolicyAssignmentPolicyTemplateAssignmentItemsPolicyAssignmentT
return modelMap, nil
}

func DataSourceIBMPolicyAssignmentPolicyAssignmentOptionsToMap(model *iampolicymanagementv1.PolicyAssignmentOptions) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["subject_type"] = *model.SubjectType
modelMap["subject_id"] = *model.SubjectID
modelMap["root_requester_id"] = *model.RootRequesterID
if model.RootTemplateID != nil {
modelMap["root_template_id"] = *model.RootTemplateID
}
if model.RootTemplateVersion != nil {
modelMap["root_template_version"] = *model.RootTemplateVersion
}
return modelMap, nil
}

func DataSourceIBMPolicyAssignmentPolicyAssignmentResourcesToMap(model *iampolicymanagementv1.PolicyAssignmentResources) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.Target != nil {
Expand Down
101 changes: 0 additions & 101 deletions ibm/service/iampolicy/resource_ibm_iam_policy_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ func ResourceIBMIAMPolicyAssignment() *schema.Resource {
"templates": {
Type: schema.TypeList,
Required: true,
MinItems: 1,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we removed Min and Max Items

MaxItems: 1,
Description: "policy template details.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -66,54 +64,6 @@ func ResourceIBMIAMPolicyAssignment() *schema.Resource {
},
},
},
"options": {
Type: schema.TypeList,
MinItems: 1,
MaxItems: 1,
Required: true,
Description: "The set of properties required for a policy assignment.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"root": {
Type: schema.TypeList,
MinItems: 1,
MaxItems: 1,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"requester_id": {
Type: schema.TypeString,
Required: true,
},
"assignment_id": {
Type: schema.TypeString,
Optional: true,
Description: "Passed in value to correlate with other assignments.",
},
"template": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Optional: true,
Description: "The template id where this policy is being assigned from.",
},
"version": {
Type: schema.TypeString,
Optional: true,
Description: "The template version where this policy is being assigned from.",
},
},
},
},
},
},
},
},
},
},
"account_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -304,11 +254,6 @@ func resourceIBMPolicyAssignmentCreate(context context.Context, d *schema.Resour
return diag.FromErr(err)
}
createPolicyTemplateAssignmentOptions.SetTarget(targetModel)
optionsModel, err := ResourceIBMPolicyAssignmentMapToPolicyAssignmentV1Options(d.Get("options.0").(map[string]interface{}))
if err != nil {
return diag.FromErr(err)
}
createPolicyTemplateAssignmentOptions.SetOptions(optionsModel)
var templates []iampolicymanagementv1.AssignmentTemplateDetails
for _, v := range d.Get("templates").([]interface{}) {
value := v.(map[string]interface{})
Expand Down Expand Up @@ -368,13 +313,6 @@ func resourceIBMPolicyAssignmentRead(context context.Context, d *schema.Resource
if err = d.Set("target", targetMap); err != nil {
return diag.FromErr(fmt.Errorf("error setting target: %s", err))
}
optionsMap, err := ResourceIBMPolicyAssignmentPolicyAssignmentV1OptionsToMap(assignmentDetails.Options)
if err != nil {
return diag.FromErr(err)
}
if err = d.Set("options", []map[string]interface{}{optionsMap}); err != nil {
return diag.FromErr(fmt.Errorf("error setting options: %s", err))
}
if !core.IsNil(assignmentDetails.AccountID) {
if err = d.Set("account_id", assignmentDetails.AccountID); err != nil {
return diag.FromErr(fmt.Errorf("error setting account_id: %s", err))
Expand Down Expand Up @@ -516,45 +454,6 @@ func ResourceIBMPolicyAssignmentMapToAssignmentTargetDetails(modelMap map[string
return model, nil
}

func ResourceIBMPolicyAssignmentMapToPolicyAssignmentV1Options(modelMap map[string]interface{}) (*iampolicymanagementv1.PolicyAssignmentV1Options, error) {
model := &iampolicymanagementv1.PolicyAssignmentV1Options{}
RootModel, err := ResourceIBMPolicyAssignmentMapToPolicyAssignmentV1OptionsRoot(modelMap["root"].([]interface{})[0].(map[string]interface{}))
if err != nil {
return model, err
}
model.Root = RootModel
return model, nil
}

func ResourceIBMPolicyAssignmentMapToPolicyAssignmentV1OptionsRoot(modelMap map[string]interface{}) (*iampolicymanagementv1.PolicyAssignmentV1OptionsRoot, error) {
model := &iampolicymanagementv1.PolicyAssignmentV1OptionsRoot{}
if modelMap["requester_id"] != nil && modelMap["requester_id"].(string) != "" {
model.RequesterID = core.StringPtr(modelMap["requester_id"].(string))
}
if modelMap["assignment_id"] != nil && modelMap["assignment_id"].(string) != "" {
model.AssignmentID = core.StringPtr(modelMap["assignment_id"].(string))
}
if modelMap["template"] != nil && len(modelMap["template"].([]interface{})) > 0 {
TemplateModel, err := ResourceIBMPolicyAssignmentMapToPolicyAssignmentV1OptionsRootTemplate(modelMap["template"].([]interface{})[0].(map[string]interface{}))
if err != nil {
return model, err
}
model.Template = TemplateModel
}
return model, nil
}

func ResourceIBMPolicyAssignmentMapToPolicyAssignmentV1OptionsRootTemplate(modelMap map[string]interface{}) (*iampolicymanagementv1.PolicyAssignmentV1OptionsRootTemplate, error) {
model := &iampolicymanagementv1.PolicyAssignmentV1OptionsRootTemplate{}
if modelMap["id"] != nil && modelMap["id"].(string) != "" {
model.ID = core.StringPtr(modelMap["id"].(string))
}
if modelMap["version"] != nil && modelMap["version"].(string) != "" {
model.Version = core.StringPtr(modelMap["version"].(string))
}
return model, nil
}

func ResourceIBMPolicyAssignmentMapToAssignmentTemplateDetails(modelMap map[string]interface{}) (*iampolicymanagementv1.AssignmentTemplateDetails, error) {
model := &iampolicymanagementv1.AssignmentTemplateDetails{}
if modelMap["id"] != nil && modelMap["id"].(string) != "" {
Expand Down
Loading