puppetlabs / puppetlabs-azure_arm

The Puppet Azure ARM Module
Apache License 2.0
4 stars 16 forks source link

Trying to deploy azure_sql_database results in "Invalid parameter elastic_pool_name" #17

Closed Monual closed 5 years ago

Monual commented 5 years ago

What you expected to happen?

A new Microsoft SQL server to be deployed.

What happened?

Error: Failed to apply catalog: Validation of Azure_sql_database[wre-dellegance-db-copy] failed: Invalid parameterelastic_pool_name(:elastic_pool_name

Anything else we need to know?

"elastic_pool_name" is an optional parameter according to the documentation. I didn't have that parameter in my manifest at all. Yet the module failed because it said a parameter I didn't even supply was invalid.

I tried specifying an elastic_pool_name, just to see what would happen, and got the same error.

Versions:

Error: Failed to apply catalog: Validation of Azure_sql_database[wre-dellegance-db-copy] failed: Invalid parameter elastic_pool_name(:elastic_pool_name) (file: /etc/puppetlabs/code/environments/production/modules/azuretest/manifests/init.pp, line: 54)
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/errors.rb:157:in `fail'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type.rb:639:in `[]'
/opt/puppetlabs/puppet/cache/lib/puppet/type/azure_sql_database.rb:21:in `block (3 levels) in <top (required)>'
/opt/puppetlabs/puppet/cache/lib/puppet/type/azure_sql_database.rb:19:in `each'
/opt/puppetlabs/puppet/cache/lib/puppet/type/azure_sql_database.rb:19:in `block (2 levels) in <top (required)>'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type.rb:2399:in `initialize'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource.rb:478:in `new'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource.rb:478:in `to_ral'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/catalog.rb:629:in `block in to_catalog'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/catalog.rb:621:in `each'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/catalog.rb:621:in `to_catalog'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/catalog.rb:515:in `to_ral'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/configurer.rb:111:in `block in convert_catalog'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:518:in `block in thinmark'
/opt/puppetlabs/puppet/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:517:in `thinmark'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/configurer.rb:105:in `convert_catalog'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/configurer.rb:168:in `prepare_and_retrieve_catalog'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/configurer.rb:341:in `run_internal'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/configurer.rb:239:in `block in run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/context.rb:65:in `override'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb:252:in `override'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/configurer.rb:217:in `run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/agent.rb:59:in `block (5 levels) in run'
/opt/puppetlabs/puppet/lib/ruby/2.5.0/timeout.rb:93:in `block in timeout'
/opt/puppetlabs/puppet/lib/ruby/2.5.0/timeout.rb:103:in `timeout'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/agent.rb:58:in `block (4 levels) in run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/agent/locker.rb:21:in `lock'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/agent.rb:52:in `block (3 levels) in run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/agent.rb:130:in `with_client'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/agent.rb:49:in `block (2 levels) in run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/agent.rb:87:in `run_in_fork'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/agent.rb:48:in `block in run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application.rb:179:in `controlled_run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/agent.rb:46:in `run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application/agent.rb:372:in `onetime'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application/agent.rb:350:in `run_command'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application.rb:382:in `block in run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:671:in `exit_on_fail'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application.rb:382:in `run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/command_line.rb:135:in `run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/command_line.rb:73:in `execute'
/opt/puppetlabs/puppet/bin/puppet:5:in `<main>'
root@puppet:~# puppet --version
6.0.5
root@puppet:~# facter os
{
  architecture => "amd64",
  distro => {
    codename => "bionic",
    description => "Ubuntu 18.04.2 LTS",
    id => "Ubuntu",
    release => {
      full => "18.04",
      major => "18.04"
    }
  },
  family => "Debian",
  hardware => "x86_64",
  name => "Ubuntu",
  release => {
    full => "18.04",
    major => "18.04"
  },
  selinux => {
    enabled => false
  }
}
root@puppet:~# puppet module list
/etc/puppetlabs/code/environments/production/site-modules
├── profile (???)
└── role (???)
/etc/puppetlabs/code/environments/production/modules
├── azuretest (???)
├── puppetlabs-azure_arm (v0.2.1)
└── puppetlabs-stdlib (v5.2.0)
/opt/puppetlabs/puppet/modules
├── puppetlabs-facter_task (v0.4.0)
├── puppetlabs-package (v0.4.1)
├── puppetlabs-pe_accounts (v2016.5.0)
├── puppetlabs-pe_bootstrap (v0.3.0)
├── puppetlabs-pe_concat (v1.1.1)
├── puppetlabs-pe_hocon (v2019.0.0)
├── puppetlabs-pe_infrastructure (v2018.1.0)
├── puppetlabs-pe_inifile (v1.1.3)
├── puppetlabs-pe_install (v2018.1.0)
├── puppetlabs-pe_java_ks (v2016.4.0)
├── puppetlabs-pe_nginx (v2017.1.0)
├── puppetlabs-pe_postgresql (v2016.5.0)
├── puppetlabs-pe_puppet_authorization (v2016.2.0)
├── puppetlabs-pe_r10k (v2016.2.0)
├── puppetlabs-pe_razor (v1.1.0)
├── puppetlabs-pe_repo (v2018.1.0)
├── puppetlabs-pe_staging (v0.3.3)
├── puppetlabs-pe_support_script (v2.10.0)
├── puppetlabs-puppet_conf (v0.3.0)
├── puppetlabs-puppet_enterprise (v2018.1.0)
└── puppetlabs-service (v0.5.0)

This one has me stumped, although I haven't done a deep dive into the code yet.

sheenaajay commented 5 years ago

Thank you @Monual for your contribution.Will be taking a look on the issue.Thank you.

Monual commented 5 years ago

Some additional commentary while I was trying to get this to work:

lib/puppet/type/azure_sql_database.rb lists these required properties:

required_properties = [
      :location,
      :elastic_pool_name,
      :parameters,
      :recommended_elastic_pool_name,
      :resource_group_name,
      :server_name,
 ]

This is wrong in multiple ways. elastic_pool_name and recommended_elastic_pool_name are not required. However, subscription_id, and api_version_name are required.

Also, elastic_pool_name and recommended_elastic_pool_name weren't even defined as properties. I had to add the following to azure_sql_database.rb::

  newproperty(:elastic_pool_name) do
    desc "Elastic Pool Name."
    validate do |value|
      true
    end
  end
  newproperty(:recommended_elastic_pool_name) do
    desc "Recommended Elastic Pool Name."
    validate do |value|
      true
    end
  end

Also, there are two lines in lib/puppet/provider/azure_sql_database/azure_sql_database.rb that assume that elastic_pool_name and recommended_elastic_pool_name are required parameters. I changed them from:

self.call_op(path_params, query_params, header_params, body_params, "management.azure.com", "/subscriptions/%{subscription_id}/resourceGroups/%{resource_group_name}/providers/Microsoft.Sql/servers/%{server_name}/elasticPools/%{elastic_pool_name}/databases", "Get", "[application/json]")

self.call_op(path_params, query_params, header_params, body_params, "management.azure.com", "/subscriptions/%{subscription_id}/resourceGroups/%{resource_group_name}/providers/Microsoft.Sql/servers/%{server_name}/recommendedElasticPools/%{recommended_elastic_pool_name}/databases/%{database_name}", "Get", "[application/json]")

to:

defined?(elastic_pool_name) && self.call_op(path_params, query_params, header_params, body_params, "management.azure.com", "/subscriptions/%{subscription_id}/resourceGroups/%{resource_group_name}/providers/Microsoft.Sql/servers/%{server_name}/elasticPools/%{elastic_pool_name}/databases", "Get", "[application/json]")

defined?(recommended_elastic_pool_name) && self.call_op(path_params, query_params, header_params, body_params, "management.azure.com", "/subscriptions/%{subscription_id}/resourceGroups/%{resource_group_name}/providers/Microsoft.Sql/servers/%{server_name}/recommendedElasticPools/%{recommended_elastic_pool_name}/databases/%{database_name}", "Get", "[application/json]")

After I did all of the above, I got my SQL database to deploy.

I will put in a PR, likely tomorrow.

sheenaajay commented 5 years ago

@Monual Thanks a lot for raising the Issue and the PR.The fix is available in the master.Apologies for the delay.