From c1972f6343e467b8eebf8b7f20a598001bf07e3e Mon Sep 17 00:00:00 2001 From: Torian Crane Date: Thu, 12 Oct 2023 08:55:30 +0000 Subject: [PATCH] output environment template file --- azure-py-oidc-provider-pulumi-cloud/README.md | 1 - .../__main__.py | 34 ++++++++++++++++--- .../requirements.txt | 1 + 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/azure-py-oidc-provider-pulumi-cloud/README.md b/azure-py-oidc-provider-pulumi-cloud/README.md index 8f63d37a8..0daa3fa8a 100644 --- a/azure-py-oidc-provider-pulumi-cloud/README.md +++ b/azure-py-oidc-provider-pulumi-cloud/README.md @@ -30,7 +30,6 @@ Next, to deploy the application and its infrastructure, follow these steps: 1. Set your Pulumi organization name, Pulumi ESC environment name, and desired Azure region: ```bash - pulumi config set pulumiOrg # replace with your Pulumi organization name pulumi config set environmentName # replace with your environment name pulumi config set azure-native:location WestUS2 # any valid Azure region will work ``` diff --git a/azure-py-oidc-provider-pulumi-cloud/__main__.py b/azure-py-oidc-provider-pulumi-cloud/__main__.py index 80f7cab94..23c6e9b57 100644 --- a/azure-py-oidc-provider-pulumi-cloud/__main__.py +++ b/azure-py-oidc-provider-pulumi-cloud/__main__.py @@ -2,12 +2,13 @@ from pulumi_azure_native import resources, aad, authorization, managedidentity import pulumi_azuread as azuread from pulumi_azure import core +import yaml issuer = "https://api.pulumi.com/oidc" # Retrieve local Pulumi configuration pulumi_config = pulumi.Config() -audience = pulumi_config.require("pulumiOrg") +audience = pulumi.get_organization() env_name = pulumi_config.require("environmentName") # Retrieve local Azure configuration @@ -35,7 +36,30 @@ subject=f"pulumi:environments:org:{audience}:env:{env_name}" ) -# Export Outputs required for Environment definition -pulumi.export('ApplicationId', application.application_id) -pulumi.export('DirectoryId', tenant_id) -pulumi.export('SubscriptionId', az_subscription) +print("OIDC configuration complete!") +print("Copy and paste the following template into your Pulumi ESC environment:") +print("--------") + +def create_yaml_structure(args): + application_id, tenant_id, subscription_id = args + return { + 'values': { + 'azure': { + 'login': { + 'fn::open::azure-login': { + 'clientId': application_id, + 'tenantId': tenant_id, + 'subscriptionId': f"/subscriptions/{subscription_id}", + 'oidc': True + } + } + } + } + } + +def print_yaml(args): + yaml_structure = create_yaml_structure(args) + yaml_string = yaml.dump(yaml_structure, sort_keys=False) + print(yaml_string) + +pulumi.Output.all(application.application_id, tenant_id, az_subscription).apply(print_yaml) \ No newline at end of file diff --git a/azure-py-oidc-provider-pulumi-cloud/requirements.txt b/azure-py-oidc-provider-pulumi-cloud/requirements.txt index 9d1294d07..20d3d20c2 100644 --- a/azure-py-oidc-provider-pulumi-cloud/requirements.txt +++ b/azure-py-oidc-provider-pulumi-cloud/requirements.txt @@ -2,3 +2,4 @@ pulumi>=3.0.0,<4.0.0 pulumi-azure-native>=2.0.0,<3.0.0 pulumi-azuread>=5.0.0, <6.0.0 pulumi-azure>=5.0.0, <6.0.0 +PyYAML