Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into scale-set
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte committed Sep 8, 2018
2 parents 8f02d6b + 8311774 commit 88044d5
Show file tree
Hide file tree
Showing 26 changed files with 4,853 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

* **New Resource:** `azurestack_route_table` [GH-26]
* **New Resource:** `azurestack_route` [GH-27]
* **New Resource:** `azurestack_template_deployment` [GH-33]
* **New Resource:** `azurestack_virtual_network_gateway` [GH-31]
* **New Data Source:** `azurestack_public_ip` [GH-34]
* **New Data Source:** `azurestack_route_table` [GH-26]
* **New Data Source:** `azurestack_subnet` [GH-34]
* **New Data Source:** `azurestack_virtual_network_gateway` [GH-31]

## 0.3.0 (August 13, 2018)

Expand Down
10 changes: 10 additions & 0 deletions azurestack/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ArmClient struct {
ifaceClient network.InterfacesClient
localNetConnClient network.LocalNetworkGatewaysClient
secRuleClient network.SecurityRulesClient
vnetGatewayClient network.VirtualNetworkGatewaysClient

// Resources
providersClient resources.ProvidersClient
Expand All @@ -71,6 +72,7 @@ type ArmClient struct {
routeTablesClient network.RouteTablesClient

resourceGroupsClient resources.GroupsClient
deploymentsClient resources.DeploymentsClient
}

func (c *ArmClient) configureClient(client *autorest.Client, auth autorest.Authorizer) {
Expand Down Expand Up @@ -226,6 +228,10 @@ func (c *ArmClient) registerNetworkingClients(endpoint, subscriptionId string, a
c.configureClient(&interfacesClient.Client, auth)
c.ifaceClient = interfacesClient

gatewaysClient := network.NewVirtualNetworkGatewaysClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&gatewaysClient.Client, auth)
c.vnetGatewayClient = gatewaysClient

localNetworkGatewaysClient := network.NewLocalNetworkGatewaysClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&localNetworkGatewaysClient.Client, auth)
c.localNetConnClient = localNetworkGatewaysClient
Expand Down Expand Up @@ -268,6 +274,10 @@ func (c *ArmClient) registerResourcesClients(endpoint, subscriptionId string, au
c.configureClient(&resourcesClient.Client, auth)
c.resourcesClient = resourcesClient

deploymentsClient := resources.NewDeploymentsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&deploymentsClient.Client, auth)
c.deploymentsClient = deploymentsClient

resourceGroupsClient := resources.NewGroupsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&resourceGroupsClient.Client, auth)
c.resourceGroupsClient = resourceGroupsClient
Expand Down
87 changes: 87 additions & 0 deletions azurestack/data_source_public_ip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package azurestack

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurestack/azurestack/utils"
)

func dataSourceArmPublicIP() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmPublicIPRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.NoZeroValues,
},

"resource_group_name": resourceGroupNameForDataSourceSchema(),

"domain_name_label": {
Type: schema.TypeString,
Computed: true,
},

"idle_timeout_in_minutes": {
Type: schema.TypeInt,
Computed: true,
},

"fqdn": {
Type: schema.TypeString,
Computed: true,
},

"ip_address": {
Type: schema.TypeString,
Computed: true,
},

"tags": tagsSchema(),
},
}
}

func dataSourceArmPublicIPRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).publicIPClient
ctx := meta.(*ArmClient).StopContext

resGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)

resp, err := client.Get(ctx, resGroup, name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Public IP %q (Resource Group %q) was not found", name, resGroup)
}
return fmt.Errorf("Error making Read request on Azure public ip %s: %s", name, err)
}

d.SetId(*resp.ID)

if props := resp.PublicIPAddressPropertiesFormat; props != nil {
if dnsSettings := props.DNSSettings; dnsSettings != nil {
if v := dnsSettings.Fqdn; v != nil && *v != "" {
d.Set("fqdn", v)
}

if v := dnsSettings.DomainNameLabel; v != nil && *v != "" {
d.Set("domain_name_label", v)
}
}

if v := props.IPAddress; v != nil && *v != "" {
d.Set("ip_address", v)
}

if v := props.IdleTimeoutInMinutes; v != nil {
d.Set("idle_timeout_in_minutes", *resp.PublicIPAddressPropertiesFormat.IdleTimeoutInMinutes)
}
}

