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

Resource Renaming/Duplication: azurerm_monitor_autoscale_setting / azurerm_log_analytics_linked_service #2768

Merged
merged 17 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
37965f6
New Resource: `azurerm_monitor_autoscale_setting`
tombuildsstuff Jan 24, 2019
5521dfe
Updating to include the changes in #2760
tombuildsstuff Jan 25, 2019
f5ee333
documenting the replacement monitor metric alert rule resources
tombuildsstuff Jan 25, 2019
f4d27de
Updating the deprecation message for the metric_alertrule resource
tombuildsstuff Jan 25, 2019
e3cd9bf
refactoring the `azurerm_monitor_metric_alertrule` resource
tombuildsstuff Jan 25, 2019
30ab72f
cdn_profile: switching to use the enum
tombuildsstuff Jan 25, 2019
1617314
r/application_gateway: deprecating the `fqdn_list` and `ip_address_li…
tombuildsstuff Jan 25, 2019
10eaaa9
r/log_analytics_workspace_linked_service: deprecating the `resource_i…
tombuildsstuff Jan 25, 2019
a41c6ed
Newly renamed resource: `azurerm_log_analtyics_linked_service
tombuildsstuff Jan 25, 2019
0e01027
Removing `oms` from the highlight name
tombuildsstuff Jan 25, 2019
c1f3829
Deprecating the older `azurerm_log_analytics_workspace_linked_service…
tombuildsstuff Jan 25, 2019
c681476
renaming the `renaming resources` guide
tombuildsstuff Jan 25, 2019
74f6f30
Adding the deprecation message to the `log_analytics_workspace_linked…
tombuildsstuff Jan 25, 2019
847de4b
PostgreSQL Server: support for 10/10.0/10.2
tombuildsstuff Jan 25, 2019
7039eaf
`azurerm_servicebus_queue`: ensuring deprecated fields are marked as …
tombuildsstuff Jan 25, 2019
b323abc
Adding some additional comments
tombuildsstuff Jan 25, 2019
1197545
fixing issues from code review
tombuildsstuff Jan 28, 2019
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
2 changes: 2 additions & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_lb": resourceArmLoadBalancer(),
"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
"azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(),
"azurerm_log_analytics_linked_service": resourceArmLogAnalyticsLinkedService(),
"azurerm_log_analytics_workspace_linked_service": resourceArmLogAnalyticsWorkspaceLinkedService(),
"azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace(),
"azurerm_logic_app_action_custom": resourceArmLogicAppActionCustom(),
Expand All @@ -257,6 +258,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_mariadb_database": resourceArmMariaDbDatabase(),
"azurerm_mariadb_server": resourceArmMariaDbServer(),
"azurerm_metric_alertrule": resourceArmMetricAlertRule(),
"azurerm_monitor_autoscale_setting": resourceArmMonitorAutoScaleSetting(),
"azurerm_monitor_action_group": resourceArmMonitorActionGroup(),
"azurerm_monitor_activity_log_alert": resourceArmMonitorActivityLogAlert(),
"azurerm_monitor_diagnostic_setting": resourceArmMonitorDiagnosticSetting(),
Expand Down
51 changes: 46 additions & 5 deletions azurerm/resource_arm_application_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,52 @@ func resourceArmApplicationGateway() *schema.Resource {
Required: true,
},

// TODO: ditch the suffix `_list` in the future
"fqdn_list": {
"fqdns": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MinItems: 1,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

// TODO: ditch the suffix `_list` in the future
"ip_address_list": {
"ip_addresses": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MinItems: 1,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validate.IPv4Address,
},
},

// TODO: remove in 2.0
"fqdn_list": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Deprecated: "`fqdn_list` has been deprecated in favour of the `fqdns` field",
MinItems: 1,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

// TODO: remove in 2.0
"ip_address_list": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Deprecated: "`ip_address_list` has been deprecated in favour of the `ip_addresses` field",
MinItems: 1,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validate.IPv4Address,
},
},

"id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -1050,12 +1075,24 @@ func expandApplicationGatewayBackendAddressPools(d *schema.ResourceData) *[]netw
v := raw.(map[string]interface{})
backendAddresses := make([]network.ApplicationGatewayBackendAddress, 0)

for _, ip := range v["ip_address_list"].([]interface{}) {
for _, ip := range v["fqdns"].([]interface{}) {
backendAddresses = append(backendAddresses, network.ApplicationGatewayBackendAddress{
Fqdn: utils.String(ip.(string)),
})
}
for _, ip := range v["ip_addresses"].([]interface{}) {
backendAddresses = append(backendAddresses, network.ApplicationGatewayBackendAddress{
IPAddress: utils.String(ip.(string)),
})
}

// TODO: remove in 2.0
for _, ip := range v["ip_address_list"].([]interface{}) {
backendAddresses = append(backendAddresses, network.ApplicationGatewayBackendAddress{
IPAddress: utils.String(ip.(string)),
})
}
// TODO: remove in 2.0
for _, ip := range v["fqdn_list"].([]interface{}) {
backendAddresses = append(backendAddresses, network.ApplicationGatewayBackendAddress{
Fqdn: utils.String(ip.(string)),
Expand Down Expand Up @@ -1099,6 +1136,10 @@ func flattenApplicationGatewayBackendAddressPools(input *[]network.ApplicationGa
}

output := map[string]interface{}{
"fqdns": fqdnList,
"ip_addresses": ipAddressList,

// TODO: deprecated - remove in 2.0
"ip_address_list": ipAddressList,
"fqdn_list": fqdnList,
}
Expand Down
7 changes: 7 additions & 0 deletions azurerm/resource_arm_autoscale_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import (

func resourceArmAutoScaleSetting() *schema.Resource {
return &schema.Resource{
DeprecationMessage: `The 'azurerm_autoscale_setting' resource is deprecated in favour of the renamed version 'azurerm_monitor_autoscale_setting'.

