Little refactoring and fixing some issues
Starting to look pretty nice…
This commit is contained in:
parent
4e33d898e9
commit
f8a56ad3d7
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/MSOpenTech/azure-sdk-for-go/management"
|
"github.com/Azure/azure-sdk-for-go/management"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is the configuration structure used to instantiate a
|
// Config is the configuration structure used to instantiate a
|
||||||
|
|
|
@ -6,11 +6,11 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/MSOpenTech/azure-sdk-for-go/management"
|
"github.com/Azure/azure-sdk-for-go/management"
|
||||||
"github.com/MSOpenTech/azure-sdk-for-go/management/hostedservice"
|
"github.com/Azure/azure-sdk-for-go/management/hostedservice"
|
||||||
"github.com/MSOpenTech/azure-sdk-for-go/management/osimage"
|
"github.com/Azure/azure-sdk-for-go/management/osimage"
|
||||||
"github.com/MSOpenTech/azure-sdk-for-go/management/virtualmachine"
|
"github.com/Azure/azure-sdk-for-go/management/virtualmachine"
|
||||||
"github.com/MSOpenTech/azure-sdk-for-go/management/vmutils"
|
"github.com/Azure/azure-sdk-for-go/management/vmutils"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/MSOpenTech/azure-sdk-for-go/management"
|
"github.com/Azure/azure-sdk-for-go/management"
|
||||||
"github.com/MSOpenTech/azure-sdk-for-go/management/networksecuritygroup"
|
"github.com/Azure/azure-sdk-for-go/management/networksecuritygroup"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ func resourceAzureSecurityGroup() *schema.Resource {
|
||||||
"type": &schema.Schema{
|
"type": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: "inbound",
|
Default: "Inbound",
|
||||||
},
|
},
|
||||||
|
|
||||||
"priority": &schema.Schema{
|
"priority": &schema.Schema{
|
||||||
|
@ -66,7 +66,7 @@ func resourceAzureSecurityGroup() *schema.Resource {
|
||||||
"action": &schema.Schema{
|
"action": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: "allow",
|
Default: "Allow",
|
||||||
},
|
},
|
||||||
|
|
||||||
"source_cidr": &schema.Schema{
|
"source_cidr": &schema.Schema{
|
||||||
|
@ -92,7 +92,7 @@ func resourceAzureSecurityGroup() *schema.Resource {
|
||||||
"protocol": &schema.Schema{
|
"protocol": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: "tcp",
|
Default: "TCP",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -196,6 +196,30 @@ func resourceAzureSecurityGroupRead(d *schema.ResourceData, meta interface{}) er
|
||||||
d.Set("label", sg.Label)
|
d.Set("label", sg.Label)
|
||||||
d.Set("location", sg.Location)
|
d.Set("location", sg.Location)
|
||||||
|
|
||||||
|
// Create an empty schema.Set to hold all rules
|
||||||
|
rules := &schema.Set{
|
||||||
|
F: resourceAzureSecurityGroupRuleHash,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, r := range sg.Rules {
|
||||||
|
if !r.IsDefault {
|
||||||
|
rule := map[string]interface{}{
|
||||||
|
"name": r.Name,
|
||||||
|
"type": r.Type,
|
||||||
|
"priority": r.Priority,
|
||||||
|
"action": r.Action,
|
||||||
|
"source_cidr": r.SourceAddressPrefix,
|
||||||
|
"source_port": r.SourcePortRange,
|
||||||
|
"destination_cidr": r.DestinationAddressPrefix,
|
||||||
|
"destination_port": r.DestinationPortRange,
|
||||||
|
"protocol": r.Protocol,
|
||||||
|
}
|
||||||
|
rules.Add(rule)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Set("rule", rules)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,21 +306,21 @@ func resourceAzureSecurityGroupRuleHash(v interface{}) int {
|
||||||
|
|
||||||
func verifySecurityGroupRuleParams(rule map[string]interface{}) error {
|
func verifySecurityGroupRuleParams(rule map[string]interface{}) error {
|
||||||
typ := rule["type"].(string)
|
typ := rule["type"].(string)
|
||||||
if typ != "inbound" && typ != "outbound" {
|
if typ != "Inbound" && typ != "Outbound" {
|
||||||
return fmt.Errorf("Parameter type only accepts 'inbound' or 'outbound' as values")
|
return fmt.Errorf("Parameter type only accepts 'Inbound' or 'Outbound' as values")
|
||||||
}
|
}
|
||||||
|
|
||||||
action := rule["action"].(string)
|
action := rule["action"].(string)
|
||||||
if action != "allow" && action != "deny" {
|
if action != "Allow" && action != "Deny" {
|
||||||
return fmt.Errorf("Parameter action only accepts 'allow' or 'deny' as values")
|
return fmt.Errorf("Parameter action only accepts 'Allow' or 'Deny' as values")
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol := rule["protocol"].(string)
|
protocol := rule["protocol"].(string)
|
||||||
if protocol != "tcp" && protocol != "udp" && protocol != "*" {
|
if protocol != "TCP" && protocol != "UDP" && protocol != "*" {
|
||||||
_, err := strconv.ParseInt(protocol, 0, 0)
|
_, err := strconv.ParseInt(protocol, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Parameter type only accepts 'tcp', 'udp' or '*' as values")
|
"Parameter type only accepts 'TCP', 'UDP' or '*' as values")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/MSOpenTech/azure-sdk-for-go/management"
|
"github.com/Azure/azure-sdk-for-go/management"
|
||||||
"github.com/MSOpenTech/azure-sdk-for-go/management/virtualnetwork"
|
"github.com/Azure/azure-sdk-for-go/management/virtualnetwork"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue