Skip to content
Daniel Berger edited this page May 15, 2018 · 7 revisions

What's an Environment?

An Azure "environment" is just a collection of endpoints that Azure uses to collect various pieces of information for its REST API. You may also see this called a "profile" by Microsoft. The environment that you need depends on your credentials, which in turn can depend on your region. Or, in some cases, whether or not you work for a government entity.

Different environments typically have different sets of supported features. Please check the Azure documentation on each environment for details.

Available Environments

The azure-armrest gem defines an Azure::Armrest::Environment class that you can use to create the environment that you need. As of azure-armrest 0.9.9, there are three available environments that are baked into the gem already.

  • Azure::Armrest::Environment::Public
  • Azure::Armrest::Environment::USGoverment
  • Azure::Armrest::Environment::Germany

By default the azure-armrest gem uses the "Public" environment. This is the most common environment, and so in most cases you will not need to set this explicitly.

Setting Your Environment

If you need to specify a different environment, you pass the :environment option to the Azure::Armrest::Configuration constructor like so:

config = Azure::Armrest::Configuration.new(
  :subscription_id => 'xxx',
  :tenant_id       => 'yyy',
  :client_id       => 'zzz',
  :client_key      => 'abc',
  :environment     => Azure::Armrest::Environment::Germany
)

Creating A Custom Environment

If you need to create a custom environment for your use, e.g. Azure Stack, you can create and assign one like so:

env = Azure::Armrest::Environment.new(
  :name                          => 'TestStack',
  :active_directory_authority    => 'https://login.windows.net/',
  :active_directory_resource_id  => 'https://management.poc.foo.com/abc123',
  :gallery_url                   => 'https://gallery.westus.foo.com/',
  :graph_url                     => 'https://graph.westus.foo.com/',
  :graph_api_version             => '1.6',
  :key_vault_dns_suffix          => 'vault.westus.foo.com',
  :key_vault_service_resource_id => 'https://vault.westus.foo.com/',
  :publish_settings_file_url     => 'https://management.westus.foo.com/publishsettings/index',
  :resource_manager_url          => 'https://management.westus.foo.com/',
  :service_management_url        => 'https://management.westus.foo.com/',
  :sql_database_dns_suffix       => 'westus.foo.com',
  :storage_suffix                => 'westus.foo.com',
  :traffic_manager_dns_suffix    => 'trafficmanager.net',
)


config = Azure::Armrest::Configuration.new(:environment => env, ...)

Not all of these endpoints are required, but at a minimum you must set the :name, :active_directory_authority, and :resource_manager_url. Otherwise, an error will be raised.

Automatic Environment Discovery

As of version 0.9.11 of the azure-armrest library, automatic discovery of essential endpoints is possible using the Environment.discover singleton method. Simply provide your resource manager endpoint and a new Environment object will be returned.

Example:

   env = Azure::Armrest::Environment.discover(:url => 'http://your_resource_manager.com', :name => 'custom name')

   # Returns an object with the following accessors set
   env.name
   env.active_directory_authority
   env.active_directory_resource_id
   env.gallery_url
   env.graph_url
   env.resource_manager_url

You can then use that environment object as part of a Configuration.