Skip to content

Commit

Permalink
fix: nil pointer on bgp
Browse files Browse the repository at this point in the history
Fixes #207
  • Loading branch information
vaerh committed May 15, 2023
1 parent f414910 commit 93cf45e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions routeros/mikrotik_serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ func TerraformResourceDataToMikrotik(s map[string]*schema.Schema, d *schema.Reso
filedNameInState := fmt.Sprintf("%v.%v.%v", terraformSnakeName, 0, fieldName)
fieldSchema := terraformMetadata.Elem.(*schema.Resource).Schema[fieldName]

// Skip all read-only properties.
if fieldSchema.Computed && !fieldSchema.Optional {
continue
}

if fieldSchema.Optional && !d.HasChange(filedNameInState) &&
isEmpty(filedNameInState, fieldSchema, d, ctyList.GetAttr(fieldName)) {
continue
Expand Down Expand Up @@ -378,6 +383,16 @@ func MikrotikResourceDataToTerraform(item MikrotikItem, s map[string]*schema.Sch
case *schema.Resource:
var v any

if _, ok := s[terraformSnakeName].Elem.(*schema.Resource).Schema[subFieldSnakeName]; !ok {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "Field '" + terraformSnakeName + "." + subFieldSnakeName + "' not found in the schema",
Detail: fmt.Sprintf("[MikrotikResourceDataToTerraformDatasource] the datasource Schema sub-field was lost during development: ▷ '%s.%s' ◁",
terraformSnakeName, subFieldSnakeName),
})
continue
}

switch s[terraformSnakeName].Elem.(*schema.Resource).Schema[subFieldSnakeName].Type {
case schema.TypeString:
v = mikrotikValue
Expand Down
5 changes: 5 additions & 0 deletions routeros/resource_bgp_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ func ResourceRoutingBGPConnection() *schema.Resource {
Optional: true,
Description: "Local connection IPv4/6 address.",
},
"default_address": {
Type: schema.TypeString,
Computed: true,
Description: "",
},
"port": {
Type: schema.TypeInt,
Optional: true,
Expand Down

0 comments on commit 93cf45e

Please sign in to comment.