Skip to content

Commit

Permalink
feat: Add description & comments field To ASN resource
Browse files Browse the repository at this point in the history
  • Loading branch information
ymylei committed Dec 15, 2024
1 parent f6d2f3e commit 7d999ec
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 36 deletions.
12 changes: 8 additions & 4 deletions docs/resources/asn.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ resource "netbox_rir" "test" {
}
resource "netbox_asn" "test" {
asn = 1337
rir_id = netbox_rir.test.id
asn = 1337
rir_id = netbox_rir.test.id
description = "test"
comments = "test"
}
```

Expand All @@ -34,11 +36,13 @@ resource "netbox_asn" "test" {

### Required

- `asn` (Number)
- `rir_id` (Number)
- `asn` (Number) Value for the AS Number record.
- `rir_id` (Number) ID for the RIR for the AS Number record.

### Optional

- `comments` (String) Comments field for the AS Number record.
- `description` (String) Description field for the AS Number record.
- `tags` (Set of String)

### Read-Only
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/config_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ From the [official documentation](https://docs.netbox.dev/en/stable/models/extra
```terraform
resource "netbox_config_context" "test" {
name = "%s"
data = jsonencode({"testkey" = "testval"})
data = jsonencode({ "testkey" = "testval" })
}
```

Expand Down
22 changes: 11 additions & 11 deletions docs/resources/interface_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ From the [official documentation](https://docs.netbox.dev/en/stable/models/dcim/

```terraform
resource "netbox_manufacturer" "test" {
name = "my-manufacturer"
name = "my-manufacturer"
}
resource "netbox_device_type" "test" {
model = "test-model"
slug = "test-model"
part_number = "test-part-number"
manufacturer_id = netbox_manufacturer.test.id
model = "test-model"
slug = "test-model"
part_number = "test-part-number"
manufacturer_id = netbox_manufacturer.test.id
}
resource "netbox_interface_template" "test" {
name = "eth0"
description = "eth0 description"
label = "eth0 label"
device_type_id = netbox_device_type.test.id
type = "100base-tx"
mgmt_only = true
name = "eth0"
description = "eth0 description"
label = "eth0 label"
device_type_id = netbox_device_type.test.id
type = "100base-tx"
mgmt_only = true
}
```

Expand Down
6 changes: 4 additions & 2 deletions examples/resources/netbox_asn/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ resource "netbox_rir" "test" {
}

resource "netbox_asn" "test" {
asn = 1337
rir_id = netbox_rir.test.id
asn = 1337
rir_id = netbox_rir.test.id
description = "test"
comments = "test"
}
2 changes: 1 addition & 1 deletion examples/resources/netbox_config_context/resource.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "netbox_config_context" "test" {
name = "%s"
data = jsonencode({"testkey" = "testval"})
data = jsonencode({ "testkey" = "testval" })
}
22 changes: 11 additions & 11 deletions examples/resources/netbox_interface_template/resource.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
resource "netbox_manufacturer" "test" {
name = "my-manufacturer"
name = "my-manufacturer"
}

resource "netbox_device_type" "test" {
model = "test-model"
slug = "test-model"
part_number = "test-part-number"
manufacturer_id = netbox_manufacturer.test.id
model = "test-model"
slug = "test-model"
part_number = "test-part-number"
manufacturer_id = netbox_manufacturer.test.id
}

resource "netbox_interface_template" "test" {
name = "eth0"
description = "eth0 description"
label = "eth0 label"
device_type_id = netbox_device_type.test.id
type = "100base-tx"
mgmt_only = true
name = "eth0"
description = "eth0 description"
label = "eth0 label"
device_type_id = netbox_device_type.test.id
type = "100base-tx"
mgmt_only = true
}
29 changes: 23 additions & 6 deletions netbox/resource_netbox_asn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,24 @@ func resourceNetboxAsn() *schema.Resource {

Schema: map[string]*schema.Schema{
"asn": {
Type: schema.TypeInt,
Required: true,
Type: schema.TypeInt,
Required: true,
Description: "Value for the AS Number record",
},
"rir_id": {
Type: schema.TypeInt,
Required: true,
Type: schema.TypeInt,
Required: true,
Description: "ID for the RIR for the AS Number record",
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: "Description field for the AS Number record",
},
"comments": {
Type: schema.TypeString,
Optional: true,
Description: "Comments field for the AS Number record",
},
tagsKey: tagsSchema,
},
Expand All @@ -49,6 +61,8 @@ func resourceNetboxAsnCreate(d *schema.ResourceData, m interface{}) error {
rir := int64(d.Get("rir_id").(int))
data.Rir = &rir

data.Description = d.Get("description").(string)
data.Comments = d.Get("comments").(string)
data.Tags, _ = getNestedTagListFromResourceDataSet(api, d.Get(tagsKey))

params := ipam.NewIpamAsnsCreateParams().WithData(&data)
Expand Down Expand Up @@ -85,7 +99,8 @@ func resourceNetboxAsnRead(d *schema.ResourceData, m interface{}) error {
asn := res.GetPayload()
d.Set("asn", asn.Asn)
d.Set("rir_id", asn.Rir.ID)

d.Set("description", asn.Description)
d.Set("comments", asn.Comments)
d.Set(tagsKey, getTagListFromNestedTagList(asn.Tags))

return nil
Expand All @@ -102,7 +117,9 @@ func resourceNetboxAsnUpdate(d *schema.ResourceData, m interface{}) error {

rir := int64(d.Get("rir_id").(int))
data.Rir = &rir


data.Description = d.Get("description").(string)
data.Comments = d.Get("comments").(string)
data.Tags, _ = getNestedTagListFromResourceDataSet(api, d.Get(tagsKey))

params := ipam.NewIpamAsnsUpdateParams().WithID(id).WithData(&data)
Expand Down
5 changes: 5 additions & 0 deletions netbox/resource_netbox_asn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ resource "netbox_rir" "test" {
resource "netbox_asn" "test" {
asn = 1337
rir_id = netbox_rir.test.id
description = "test"
comments = "test"
tags = ["%[1]sa"]
}`, testName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netbox_asn.test", "asn", "1337"),
resource.TestCheckResourceAttr("netbox_asn.test", "description", "test"),
resource.TestCheckResourceAttr("netbox_asn.test", "comments", "test"),
resource.TestCheckResourceAttr("netbox_asn.test", "tags.#", "1"),
resource.TestCheckResourceAttr("netbox_asn.test", "tags.0", testName+"a"),
),
Expand Down

0 comments on commit 7d999ec

Please sign in to comment.