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

azurerm_bastion_host - support for scale_units #14968

Merged
merged 5 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 16 additions & 1 deletion internal/services/network/bastion_host_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ func resourceBastionHost() *pluginsdk.Resource {
},
},

"scale_units": {
Type: pluginsdk.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(2, 50),
Default: 2,
},

"sku": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -110,6 +117,12 @@ func resourceBastionHostCreateUpdate(d *pluginsdk.ResourceData, meta interface{}
id := parse.NewBastionHostID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
location := azure.NormalizeLocation(d.Get("location").(string))
t := d.Get("tags").(map[string]interface{})
scaleUnits := d.Get("scale_units").(int)
sku := d.Get("sku").(string)

if scaleUnits > 2 && sku == string(network.BastionHostSkuNameBasic) {
return fmt.Errorf("`scale_units` only can be changed when `sku` is `Standard`. `scale_units` is always `2` when `sku` is `Basic`")
}

if d.IsNewResource() {
existing, err := client.Get(ctx, id.ResourceGroup, id.Name)
Expand All @@ -128,9 +141,10 @@ func resourceBastionHostCreateUpdate(d *pluginsdk.ResourceData, meta interface{}
Location: &location,
BastionHostPropertiesFormat: &network.BastionHostPropertiesFormat{
IPConfigurations: expandBastionHostIPConfiguration(d.Get("ip_configuration").([]interface{})),
ScaleUnits: utils.Int32(int32(d.Get("scale_units").(int))),
},
Sku: &network.Sku{
Name: network.BastionHostSkuName(d.Get("sku").(string)),
Name: network.BastionHostSkuName(sku),
},
Tags: tags.Expand(t),
}
Expand Down Expand Up @@ -182,6 +196,7 @@ func resourceBastionHostRead(d *pluginsdk.ResourceData, meta interface{}) error

if props := resp.BastionHostPropertiesFormat; props != nil {
d.Set("dns_name", props.DNSName)
d.Set("scale_units", props.ScaleUnits)

if ipConfigs := props.IPConfigurations; ipConfigs != nil {
if err := d.Set("ip_configuration", flattenBastionHostIPConfiguration(ipConfigs)); err != nil {
Expand Down
69 changes: 69 additions & 0 deletions internal/services/network/bastion_host_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ func TestAccBastionHost_requiresImport(t *testing.T) {
})
}

func TestAccBastionHost_scaleUnits(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_bastion_host", "test")
r := BastionHostResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.scaleUnits(data, 3),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
{
Config: r.scaleUnits(data, 5),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
})
}

func (BastionHostResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.BastionHostID(state.ID)
if err != nil {
Expand Down Expand Up @@ -255,3 +275,52 @@ resource "azurerm_bastion_host" "import" {
}
`, r.basic(data))
}

func (BastionHostResource) scaleUnits(data acceptance.TestData, scaleUnits int) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-bastion-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctestVNet%s"
address_space = ["192.168.1.0/24"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_subnet" "test" {
name = "AzureBastionSubnet"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefix = "192.168.1.224/27"
}

resource "azurerm_public_ip" "test" {
name = "acctestBastionPIP%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
allocation_method = "Static"
sku = "Standard"
}

resource "azurerm_bastion_host" "test" {
name = "acctestBastion%s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "Standard"
scale_units = %d

ip_configuration {
name = "ip-configuration"
subnet_id = azurerm_subnet.test.id
public_ip_address_id = azurerm_public_ip.test.id
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomString, scaleUnits)
}
4 changes: 4 additions & 0 deletions website/docs/r/bastion_host.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ The following arguments are supported:

* `ip_configuration` - (Required) A `ip_configuration` block as defined below.

* `scale_units` - (Optional) The number of scale units with which to provision the Bastion Host. Possible values are between `2` and `50`. Defaults to `2`.

~> **Note:** `scale_units` only can be changed when `sku` is `Standard`. `scale_units` is always `2` when `sku` is `Basic`.

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

---
Expand Down