Skip to content

Commit

Permalink
- Add ability to add subsciptionId to sp.yml on Azure (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
seriva committed Mar 23, 2020
1 parent 0b0066f commit 09f9456
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-0.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [#987](https://github.com/epiphany-platform/epiphany/issues/987) - Add verbosity levels for Terraform and Ansible
- [#656](https://github.com/epiphany-platform/epiphany/issues/656) - Add logrotation to kafka by size
- [#1016](https://github.com/epiphany-platform/epiphany/issues/1016) - Disable verify , backup and recovery as they are not fully implemented
- [#1044](https://github.com/epiphany-platform/epiphany/issues/1044) - Add ability to add subsciptionId to sp.yml on Azure

### Fixed

Expand Down
16 changes: 12 additions & 4 deletions core/src/epicli/cli/engine/terraform/TerraformRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,30 @@ def azure_login(self):
subscription = apiproxy.login_account()
apiproxy.set_active_subscribtion(subscription['id'])

# Create the service principle
# Create the service principle, for now we use the default subscription
self.logger.info('Creating service principal')
cluster_name = self.cluster_model.specification.name.lower()
cluster_prefix = self.cluster_model.specification.prefix.lower()
resource_group_name = resource_name(cluster_prefix, cluster_name, 'rg')
sp = apiproxy.create_sp(resource_group_name, subscription['id'])
sp['subscriptionId'] = subscription['id']
save_sp(sp, self.cluster_model.specification.name)
else:
self.logger.info('Using service principal from file')
sp = load_yaml_file(sp_file)

# Login as SP.
# Login as SP and get the default subscription.
subscription = apiproxy.login_sp(sp)

# Setup environment variables for Terraform when working with Azure and service principal.
self.new_env['ARM_SUBSCRIPTION_ID'] = subscription[0]['id']
if 'subscriptionId' in sp:
# Set active subscription if sp contains it.
apiproxy.set_active_subscribtion(sp['subscriptionId'])
self.new_env['ARM_SUBSCRIPTION_ID'] = sp['subscriptionId']
else:
# No subscriptionId in sp.yml so use the default one from Azure SP login.
self.new_env['ARM_SUBSCRIPTION_ID'] = subscription[0]['id']

# Set other environment variables for Terraform when working with Azure and service principal.
self.new_env['ARM_TENANT_ID'] = sp['tenant']
self.new_env['ARM_CLIENT_ID'] = sp['appId']
self.new_env['ARM_CLIENT_SECRET'] = sp['password']
1 change: 1 addition & 0 deletions docs/home/howto/CLUSTER.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ To setup the cluster do the following steps from the provisioning machine:
name: "http://app-name"
password: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
tenant: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
subscriptionId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
```
Epicli will read this file and automaticly use it for authentication for resource creation and management.
Expand Down

0 comments on commit 09f9456

Please sign in to comment.