Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops committed Sep 1, 2020
1 parent ab974d5 commit 603ee9b
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 45 deletions.
2 changes: 1 addition & 1 deletion azurerm/internal/features/beta_features_opt_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
// VMSSExtensionsBeta returns whether or not the beta for VMSS Extensions for Linux and Windows VMSS resources is
// enabled.
//
// Set to any non-empty value to enable
// Set the Environment Variable `ARM_PROVIDER_VMSS_EXTENSIONS_BETA` to `true`
func VMSSExtensionsBeta() bool {
return strings.EqualFold(os.Getenv("ARM_PROVIDER_VMSS_EXTENSIONS_BETA"), "true")
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
Expand Down Expand Up @@ -264,15 +265,15 @@ func resourceArmLinuxVirtualMachineScaleSetCreate(d *schema.ResourceData, meta i
resourceGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)

resp, err := client.Get(ctx, resourceGroup, name)
exists, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if !utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error checking for existing Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err)
if !utils.ResponseWasNotFound(exists.Response) {
return fmt.Errorf("checking for existing Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err)
}
}

if !utils.ResponseWasNotFound(resp.Response) {
return tf.ImportAsExistsError("azurerm_linux_virtual_machine_scale_set", *resp.ID)
if !utils.ResponseWasNotFound(exists.Response) {
return tf.ImportAsExistsError("azurerm_linux_virtual_machine_scale_set", *exists.ID)
}

location := azure.NormalizeLocation(d.Get("location").(string))
Expand Down Expand Up @@ -499,7 +500,7 @@ func resourceArmLinuxVirtualMachineScaleSetCreate(d *schema.ResourceData, meta i
log.Printf("[DEBUG] Virtual Machine Scale Set %q (Resource Group %q) was created", name, resourceGroup)

log.Printf("[DEBUG] Retrieving Virtual Machine Scale Set %q (Resource Group %q)..", name, resourceGroup)
resp, err = client.Get(ctx, resourceGroup, name)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ func expandVirtualMachineScaleSetExtensions(input []interface{}) (*compute.Virtu

func flattenVirtualMachineScaleSetExtensions(input *compute.VirtualMachineScaleSetExtensionProfile, d *schema.ResourceData) ([]map[string]interface{}, error) {
result := make([]map[string]interface{}, 0)
if input == nil {
if input == nil || input.Extensions == nil {
return result, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func importVirtualMachineScaleSet(osType compute.OperatingSystemTypes, resourceT
d.Set("extension", updatedExtensions)
}
}
} else {
d.Set("extension", map[string]interface{}{})
}

return []*schema.ResourceData{d}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute/parse"
computeValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
Expand Down Expand Up @@ -281,15 +282,15 @@ func resourceArmWindowsVirtualMachineScaleSetCreate(d *schema.ResourceData, meta
resourceGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)

resp, err := client.Get(ctx, resourceGroup, name)
exists, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if !utils.ResponseWasNotFound(resp.Response) {
if !utils.ResponseWasNotFound(exists.Response) {
return fmt.Errorf("Error checking for existing Windows Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err)
}
}

if !utils.ResponseWasNotFound(resp.Response) {
return tf.ImportAsExistsError("azurerm_windows_virtual_machine_scale_set", *resp.ID)
if !utils.ResponseWasNotFound(exists.Response) {
return tf.ImportAsExistsError("azurerm_windows_virtual_machine_scale_set", *exists.ID)
}

location := azure.NormalizeLocation(d.Get("location").(string))
Expand Down Expand Up @@ -526,7 +527,7 @@ func resourceArmWindowsVirtualMachineScaleSetCreate(d *schema.ResourceData, meta
log.Printf("[DEBUG] Virtual Machine Scale Set %q (Resource Group %q) was created", name, resourceGroup)

log.Printf("[DEBUG] Retrieving Virtual Machine Scale Set %q (Resource Group %q)..", name, resourceGroup)
resp, err = client.Get(ctx, resourceGroup, name)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error retrieving Windows Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ data "azurerm_client_config" "current" {
}

resource "azurerm_resource_group" "example" {
name = "example-resources"
name = "${var.prefix}-resources"
location = var.location
}

resource "azurerm_virtual_network" "example" {
name = "example-sf-network"
name = "${var.prefix}-sf-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}

resource "azurerm_subnet" "example" {
name = "example"
name = "${var.prefix}-subnet"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.2.0/24"]
}

resource "azurerm_storage_account" "example" {
name = "sfexamplesa0123456"
name = "${var.prefix}sfexamplesa"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "azurerm_key_vault" "example" {
name = "examplekv1234560"
name = "${var.prefix}examplekv"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
tenant_id = data.azurerm_client_config.current.tenant_id
Expand Down Expand Up @@ -35,7 +35,7 @@ resource "azurerm_key_vault" "example" {
}

resource "azurerm_key_vault_certificate" "example" {
name = "acctestcert1234560"
name = "${var.prefix}acctestcert"
key_vault_id = azurerm_key_vault.example.id

certificate_policy {
Expand Down Expand Up @@ -79,7 +79,7 @@ resource "azurerm_key_vault_certificate" "example" {
"keyEncipherment",
]

subject = "CN=exampleservicefabric.${var.location}.cloudapp.azure.com"
subject = "CN=${var.prefix}servicefabric.${var.location}.cloudapp.azure.com"
validity_in_months = 12
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
resource "azurerm_public_ip" "example" {
name = "PublicIPForLB"
name = "${var.prefix}PIPForLB"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
allocation_method = "Dynamic"
domain_name_label = "exampleservicefabric"
}

resource "azurerm_lb" "example" {
name = "TestLoadBalancer"
name = "${var.prefix}LoadBalancer"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name

Expand All @@ -20,13 +20,13 @@ resource "azurerm_lb" "example" {
resource "azurerm_lb_backend_address_pool" "example" {
resource_group_name = azurerm_resource_group.example.name
loadbalancer_id = azurerm_lb.example.id
name = "BackEndAddressPool"
name = "${var.prefix}BEAPool"
}

resource "azurerm_lb_nat_pool" "example" {
resource_group_name = azurerm_resource_group.example.name
loadbalancer_id = azurerm_lb.example.id
name = "SFApplicationPool"
name = "${var.prefix}SFApplicationPool"
protocol = "Tcp"
frontend_port_start = 3389
frontend_port_end = 4500
Expand All @@ -37,7 +37,7 @@ resource "azurerm_lb_nat_pool" "example" {
resource "azurerm_lb_rule" "example_tcp" {
resource_group_name = azurerm_resource_group.example.name
loadbalancer_id = azurerm_lb.example.id
name = "LBRuleTcp"
name = "${var.prefix}LBRuleTcp"
protocol = "Tcp"
frontend_port = 19000
backend_port = 19000
Expand All @@ -48,7 +48,7 @@ resource "azurerm_lb_rule" "example_tcp" {
resource "azurerm_lb_rule" "example_http" {
resource_group_name = azurerm_resource_group.example.name
loadbalancer_id = azurerm_lb.example.id
name = "LBRuleHttp"
name = "${var.prefix}LBRuleHttp"
protocol = "Tcp"
frontend_port = 19080
backend_port = 19080
Expand All @@ -59,14 +59,14 @@ resource "azurerm_lb_rule" "example_http" {
resource "azurerm_lb_probe" "example_tcp" {
resource_group_name = azurerm_resource_group.example.name
loadbalancer_id = azurerm_lb.example.id
name = "FabricGatewayProbe"
name = "${var.prefix}SFTcpGatewayProbe"
port = 19000
}

resource "azurerm_lb_probe" "example_http" {
resource_group_name = azurerm_resource_group.example.name
loadbalancer_id = azurerm_lb.example.id
name = "FabricHttpGatewayProbe"
name = "${var.prefix}SFHttpGatewayProbe"
port = 19080
}

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

resource "azurerm_service_fabric_cluster" "example" {
name = "exampleservicefabric"
name = "${var.prefix}servicefabric"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
reliability_level = "Bronze"
upgrade_mode = "Automatic"
vm_image = "Windows"
management_endpoint = "https://exampleservicefabric.${var.location}.cloudapp.azure.com:19080"
management_endpoint = "https://${var.prefix}servicefabric.${var.location}.cloudapp.azure.com:19080"

node_type {
name = "Windows"
Expand All @@ -18,12 +18,12 @@ resource "azurerm_service_fabric_cluster" "example" {


reverse_proxy_certificate {
thumbprint = azurerm_key_vault_certificate.example.thumbprint
thumbprint = azurerm_key_vault_certificate.example.thumbprint
x509_store_name = "My"
}

certificate {
thumbprint = azurerm_key_vault_certificate.example.thumbprint
thumbprint = azurerm_key_vault_certificate.example.thumbprint
x509_store_name = "My"
}

Expand All @@ -34,15 +34,16 @@ resource "azurerm_service_fabric_cluster" "example" {
}

resource "azurerm_windows_virtual_machine_scale_set" "example" {
name = "examplesf"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
sku = "Standard_D1_v2"
instances = azurerm_service_fabric_cluster.example.node_type[0].instance_count
admin_password = "P@55w0rd1234!"
admin_username = "adminuser"
overprovision = false
upgrade_mode = "Automatic"
name = "${var.prefix}examplesf"
computer_name_prefix = var.prefix
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
sku = "Standard_D1_v2"
instances = azurerm_service_fabric_cluster.example.node_type[0].instance_count
admin_password = "P@55w0rd1234!"
admin_username = "adminuser"
overprovision = false
upgrade_mode = "Automatic"


source_image_reference {
Expand Down Expand Up @@ -83,7 +84,7 @@ resource "azurerm_windows_virtual_machine_scale_set" "example" {
}

extension {
name = "ServiceFabricNode"
name = "${var.prefix}ServiceFabricNode"
publisher = "Microsoft.Azure.ServiceFabric"
type = "ServiceFabricNode"
type_handler_version = "1.1"
Expand All @@ -97,7 +98,7 @@ resource "azurerm_windows_virtual_machine_scale_set" "example" {
"enableParallelJobs" = true
"certificate" = {
"commonNames" = [
"exampleservicefabric.${var.location}.cloudapp.azure.com",
"${var.prefix}servicefabric.${var.location}.cloudapp.azure.com",
]
"x509StoreName" = "My"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Example: Service Fabric using Windows VMSS and Self Signed Certificate

### Notes:
* This example requires the use of the VMSS Extensions beta functionality, set `ARM_PROVIDER_VMSS_EXTENSIONS_BETA=1` to enable.
* This example requires the use of the VMSS Extensions beta functionality, set `ARM_PROVIDER_VMSS_EXTENSIONS_BETA=true` to enable.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
variable "prefix" {
description = "The prefix which should be used for all resources in this example"
}

variable "location" {
description = "The Azure Region in which all resources in this example should be created. Use the `Name` value from `az account list-locations -otable` for your chosen region"
default = "westeurope"
Expand Down

0 comments on commit 603ee9b

Please sign in to comment.