From 4a09db9a8a9df1a30beb0b8cd3227cb27313cce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Mu=C3=B1oz?= Date: Tue, 26 Nov 2024 12:25:30 -0600 Subject: [PATCH] meraki_organizations_policy_objects_groups broken, both the data and resource #178 --- .../data-source.tf | 20 ++++++++++++++++ .../meraki_organizations_admins/resource.tf | 2 +- .../import.sh | 1 + .../resource.tf | 24 +++++++++++++++++++ ...aki_organizations_policy_objects_groups.go | 2 +- ...aki_organizations_policy_objects_groups.go | 23 ++++++++++++------ 6 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 examples/samples/data_sources/meraki_organizations_policy_objects_groups/data-source.tf create mode 100644 examples/samples/resources/meraki_organizations_policy_objects_groups/import.sh create mode 100644 examples/samples/resources/meraki_organizations_policy_objects_groups/resource.tf diff --git a/examples/samples/data_sources/meraki_organizations_policy_objects_groups/data-source.tf b/examples/samples/data_sources/meraki_organizations_policy_objects_groups/data-source.tf new file mode 100644 index 0000000..2a6771f --- /dev/null +++ b/examples/samples/data_sources/meraki_organizations_policy_objects_groups/data-source.tf @@ -0,0 +1,20 @@ +terraform { + required_providers { + meraki = { + version = "0.2.12-alpha" + source = "hashicorp.com/edu/meraki" + } + } +} + +data "meraki_organizations_policy_objects_groups" "example" { + + # ending_before = "string" + # organization_id = "string" + per_page = 1 + # starting_after = "string" +} + +output "meraki_organizations_policy_objects_groups_example" { + value = data.meraki_organizations_policy_objects_groups.example.item +} diff --git a/examples/samples/resources/meraki_organizations_admins/resource.tf b/examples/samples/resources/meraki_organizations_admins/resource.tf index 1be773e..06ae03b 100644 --- a/examples/samples/resources/meraki_organizations_admins/resource.tf +++ b/examples/samples/resources/meraki_organizations_admins/resource.tf @@ -5,7 +5,7 @@ terraform { source = "hashicorp.com/edu/meraki" } } -} + } provider "meraki" { diff --git a/examples/samples/resources/meraki_organizations_policy_objects_groups/import.sh b/examples/samples/resources/meraki_organizations_policy_objects_groups/import.sh new file mode 100644 index 0000000..0374b03 --- /dev/null +++ b/examples/samples/resources/meraki_organizations_policy_objects_groups/import.sh @@ -0,0 +1 @@ +terraform import meraki_organizations_policy_objects_groups.example "organization_id,policy_object_group_id" \ No newline at end of file diff --git a/examples/samples/resources/meraki_organizations_policy_objects_groups/resource.tf b/examples/samples/resources/meraki_organizations_policy_objects_groups/resource.tf new file mode 100644 index 0000000..3f11e15 --- /dev/null +++ b/examples/samples/resources/meraki_organizations_policy_objects_groups/resource.tf @@ -0,0 +1,24 @@ +terraform { + required_providers { + meraki = { + version = "0.2.12-alpha" + source = "hashicorp.com/edu/meraki" + } + } + } + +provider "meraki" { + meraki_debug = "true" +} + +resource "meraki_organizations_policy_objects_groups" "example" { + + category = "NetworkObjectGroup" + name = "Issue 178" + object_ids = [828099381482759082, 828099381482759083] + organization_id = "828099381482762270" +} + +output "meraki_organizations_policy_objects_groups_example" { + value = meraki_organizations_policy_objects_groups.example +} \ No newline at end of file diff --git a/internal/provider/data_source_meraki_organizations_policy_objects_groups.go b/internal/provider/data_source_meraki_organizations_policy_objects_groups.go index ad4fc29..844d14c 100644 --- a/internal/provider/data_source_meraki_organizations_policy_objects_groups.go +++ b/internal/provider/data_source_meraki_organizations_policy_objects_groups.go @@ -194,7 +194,7 @@ func ResponseOrganizationsGetOrganizationPolicyObjectsGroupItemToBody(state Orga ID: types.StringValue(response.ID), Name: types.StringValue(response.Name), NetworkIDs: StringSliceToSet(response.NetworkIDs), - ObjectIDs: StringSliceToSetInt(response.ObjectIDs), + ObjectIDs: StringSliceToSet(*response.ObjectIDs), UpdatedAt: types.StringValue(response.UpdatedAt), } state.Item = &itemState diff --git a/internal/provider/resource_meraki_organizations_policy_objects_groups.go b/internal/provider/resource_meraki_organizations_policy_objects_groups.go index a7e13a4..6bc979a 100644 --- a/internal/provider/resource_meraki_organizations_policy_objects_groups.go +++ b/internal/provider/resource_meraki_organizations_policy_objects_groups.go @@ -58,9 +58,15 @@ func (r *OrganizationsPolicyObjectsGroupsResource) Schema(_ context.Context, _ r }, "created_at": schema.StringAttribute{ Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, }, "id": schema.StringAttribute{ Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, }, "name": schema.StringAttribute{ MarkdownDescription: `A name for the group of network addresses, unique within the organization (alphanumeric, space, dash, or underscore characters only)`, @@ -71,7 +77,10 @@ func (r *OrganizationsPolicyObjectsGroupsResource) Schema(_ context.Context, _ r }, }, "network_ids": schema.SetAttribute{ - Computed: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, ElementType: types.StringType, }, "object_ids": schema.SetAttribute{ @@ -129,7 +138,7 @@ func (r *OrganizationsPolicyObjectsGroupsResource) Create(ctx context.Context, r // organization_id vvName := data.Name.ValueString() //Items - responseVerifyItem, restyResp1, err := r.client.Organizations.GetOrganizationPolicyObjects(vvOrganizationID, nil) + responseVerifyItem, restyResp1, err := r.client.Organizations.GetOrganizationPolicyObjectsGroups(vvOrganizationID, nil) //Have Create if err != nil { if restyResp1 != nil { @@ -183,7 +192,7 @@ func (r *OrganizationsPolicyObjectsGroupsResource) Create(ctx context.Context, r return } //Items - responseGet, restyResp1, err := r.client.Organizations.GetOrganizationPolicyObjects(vvOrganizationID, nil) + responseGet, restyResp1, err := r.client.Organizations.GetOrganizationPolicyObjectsGroups(vvOrganizationID, nil) // Has item and has items if err != nil || responseGet == nil { @@ -207,8 +216,7 @@ func (r *OrganizationsPolicyObjectsGroupsResource) Create(ctx context.Context, r vvPolicyObjectGroupID, ok := result2["ID"].(string) if !ok { resp.Diagnostics.AddError( - "Failure when parsing path parameter PolicyObjectGroupID", - err.Error(), + "Failure when parsing path parameter PolicyObjectGroupID", "Error", ) return } @@ -402,8 +410,9 @@ func (r *OrganizationsPolicyObjectsGroupsRs) toSdkApiRequestCreate(ctx context.C } else { name = &emptyString } - var objectIDs *[]int = nil + var objectIDs *[]string = nil r.ObjectIDs.ElementsAs(ctx, &objectIDs, false) + out := merakigosdk.RequestOrganizationsCreateOrganizationPolicyObjectsGroup{ Category: *category, Name: *name, @@ -436,7 +445,7 @@ func ResponseOrganizationsGetOrganizationPolicyObjectsGroupItemToBodyRs(state Or ID: types.StringValue(response.ID), Name: types.StringValue(response.Name), NetworkIDs: StringSliceToSet(response.NetworkIDs), - ObjectIDs: StringSliceToSetInt(response.ObjectIDs), + ObjectIDs: StringSliceToSet(*response.ObjectIDs), UpdatedAt: types.StringValue(response.UpdatedAt), } if is_read {