Skip to content

Commit

Permalink
squashed sf create / update to allow AAD update (#3654)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Hawkins authored and mbfrahry committed Jun 13, 2019
1 parent e83c336 commit a133ae3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 78 deletions.
86 changes: 12 additions & 74 deletions azurerm/resource_arm_service_fabric_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (

func resourceArmServiceFabricCluster() *schema.Resource {
return &schema.Resource{
Create: resourceArmServiceFabricClusterCreate,
Create: resourceArmServiceFabricClusterCreateUpdate,
Read: resourceArmServiceFabricClusterRead,
Update: resourceArmServiceFabricClusterUpdate,
Update: resourceArmServiceFabricClusterCreateUpdate,
Delete: resourceArmServiceFabricClusterDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
Expand Down Expand Up @@ -84,24 +84,23 @@ func resourceArmServiceFabricCluster() *schema.Resource {
"azure_active_directory": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tenant_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.UUID,
},
"cluster_application_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.UUID,
},
"client_application_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.UUID,
},
},
},
Expand Down Expand Up @@ -333,7 +332,7 @@ func resourceArmServiceFabricCluster() *schema.Resource {
}
}

func resourceArmServiceFabricClusterCreate(d *schema.ResourceData, meta interface{}) error {
func resourceArmServiceFabricClusterCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).serviceFabric.ClustersClient
ctx := meta.(*ArmClient).StopContext

Expand Down Expand Up @@ -431,67 +430,6 @@ func resourceArmServiceFabricClusterCreate(d *schema.ResourceData, meta interfac
return resourceArmServiceFabricClusterRead(d, meta)
}

func resourceArmServiceFabricClusterUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).serviceFabric.ClustersClient
ctx := meta.(*ArmClient).StopContext

log.Printf("[INFO] preparing arguments for Service Fabric Cluster update.")

resourceGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)
reliabilityLevel := d.Get("reliability_level").(string)
upgradeMode := d.Get("upgrade_mode").(string)
clusterCodeVersion := d.Get("cluster_code_version").(string)
tags := d.Get("tags").(map[string]interface{})

addOnFeaturesRaw := d.Get("add_on_features").(*schema.Set).List()
addOnFeatures := expandServiceFabricClusterAddOnFeatures(addOnFeaturesRaw)

certificateRaw := d.Get("certificate").([]interface{})
certificate := expandServiceFabricClusterCertificate(certificateRaw)

reverseProxyCertificateRaw := d.Get("reverse_proxy_certificate").([]interface{})
reverseProxyCertificate := expandServiceFabricClusterReverseProxyCertificate(reverseProxyCertificateRaw)

clientCertificateThumbprintsRaw := d.Get("client_certificate_thumbprint").([]interface{})
clientCertificateThumbprints := expandServiceFabricClusterClientCertificateThumbprints(clientCertificateThumbprintsRaw)

fabricSettingsRaw := d.Get("fabric_settings").([]interface{})
fabricSettings := expandServiceFabricClusterFabricSettings(fabricSettingsRaw)

nodeTypesRaw := d.Get("node_type").([]interface{})
nodeTypes := expandServiceFabricClusterNodeTypes(nodeTypesRaw)

parameters := servicefabric.ClusterUpdateParameters{
ClusterPropertiesUpdateParameters: &servicefabric.ClusterPropertiesUpdateParameters{
AddOnFeatures: addOnFeatures,
Certificate: certificate,
ReverseProxyCertificate: reverseProxyCertificate,
ClientCertificateThumbprints: clientCertificateThumbprints,
FabricSettings: fabricSettings,
NodeTypes: nodeTypes,
ReliabilityLevel: servicefabric.ReliabilityLevel1(reliabilityLevel),
UpgradeMode: servicefabric.UpgradeMode1(upgradeMode),
},
Tags: expandTags(tags),
}

if clusterCodeVersion != "" {
parameters.ClusterPropertiesUpdateParameters.ClusterCodeVersion = utils.String(clusterCodeVersion)
}

future, err := client.Update(ctx, resourceGroup, name, parameters)
if err != nil {
return fmt.Errorf("Error updating Service Fabric Cluster %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("Error waiting for update of Service Fabric Cluster %q (Resource Group %q): %+v", name, resourceGroup, err)
}

return resourceArmServiceFabricClusterRead(d, meta)
}

func resourceArmServiceFabricClusterRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).serviceFabric.ClustersClient
ctx := meta.(*ArmClient).StopContext
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/service_fabric_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The following arguments are supported:

* `add_on_features` - (Optional) A List of one or more features which should be enabled, such as `DnsService`.

* `azure_active_directory` - (Optional) An `azure_active_directory` block as defined below. Changing this forces a new resource to be created.
* `azure_active_directory` - (Optional) An `azure_active_directory` block as defined below.

* `certificate` - (Optional) A `certificate` block as defined below.

Expand All @@ -85,11 +85,11 @@ The following arguments are supported:

A `azure_active_directory` block supports the following:

* `tenant_id` - (Required) The Azure Active Directory Tenant ID. Changing this forces a new resource to be created.
* `tenant_id` - (Required) The Azure Active Directory Tenant ID.

* `cluster_application_id` - (Required) The Azure Active Directory Cluster Application ID. Changing this forces a new resource to be created.
* `cluster_application_id` - (Required) The Azure Active Directory Cluster Application ID.

* `client_application_id` - (Required) The Azure Active Directory Client ID which should be used for the Client Application. Changing this forces a new resource to be created.
* `client_application_id` - (Required) The Azure Active Directory Client ID which should be used for the Client Application.

---

Expand Down

0 comments on commit a133ae3

Please sign in to comment.