flattenAndSetTags(d, &resp.Tags)
return nil
}
67 changes: 67 additions & 0 deletions azurestack/data_source_public_ip_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package azurestack

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceAzureRMPublicIP_basic(t *testing.T) {
dataSourceName := "data.azurestack_public_ip.test"
ri := acctest.RandInt()

name := fmt.Sprintf("acctestpublicip-%d", ri)
resourceGroupName := fmt.Sprintf("acctestRG-%d", ri)

config := testAccDataSourceAzureRMPublicIPBasic(name, resourceGroupName, ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureStackPublicIpDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "name", name),
resource.TestCheckResourceAttr(dataSourceName, "resource_group_name", resourceGroupName),
resource.TestCheckResourceAttr(dataSourceName, "domain_name_label", fmt.Sprintf("acctest-%d", ri)),
resource.TestCheckResourceAttr(dataSourceName, "idle_timeout_in_minutes", "30"),
resource.TestCheckResourceAttrSet(dataSourceName, "fqdn"),
resource.TestCheckResourceAttrSet(dataSourceName, "ip_address"),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "test"),
),
},
},
})
}

func testAccDataSourceAzureRMPublicIPBasic(name string, resourceGroupName string, rInt int, location string) string {
return fmt.Sprintf(`
resource "azurestack_resource_group" "test" {
name = "%s"
location = "%s"
}
resource "azurestack_public_ip" "test" {
name = "%s"
location = "${azurestack_resource_group.test.location}"
resource_group_name = "${azurestack_resource_group.test.name}"
public_ip_address_allocation = "static"
domain_name_label = "acctest-%d"
idle_timeout_in_minutes = 30
tags {
environment = "test"
}
}
data "azurestack_public_ip" "test" {
name = "${azurestack_public_ip.test.name}"
resource_group_name = "${azurestack_resource_group.test.name}"
}
`, resourceGroupName, location, name, rInt)
}
96 changes: 96 additions & 0 deletions azurestack/data_source_subnet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package azurestack

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurestack/azurestack/utils"
)

func dataSourceArmSubnet() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmSubnetRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.NoZeroValues,
},

"virtual_network_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.NoZeroValues,
},

"resource_group_name": resourceGroupNameForDataSourceSchema(),

"address_prefix": {
Type: schema.TypeString,
Computed: true,
},

"network_security_group_id": {
Type: schema.TypeString,
Computed: true,
},

"route_table_id": {
Type: schema.TypeString,
Computed: true,
},

"ip_configurations": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
},
}
}

func dataSourceArmSubnetRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).subnetClient
ctx := meta.(*ArmClient).StopContext

name := d.Get("name").(string)
virtualNetworkName := d.Get("virtual_network_name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resourceGroup, virtualNetworkName, name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Subnet %q (Virtual Network %q / Resource Group %q) was not found", name, resourceGroup, virtualNetworkName)
}
return fmt.Errorf("Error making Read request on Azure Subnet %q: %+v", name, err)
}
d.SetId(*resp.ID)

d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
d.Set("virtual_network_name", virtualNetworkName)

if props := resp.SubnetPropertiesFormat; props != nil {
d.Set("address_prefix", props.AddressPrefix)

if props.NetworkSecurityGroup != nil {
d.Set("network_security_group_id", props.NetworkSecurityGroup.ID)
} else {
d.Set("network_security_group_id", "")
}

if props.RouteTable != nil {
d.Set("route_table_id", props.RouteTable.ID)
} else {
d.Set("route_table_id", "")
}

if err := d.Set("ip_configurations", flattenSubnetIPConfigurations(props.IPConfigurations)); err != nil {
return err
}
}

return nil
}
Loading

0 comments on commit 88044d5

Please sign in to comment.