Information on migrating to the renamed resource can be found here: https://terraform.io/docs/providers/azurerm/guides/migrating-between-renamed-resources.html

As such the existing 'azurerm_autoscale_setting' resource is deprecated and will be removed in the next major version of the AzureRM Provider (2.0).
`,

Create: resourceArmAutoScaleSettingCreateUpdate,
Read: resourceArmAutoScaleSettingRead,
Update: resourceArmAutoScaleSettingCreateUpdate,
Expand Down
3 changes: 1 addition & 2 deletions azurerm/resource_arm_cdn_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ func resourceArmCdnProfile() *schema.Resource {
string(cdn.StandardAkamai),
string(cdn.StandardChinaCdn),
string(cdn.StandardVerizon),
// TODO: replace this with an SDK constant once available
"Standard_Microsoft",
string(cdn.StandardMicrosoft),
string(cdn.PremiumVerizon),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
Expand Down
232 changes: 232 additions & 0 deletions azurerm/resource_arm_log_analytics_linked_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
package azurerm

import (
"fmt"
"log"

"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/operationalinsights"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"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/utils"
)

/*
TODO: refactor this:

* resource_group_name/workspace_name can become case-sensitive
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
*/
func resourceArmLogAnalyticsLinkedService() *schema.Resource {
return &schema.Resource{
Create: resourceArmLogAnalyticsLinkedServiceCreateUpdate,
Read: resourceArmLogAnalyticsLinkedServiceRead,
Update: resourceArmLogAnalyticsLinkedServiceCreateUpdate,
Delete: resourceArmLogAnalyticsLinkedServiceDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"resource_group_name": resourceGroupNameDiffSuppressSchema(),

"workspace_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validateAzureRmLogAnalyticsWorkspaceName,
},

"linked_service_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "automation",
ValidateFunc: validation.StringInSlice([]string{
"automation",
}, false),
},

"resource_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: azure.ValidateResourceID,
},

"linked_service_properties": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"resource_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateResourceID,
ConflictsWith: []string{
// this is the top-level field, not this one
"resource_id",
},
},
},
},
},

// Exported properties
"name": {
Type: schema.TypeString,
Computed: true,
},

"tags": tagsSchema(),
},
}
}

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

log.Printf("[INFO] preparing arguments for AzureRM Log Analytics Linked Services creation.")

resGroup := d.Get("resource_group_name").(string)
workspaceName := d.Get("workspace_name").(string)
lsName := d.Get("linked_service_name").(string)

if requireResourcesToBeImported && d.IsNewResource() {
existing, err := client.Get(ctx, resGroup, workspaceName, lsName)
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("Error checking for presence of existing Linked Service %q (Workspace %q / Resource Group %q): %s", lsName, workspaceName, resGroup, err)
}
}

if existing.ID != nil && *existing.ID != "" {
return tf.ImportAsExistsError("azurerm_log_analytics_linked_service", *existing.ID)
}
}

resourceId := d.Get("resource_id").(string)
if resourceId == "" {
props := d.Get("linked_service_properties").(map[string]interface{})
resourceId = props["resource_id"].(string)
if resourceId == "" {
return fmt.Errorf("A `resource_id` must be specified either using the `resource_id` field at the top level or within the `linked_service_properties` block")
}
}
tags := d.Get("tags").(map[string]interface{})

parameters := operationalinsights.LinkedService{
LinkedServiceProperties: &operationalinsights.LinkedServiceProperties{
ResourceID: utils.String(resourceId),
},
Tags: expandTags(tags),
}

if _, err := client.CreateOrUpdate(ctx, resGroup, workspaceName, lsName, parameters); err != nil {
return fmt.Errorf("Error creating Linked Service %q (Workspace %q / Resource Group %q): %+v", lsName, workspaceName, resGroup, err)
}

read, err := client.Get(ctx, resGroup, workspaceName, lsName)
if err != nil {
return fmt.Errorf("Error retrieving Linked Service %q (Worksppce %q / Resource Group %q): %+v", lsName, workspaceName, resGroup, err)
}
if read.ID == nil {
return fmt.Errorf("Cannot read Linked Service %q (Workspace %q / Resource Group %q) ID", lsName, workspaceName, resGroup)
}

d.SetId(*read.ID)

return resourceArmLogAnalyticsLinkedServiceRead(d, meta)
}

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

id, err := parseAzureResourceID(d.Id())
if err != nil {
return err
}

resGroup := id.ResourceGroup
workspaceName := id.Path["workspaces"]
lsName := id.Path["linkedServices"]

resp, err := client.Get(ctx, resGroup, workspaceName, lsName)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
return nil
}
return fmt.Errorf("Error making Read request on AzureRM Log Analytics Linked Service '%s': %+v", lsName, err)
}
if resp.ID == nil {
d.SetId("")
return nil
}

d.Set("name", resp.Name)
d.Set("resource_group_name", resGroup)
d.Set("workspace_name", workspaceName)
d.Set("linked_service_name", lsName)

if props := resp.LinkedServiceProperties; props != nil {
d.Set("resource_id", props.ResourceID)
}

linkedServiceProperties := flattenLogAnalyticsLinkedServiceProperties(resp.LinkedServiceProperties)
if err := d.Set("linked_service_properties", linkedServiceProperties); err != nil {
return fmt.Errorf("Error setting `linked_service_properties`: %+v", err)
}

flattenAndSetTags(d, resp.Tags)
return nil
}

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

id, err := parseAzureResourceID(d.Id())
if err != nil {
return err
}

resGroup := id.ResourceGroup
workspaceName := id.Path["workspaces"]
lsName := id.Path["linkedServices"]

resp, err := client.Delete(ctx, resGroup, workspaceName, lsName)
if err != nil {
if utils.ResponseWasNotFound(resp) {
return nil
}

return fmt.Errorf("Error deleting Linked Service %q (Workspace %q / Resource Group %q): %+v", lsName, workspaceName, resGroup, err)
}

return nil
}

func flattenLogAnalyticsLinkedServiceProperties(input *operationalinsights.LinkedServiceProperties) interface{} {
if input == nil {
return []interface{}{}
}

properties := make(map[string]interface{})

// resource id linked service
if resourceID := input.ResourceID; resourceID != nil {
properties["resource_id"] = interface{}(*resourceID)
}

return interface{}(properties)
}
Loading