Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.8.1
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a (unreleased) here to emphasize this is not published yet. Also, whenever you update the changelog, make sure you run the generator again to update the changelog in the documentation as well.


- Enhance handling of DNS split profile assignments by adding checks for empty responses and refining matching logic for assignment IDs during updates - Issue #131.

## 1.8.0

- Add `high_speed_enabled` attribute to `meraki_switch_port` resources and data sources
Expand Down
4 changes: 4 additions & 0 deletions gen/definitions/appliance_dns_split_profile_assignments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ no_update: false
no_delete: false
no_import: true
no_read: false
get_in_create_context: true
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to enhance the generator here, as this should not be a common theme. Due to the non-standard endpoint paths, this resource requires code customizations anyway, therefore I would just insert the extra GET after the POST manually in resource.go.

read_path_method: getAssignmentsPath
doc_category: Appliances
test_tags: [APPLIANCE_DNS_SPLIT_PROFILE_ASSIGNMENTS]
test_variables: [test_org, test_network]
Expand Down Expand Up @@ -34,12 +36,14 @@ attributes:
description: ID of the network
example: N_123456
test_value: meraki_network.test.id
id: true
- model_name: id
type: String
data_path: [profile]
mandatory: true
description: ID of the profile
example: "1234"
id: true
test_value: meraki_appliance_dns_split_profile.test.id
test_prerequisites: |
data "meraki_organization" "test" {
Expand Down
2 changes: 2 additions & 0 deletions gen/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ no_delete: bool(required=False) # Set to true if the DELETE request is not suppo
no_import: bool(required=False) # Set to true if the resource does not support importing
no_read: bool(required=False) # Set to true if the resource does not support reading (GET)
post_and_put: bool(required=False) # Set to true if the resource should issue another PUT request after a POST request
get_in_create_context: bool(required=False) # Set to true if the resource should issue a GET request after create to retrieve computed values
read_path_method: str(required=False) # Method name to use for Read() path (e.g., "getAssignmentsPath", "getGetPath"). If not specified, uses "getPath()"
data_source_name_query: bool(required=False) # Set to true if the data source supports name queries
minimum_version: str(required=False) # Define a minimum supported version
ds_description: str(required=False) # Define a data source description
Expand Down
14 changes: 14 additions & 0 deletions gen/templates/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,21 @@ func (r *{{camelCase .Name}}Resource) Create(ctx context.Context, req resource.C
{{- else}}
plan.Id = types.StringValue(res.Get("{{.IdName}}").String())
{{- end}}

{{- if .GetInCreateContext}}
{{- if .ReadPathMethod}}
resGet, errGet := r.client.Get(plan.{{.ReadPathMethod}}())
{{- else}}
resGet, errGet := r.client.Get(plan.getPath())
{{- end}}
if errGet != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", errGet, resGet.String()))
return
}
plan.fromBodyUnknowns(ctx, resGet)
{{- else}}
plan.fromBodyUnknowns(ctx, res)
{{- end}}

{{- if .PostAndPut}}
res, err = r.client.Put(plan.getPath() + "/" + url.QueryEscape(plan.Id.ValueString()), body)
Expand Down
6 changes: 6 additions & 0 deletions gen/yamlconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ type YamlConfig struct {
GetFromAll bool `yaml:"get_from_all,omitempty"`
NoUpdate bool `yaml:"no_update,omitempty"`
NoDelete bool `yaml:"no_delete,omitempty"`
GetInCreateContext bool `yaml:"get_in_create_context,omitempty"`
NoImport bool `yaml:"no_import,omitempty"`
NoRead bool `yaml:"no_read,omitempty"`
PostAndPut bool `yaml:"post_and_put,omitempty"`
ReadPathMethod string `yaml:"read_path_method,omitempty"`
IdName string `yaml:"id_name,omitempty"`
EarlyAccess bool `yaml:"early_access,omitempty"`
DataSourceNameQuery bool `yaml:"data_source_name_query,omitempty"`
Expand Down Expand Up @@ -66,6 +68,7 @@ type YamlConfigP struct {
NoImport *bool `yaml:"no_import,omitempty"`
NoRead *bool `yaml:"no_read,omitempty"`
PostAndPut *bool `yaml:"post_and_put,omitempty"`
ReadPathMethod *string `yaml:"read_path_method,omitempty"`
IdName *string `yaml:"id_name,omitempty"`
EarlyAccess *bool `yaml:"early_access,omitempty"`
DataSourceNameQuery *bool `yaml:"data_source_name_query,omitempty"`
Expand Down Expand Up @@ -732,6 +735,9 @@ func MergeYamlConfig(existing *YamlConfigP, new *YamlConfigP) *YamlConfigP {
if existing.PostAndPut != nil {
new.PostAndPut = existing.PostAndPut
}
if existing.ReadPathMethod != nil {
new.ReadPathMethod = existing.ReadPathMethod
}
if existing.IdName != nil {
new.IdName = existing.IdName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func (data *ApplianceDNSSplitProfileAssignments) fromBody(ctx context.Context, r
// "managed" elements, instead of all elements.
func (data *ApplianceDNSSplitProfileAssignments) fromBodyPartial(ctx context.Context, res meraki.Res) {
for i := 0; i < len(data.Items); i++ {
keys := [...]string{"assignmentId", "network.id", "profile.id"}
keyValues := [...]string{data.Items[i].AssignmentId.ValueString(), data.Items[i].NetworkId.ValueString(), data.Items[i].ProfileId.ValueString()}
keys := [...]string{"network.id", "profile.id"}
keyValues := [...]string{data.Items[i].NetworkId.ValueString(), data.Items[i].ProfileId.ValueString()}

parent := &data
data := (*parent).Items[i]
Expand Down Expand Up @@ -203,8 +203,8 @@ func (data *ApplianceDNSSplitProfileAssignments) fromBodyPartial(ctx context.Con
// Known values are not changed (usual for Computed attributes with UseStateForUnknown or with Default).
func (data *ApplianceDNSSplitProfileAssignments) fromBodyUnknowns(ctx context.Context, res meraki.Res) {
for i := 0; i < len(data.Items); i++ {
keys := [...]string{"assignmentId", "network.id", "profile.id"}
keyValues := [...]string{data.Items[i].AssignmentId.ValueString(), data.Items[i].NetworkId.ValueString(), data.Items[i].ProfileId.ValueString()}
keys := [...]string{"network.id", "profile.id"}
keyValues := [...]string{data.Items[i].NetworkId.ValueString(), data.Items[i].ProfileId.ValueString()}

parent := &data
data := (*parent).Items[i]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ func (r *ApplianceDNSSplitProfileAssignmentsResource) Create(ctx context.Context
return
}
plan.Id = plan.OrganizationId
plan.fromBodyUnknowns(ctx, res)
resGet, errGet := r.client.Get(plan.getAssignmentsPath())
if errGet != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", errGet, resGet.String()))
return
}
plan.fromBodyUnknowns(ctx, resGet)

tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.Id.ValueString()))

Expand Down
4 changes: 4 additions & 0 deletions templates/guides/changelog.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ description: |-

# Changelog

## 1.8.1

- Enhance handling of DNS split profile assignments by adding checks for empty responses and refining matching logic for assignment IDs during updates - Issue #131.

## 1.8.0

- Add `high_speed_enabled` attribute to `meraki_switch_port` resources and data sources
Expand Down
Loading