diff --git a/awx/main/migrations/0012_v322_update_cred_types.py b/awx/main/migrations/0012_v322_update_cred_types.py new file mode 100644 index 0000000000..86d9fd55fa --- /dev/null +++ b/awx/main/migrations/0012_v322_update_cred_types.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +# AWX +from awx.main.migrations import _credentialtypes as credentialtypes + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0011_v322_encrypt_survey_passwords'), + ] + + operations = [ + migrations.RunPython(credentialtypes.add_azure_cloud_environment_field), + ] diff --git a/awx/main/migrations/_credentialtypes.py b/awx/main/migrations/_credentialtypes.py index 104caa334a..c9732b6239 100644 --- a/awx/main/migrations/_credentialtypes.py +++ b/awx/main/migrations/_credentialtypes.py @@ -176,3 +176,13 @@ def migrate_job_credentials(apps, schema_editor): def create_ovirt4_credtype(apps, schema_editor): CredentialType.setup_tower_managed_defaults() + + +def add_azure_cloud_environment_field(apps, schema_editor): + azure_rm_credtype = CredentialType.defaults.get('azure_rm', None) + if azure_rm_credtype: + azure_rm_credtype = azure_rm_credtype() + azure_rm_credtype.pk = CredentialType.objects.get( + kind='cloud', name='Microsoft Azure Resource Manager' + ).pk + azure_rm_credtype.save() diff --git a/awx/main/models/credential.py b/awx/main/models/credential.py index 77ce9ca3b0..e543bbb8b8 100644 --- a/awx/main/models/credential.py +++ b/awx/main/models/credential.py @@ -977,6 +977,12 @@ def azure_rm(cls): 'id': 'tenant', 'label': 'Tenant ID', 'type': 'string' + }, { + 'id': 'cloud_environment', + 'label': 'Azure Cloud Environment', + 'type': 'string', + 'help_text': ('Environment variable AZURE_CLOUD_ENVIRONMENT when' + ' using Azure GovCloud or Azure stack.') }], 'required': ['subscription'], } diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 98699de88c..8ba58111e2 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -1890,6 +1890,9 @@ class RunInventoryUpdate(BaseTask): env['AZURE_AD_USER'] = passwords.get('source_username', '') env['AZURE_PASSWORD'] = passwords.get('source_password', '') env['AZURE_INI_PATH'] = cloud_credential + if inventory_update.credential and \ + inventory_update.credential.inputs.get('cloud_environment', None): + env['AZURE_CLOUD_ENVIRONMENT'] = inventory_update.credential.inputs['cloud_environment'] elif inventory_update.source == 'gce': env['GCE_EMAIL'] = passwords.get('source_username', '') env['GCE_PROJECT'] = passwords.get('source_project', '')