-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into scale-set
- Loading branch information
Showing
26 changed files
with
4,853 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.