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

Added a parameters for LoadBalancer resource #152

Merged
merged 6 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions internal/services/loadbalancer/loadbalancer_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ func loadBalancer() *pluginsdk.Resource {

"resource_group_name": commonschema.ResourceGroupName(),

"sku": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(network.LoadBalancerSkuNameBasic),
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(network.LoadBalancerSkuNameBasic),
}, false),
},

"frontend_ip_configuration": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -121,6 +131,16 @@ func loadBalancer() *pluginsdk.Resource {
Set: pluginsdk.HashString,
},

"outbound_rule_ids": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we ensure these are covered by a test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems in order to appear the outbound rules, it will need a resource azurestack_public_ip_prefix but it is not available at the moment, I can remove the parameter outbound_rule_ids or keep it. What do you think? @katbyte

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can either open a new PR with that resource or add it to this one but that property needs to be be tested to be included here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the parameter because the resource azurestack_public_ip_prefix it's not supported at the current profile.

Type: pluginsdk.TypeSet,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringIsNotEmpty,
},
Set: pluginsdk.HashString,
},

"id": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -192,9 +212,12 @@ func loadBalancerCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error
}

loadBalancer := network.LoadBalancer{
Name: pointer.FromString(id.Name),
Location: pointer.FromString(location.Normalize(d.Get("location").(string))),
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
Name: pointer.FromString(id.Name),
Location: pointer.FromString(location.Normalize(d.Get("location").(string))),
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
Sku: &network.LoadBalancerSku{
Name: network.LoadBalancerSkuName(d.Get("sku").(string)),
},
LoadBalancerPropertiesFormat: &properties,
}

Expand Down Expand Up @@ -235,6 +258,10 @@ func loadBalancerRead(d *pluginsdk.ResourceData, meta interface{}) error {
d.Set("resource_group_name", id.ResourceGroup)
d.Set("location", location.NormalizeNilable(resp.Location))

if sku := resp.Sku; sku != nil {
d.Set("sku", string(sku.Name))
}

if props := resp.LoadBalancerPropertiesFormat; props != nil {
if feipConfigs := props.FrontendIPConfigurations; feipConfigs != nil {
if err := d.Set("frontend_ip_configuration", flattenLoadBalancerFrontendIpConfiguration(feipConfigs)); err != nil {
Expand Down Expand Up @@ -373,6 +400,14 @@ func flattenLoadBalancerFrontendIpConfiguration(ipConfigs *[]network.FrontendIPC
}
}
ipConfig["inbound_nat_rules"] = pluginsdk.NewSet(pluginsdk.HashString, inboundNatRules)

outboundRules := make([]interface{}, 0)
if rules := props.OutboundRules; rules != nil {
for _, rule := range *rules {
outboundRules = append(outboundRules, *rule.ID)
}
}
ipConfig["outbound_rule_ids"] = pluginsdk.NewSet(pluginsdk.HashString, outboundRules)
}

result = append(result, ipConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ resource "azurestack_lb" "test" {
name = "acctestlb-%d"
resource_group_name = azurestack_resource_group.test.name
location = azurestack_resource_group.test.location
sku = "Basic"
katbyte marked this conversation as resolved.
Show resolved Hide resolved

frontend_ip_configuration {
name = "Internal"
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/loadbalancer.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The following arguments are supported:
* `resource_group_name` - (Required) The name of the resource group in which to create the LoadBalancer.
* `location` - (Required) Specifies the supported Azure location where the resource exists.
* `frontend_ip_configuration` - (Optional) A frontend ip configuration block as documented below.
* `sku` - (Optional) The SKU of the Azure Load Balancer. Accepted values are `Basic` and `Standard`. Defaults to `Basic`.

* `tags` - (Optional) A mapping of tags to assign to the resource.

Expand All @@ -64,6 +65,7 @@ The following attributes are exported:
* `id` - The LoadBalancer ID.
* `private_ip_address` - The first private IP address assigned to the load balancer in `frontend_ip_configuration` blocks, if any.
* `private_ip_addresses` - The list of private IP address assigned to the load balancer in `frontend_ip_configuration` blocks, if any.
* `outbound_rules_ids` - The list of IDs outbound rules that use this frontend IP.

## Import

Expand Down