Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtual_machine_scale_set datasource - support network_interfaces #10585

160 changes: 156 additions & 4 deletions azurerm/internal/services/compute/virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,47 @@ func VirtualMachineScaleSetNetworkInterfaceSchema() *schema.Schema {
}
}

func VirtualMachineScaleSetNetworkInterfaceSchemaForDataSource() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},

"ip_configuration": virtualMachineScaleSetIPConfigurationSchemaForDataSource(),

"dns_servers": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"enable_accelerated_networking": {
Type: schema.TypeBool,
Computed: true,
},
"enable_ip_forwarding": {
Type: schema.TypeBool,
Computed: true,
},
"network_security_group_id": {
Type: schema.TypeString,
Computed: true,
},
"primary": {
Type: schema.TypeBool,
Computed: true,
},
},
},
}
}

func virtualMachineScaleSetIPConfigurationSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Expand Down Expand Up @@ -280,6 +321,70 @@ func virtualMachineScaleSetIPConfigurationSchema() *schema.Schema {
}
}

func virtualMachineScaleSetIPConfigurationSchemaForDataSource() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Required: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to Computed: true?

Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},

"application_gateway_backend_address_pool_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"application_security_group_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"load_balancer_backend_address_pool_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"load_balancer_inbound_nat_rules_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"primary": {
Type: schema.TypeBool,
Computed: true,
},

"public_ip_address": virtualMachineScaleSetPublicIPAddressSchemaForDataSource(),

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

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

func virtualMachineScaleSetPublicIPAddressSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Expand Down Expand Up @@ -340,6 +445,53 @@ func virtualMachineScaleSetPublicIPAddressSchema() *schema.Schema {
}
}

func virtualMachineScaleSetPublicIPAddressSchemaForDataSource() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to Computed: true?

Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},

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

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

"ip_tag": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tag": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

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

func ExpandVirtualMachineScaleSetNetworkInterface(input []interface{}) (*[]compute.VirtualMachineScaleSetNetworkConfiguration, error) {
output := make([]compute.VirtualMachineScaleSetNetworkConfiguration, 0)

Expand Down Expand Up @@ -666,10 +818,10 @@ func flattenVirtualMachineScaleSetIPConfiguration(input compute.VirtualMachineSc
"public_ip_address": publicIPAddresses,
"subnet_id": subnetId,
"version": string(input.PrivateIPAddressVersion),
"application_gateway_backend_address_pool_ids": schema.NewSet(schema.HashString, applicationGatewayBackendAddressPoolIds),
"application_security_group_ids": schema.NewSet(schema.HashString, applicationSecurityGroupIds),
"load_balancer_backend_address_pool_ids": schema.NewSet(schema.HashString, loadBalancerBackendAddressPoolIds),
"load_balancer_inbound_nat_rules_ids": schema.NewSet(schema.HashString, loadBalancerInboundNatRuleIds),
"application_gateway_backend_address_pool_ids": applicationGatewayBackendAddressPoolIds,
"application_security_group_ids": applicationSecurityGroupIds,
"load_balancer_backend_address_pool_ids": loadBalancerBackendAddressPoolIds,
"load_balancer_inbound_nat_rules_ids": loadBalancerInboundNatRuleIds,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func dataSourceVirtualMachineScaleSet() *schema.Resource {

"location": azure.SchemaLocationForDataSource(),

"network_interface": VirtualMachineScaleSetNetworkInterfaceSchemaForDataSource(),

"identity": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -82,6 +84,15 @@ func dataSourceVirtualMachineScaleSetRead(d *schema.ResourceData, meta interface
}
d.SetId(*resp.ID)

if profile := resp.VirtualMachineProfile; profile != nil {
if nwProfile := profile.NetworkProfile; nwProfile != nil {
flattenedNics := FlattenVirtualMachineScaleSetNetworkInterface(nwProfile.NetworkInterfaceConfigurations)
if err := d.Set("network_interface", flattenedNics); err != nil {
return fmt.Errorf("Error setting `network_interface`: %+v", err)
}
}
}

identity, err := FlattenVirtualMachineScaleSetIdentity(resp.Identity)
if err != nil {
return err
Expand Down
36 changes: 36 additions & 0 deletions website/docs/d/virtual_machine_scale_set.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `identity` - A `identity` block as defined below.

* `network_interface` - A list of `network_interface` blocks as defined below.

---

A `identity` block exports the following:
Expand All @@ -49,6 +51,40 @@ A `identity` block exports the following:

* `type` - The identity type of the Managed Identity assigned to the Virtual Machine Scale Set.

---

`network_profile` exports the following:

* `name` - The name of the network interface configuration.
* `primary` - Whether network interfaces created from the network interface configuration will be the primary NIC of the VM.
* `ip_configuration` - An ip_configuration block as documented below.
* `accelerated_networking` - Whether to enable accelerated networking or not.
* `dns_settings` - A dns_settings block as documented below.
* `ip_forwarding` - Whether IP forwarding is enabled on this NIC.
* `network_security_group_id` - The identifier for the network security group.

`dns_settings` exports the following:

* `dns_servers` - The dns servers in use.

`ip_configuration` exports the following:

* `name` - The name of the IP configuration.
* `subnet_id` - The the identifier of the subnet.
* `application_gateway_backend_address_pool_ids` - An array of references to backend address pools of application gateways.
* `load_balancer_backend_address_pool_ids` - An array of references to backend address pools of load balancers.
* `load_balancer_inbound_nat_rules_ids` - An array of references to inbound NAT pools for load balancers.
* `primary` - If this ip_configuration is the primary one.
* `application_security_group_ids` - The application security group IDs to use.
* `public_ip_address_configuration` - The virtual machines scale set IP Configuration's PublicIPAddress configuration. The `public_ip_address_configuration` is documented below.

`public_ip_address_configuration` exports the following:

* `name` - The name of the public ip address configuration
* `idle_timeout` - The idle timeout in minutes.
* `domain_name_label` - The domain name label for the dns settings.


## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
Expand Down