From f8a56ad3d704fcbbe1554c59308fcdbce9444f9d Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Thu, 30 Apr 2015 17:12:05 +0200 Subject: [PATCH] Little refactoring and fixing some issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Starting to look pretty nice… --- builtin/providers/azure/config.go | 2 +- .../azure/resource_azure_instance.go | 10 ++-- .../azure/resource_azure_security_group.go | 46 ++++++++++++++----- .../azure/resource_azure_virtual_network.go | 4 +- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/builtin/providers/azure/config.go b/builtin/providers/azure/config.go index ad4dc60c00..62e302a276 100644 --- a/builtin/providers/azure/config.go +++ b/builtin/providers/azure/config.go @@ -4,7 +4,7 @@ import ( "fmt" "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 diff --git a/builtin/providers/azure/resource_azure_instance.go b/builtin/providers/azure/resource_azure_instance.go index 9fe45eee10..b3eb5c5afd 100644 --- a/builtin/providers/azure/resource_azure_instance.go +++ b/builtin/providers/azure/resource_azure_instance.go @@ -6,11 +6,11 @@ import ( "log" "strings" - "github.com/MSOpenTech/azure-sdk-for-go/management" - "github.com/MSOpenTech/azure-sdk-for-go/management/hostedservice" - "github.com/MSOpenTech/azure-sdk-for-go/management/osimage" - "github.com/MSOpenTech/azure-sdk-for-go/management/virtualmachine" - "github.com/MSOpenTech/azure-sdk-for-go/management/vmutils" + "github.com/Azure/azure-sdk-for-go/management" + "github.com/Azure/azure-sdk-for-go/management/hostedservice" + "github.com/Azure/azure-sdk-for-go/management/osimage" + "github.com/Azure/azure-sdk-for-go/management/virtualmachine" + "github.com/Azure/azure-sdk-for-go/management/vmutils" "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" ) diff --git a/builtin/providers/azure/resource_azure_security_group.go b/builtin/providers/azure/resource_azure_security_group.go index f288fc0e55..b6fe4c9a2f 100644 --- a/builtin/providers/azure/resource_azure_security_group.go +++ b/builtin/providers/azure/resource_azure_security_group.go @@ -5,8 +5,8 @@ import ( "log" "strconv" - "github.com/MSOpenTech/azure-sdk-for-go/management" - "github.com/MSOpenTech/azure-sdk-for-go/management/networksecuritygroup" + "github.com/Azure/azure-sdk-for-go/management" + "github.com/Azure/azure-sdk-for-go/management/networksecuritygroup" "github.com/hashicorp/terraform/helper/schema" ) @@ -55,7 +55,7 @@ func resourceAzureSecurityGroup() *schema.Resource { "type": &schema.Schema{ Type: schema.TypeString, Optional: true, - Default: "inbound", + Default: "Inbound", }, "priority": &schema.Schema{ @@ -66,7 +66,7 @@ func resourceAzureSecurityGroup() *schema.Resource { "action": &schema.Schema{ Type: schema.TypeString, Optional: true, - Default: "allow", + Default: "Allow", }, "source_cidr": &schema.Schema{ @@ -92,7 +92,7 @@ func resourceAzureSecurityGroup() *schema.Resource { "protocol": &schema.Schema{ Type: schema.TypeString, 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("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 } @@ -282,21 +306,21 @@ func resourceAzureSecurityGroupRuleHash(v interface{}) int { func verifySecurityGroupRuleParams(rule map[string]interface{}) error { typ := rule["type"].(string) - if typ != "inbound" && typ != "outbound" { - return fmt.Errorf("Parameter type only accepts 'inbound' or 'outbound' as values") + if typ != "Inbound" && typ != "Outbound" { + return fmt.Errorf("Parameter type only accepts 'Inbound' or 'Outbound' as values") } action := rule["action"].(string) - if action != "allow" && action != "deny" { - return fmt.Errorf("Parameter action only accepts 'allow' or 'deny' as values") + if action != "Allow" && action != "Deny" { + return fmt.Errorf("Parameter action only accepts 'Allow' or 'Deny' as values") } protocol := rule["protocol"].(string) - if protocol != "tcp" && protocol != "udp" && protocol != "*" { + if protocol != "TCP" && protocol != "UDP" && protocol != "*" { _, err := strconv.ParseInt(protocol, 0, 0) if err != nil { return fmt.Errorf( - "Parameter type only accepts 'tcp', 'udp' or '*' as values") + "Parameter type only accepts 'TCP', 'UDP' or '*' as values") } } diff --git a/builtin/providers/azure/resource_azure_virtual_network.go b/builtin/providers/azure/resource_azure_virtual_network.go index 0de4561139..39053cf2dd 100644 --- a/builtin/providers/azure/resource_azure_virtual_network.go +++ b/builtin/providers/azure/resource_azure_virtual_network.go @@ -5,8 +5,8 @@ import ( "log" "strings" - "github.com/MSOpenTech/azure-sdk-for-go/management" - "github.com/MSOpenTech/azure-sdk-for-go/management/virtualnetwork" + "github.com/Azure/azure-sdk-for-go/management" + "github.com/Azure/azure-sdk-for-go/management/virtualnetwork" "github.com/hashicorp/terraform/helper/schema" "github.com/mitchellh/mapstructure" )