-
Notifications
You must be signed in to change notification settings - Fork 80
/
azure_mysql_server.rb
103 lines (92 loc) · 4.46 KB
/
azure_mysql_server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require "azure_generic_resource"
class AzureMysqlServer < AzureGenericResource
name "azure_mysql_server"
desc "Verifies settings for an Azure My SQL Server"
example <<-EXAMPLE
describe azurerm_mysql_server(resource_group: 'example', server_name: 'vm-name') do
it { should have_monitoring_agent_installed }
end
EXAMPLE
def initialize(opts = {})
# Options should be Hash type. Otherwise Ruby will raise an error when we try to access the keys.
raise ArgumentError, "Parameters must be provided in an Hash object." unless opts.is_a?(Hash)
# Azure REST API endpoint URL format for the resource:
# GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/
# Microsoft.DBforMySQL/servers/{serverName}?api-version=2017-12-01
#
# The dynamic part that has to be created in this resource:
# Microsoft.DBforMySQL/servers/{serverName}?api-version=2017-12-01
#
# Parameters acquired from environment variables:
# - {subscriptionId} => Required parameter. It will be acquired by the backend from environment variables.
#
# For parameters applicable to all resources, see project's README.
#
# User supplied parameters:
# - resource_group => Required parameter unless `resource_id` is provided. {resourceGroupName}
# - name => Required parameter unless `resource_id` is provided. Name of the resource to be tested.
# - resource_id => Optional parameter. If exists, other resource related parameters must not be provided.
# In the following format:
# /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/
# Microsoft.DBforMySQL/servers/{serverName}
# - api_version => Optional parameter. The latest version will be used unless provided.
#
# **`resource_group`, (resource) `name` and `resource_id` will be validated in the backend appropriately.
# We don't have to do anything here.
#
# Following resource parameters have to be defined/created here.
# resource_provider => Microsoft.Network/virtualNetworks
# The `specific_resource_constraint` method will validate the user input
# not to accept a different `resource_provider`.
#
# `resource_provider` has to be defined first since it does the first validation on user-supplied input.
opts[:resource_provider] = specific_resource_constraint("Microsoft.DBforMySQL/servers", opts)
opts[:resource_identifiers] = %i(server_name)
opts[:allowed_parameters] = %i(firewall_rules_api_version)
# static_resource parameter must be true for setting the resource_provider in the backend.
super(opts, true)
@opts[:firewall_rules_api_version] ||= "latest"
end
def to_s
super(AzureMysqlServer)
end
# Resource specific methods can be created.
# `return unless exists?` is necessary to prevent any unforeseen Ruby error.
# Following methods are created to provide the same functionality with the current resource pack >>>>
# @see https://github.com/inspec/inspec-azure
# Azure Rest API endpoint for MySql firewall rules
# GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/
# Microsoft.DBforMySQL/servers/{serverName}/firewallRules?api-version=2017-12-01
#
# @see AzureKeyVault#diagnostic_settings for how to use #additional_resource_properties method.
#
def firewall_rules
return unless exists?
additional_resource_properties(
{
property_name: "firewall_rules",
property_endpoint: "#{id}/firewallRules",
api_version: @opts[:firewall_rules_api_version],
},
)
end
end
# Provide the same functionality under the old resource name.
# This is for backward compatibility.
class AzurermMysqlServer < AzureMysqlServer
name "azurerm_mysql_server"
desc "Verifies settings for an Azure My SQL Server"
example <<-EXAMPLE
describe azurerm_mysql_server(resource_group: 'example', server_name: 'vm-name') do
it { should have_monitoring_agent_installed }
end
EXAMPLE
def initialize(opts = {})
Inspec::Log.warn Helpers.resource_deprecation_message(@__resource_name__, AzureMysqlServer.name)
# Options should be Hash type. Otherwise Ruby will raise an error when we try to access the keys.
raise ArgumentError, "Parameters must be provided in an Hash object." unless opts.is_a?(Hash)
# For backward compatibility.
opts[:api_version] ||= "2017-12-01"
super
end
end