Skip to content

Commit

Permalink
Add description field to firewall rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Huber authored and fhofherr committed Aug 3, 2021
1 parent a0a90b8 commit 92a07cd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -4,7 +4,7 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0
github.com/hetznercloud/hcloud-go v1.28.0
github.com/hetznercloud/hcloud-go v1.29.0
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -201,8 +201,8 @@ github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0/go.mod h1:grseeRo9g3yNkYW09i
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hetznercloud/hcloud-go v1.28.0 h1:T2a0CVGETf7BoWIdZ/TACqmTZAa/ROutcfdUHYiPAQ4=
github.com/hetznercloud/hcloud-go v1.28.0/go.mod h1:2C5uMtBiMoFr3m7lBFPf7wXTdh33CevmZpQIIDPGYJI=
github.com/hetznercloud/hcloud-go v1.29.0 h1:GVUj/VM3wFG6bnVGbIbTyUBr1MgcJI30pH6lus/UfpY=
github.com/hetznercloud/hcloud-go v1.29.0/go.mod h1:2C5uMtBiMoFr3m7lBFPf7wXTdh33CevmZpQIIDPGYJI=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
Expand Down
4 changes: 4 additions & 0 deletions internal/firewall/data_source.go
Expand Up @@ -62,6 +62,10 @@ func DataSource() *schema.Resource {
},
Optional: true,
},
"description": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
},
},
Expand Down
11 changes: 11 additions & 0 deletions internal/firewall/resource.go
Expand Up @@ -95,6 +95,10 @@ func Resource() *schema.Resource {
},
Optional: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -147,6 +151,10 @@ func toHcloudRule(tfRawRule interface{}) hcloud.FirewallRule {
if rawPort != "" {
rule.Port = hcloud.String(rawPort)
}
rawDescription := tfRule["description"].(string)
if rawDescription != "" {
rule.Description = hcloud.String(rawDescription)
}
for _, sourceIP := range tfRule["source_ips"].(*schema.Set).List() {
// We ignore the error here, because it was already validated before
_, source, _ := net.ParseCIDR(sourceIP.(string))
Expand All @@ -168,6 +176,9 @@ func toTFRule(hcloudRule hcloud.FirewallRule) map[string]interface{} {
if hcloudRule.Port != nil {
tfRule["port"] = hcloudRule.Port
}
if hcloudRule.Description != nil {
tfRule["description"] = hcloudRule.Description
}
sourceIPs := make([]string, len(hcloudRule.SourceIPs))
for i, sourceIP := range hcloudRule.SourceIPs {
sourceIPs[i] = sourceIP.String()
Expand Down
1 change: 1 addition & 0 deletions internal/firewall/testing.go
Expand Up @@ -93,6 +93,7 @@ type RDataRule struct {
SourceIPs []string
DestinationIPs []string
Protocol string
Description string
}

// TFID returns the resource identifier.
Expand Down

0 comments on commit 92a07cd

Please sign in to comment.