@@ -56,3 +56,192 @@ output "azure_ad_tenant_id" {
5656 description = " The Azure AD tenant id."
5757 value = data. azuread_client_config . current . tenant_id
5858}
59+
60+
61+
62+ output "documentation" {
63+ description = " Complete module documentation in markdown format"
64+ value = <<- EOT
65+ # terraform-azure-meshplatform Documentation
66+
67+
68+
69+ ## Overview
70+
71+ This Terraform module provisions Azure service principals and configurations for meshStack integration. It creates the necessary Azure AD applications, service principals, and role assignments required for meshStack to manage Azure resources.
72+
73+ ## Deployed Components
74+
75+ ### Service Principal Status
76+
77+ | Component | Enabled | Service Principal Name | Application ID |
78+ |-----------|---------|----------------------|----------------|
79+ | Replicator | ${ length (module. replicator_service_principal ) > 0 ? " ✅ Yes" : " ❌ No" } | ${ var . replicator_service_principal_name } | ${ length (module. replicator_service_principal ) > 0 ? module . replicator_service_principal [0 ]. credentials . Application_Client_ID : " N/A" } |
80+ | Metering (Kraken) | ${ length (module. metering_service_principal ) > 0 ? " ✅ Yes" : " ❌ No" } | ${ var . metering_service_principal_name } | ${ length (module. metering_service_principal ) > 0 ? module . metering_service_principal [0 ]. credentials . Application_Client_ID : " N/A" } |
81+ | SSO | ${ length (module. sso_service_principal ) > 0 ? " ✅ Yes" : " ❌ No" } | ${ var . sso_service_principal_name } | ${ length (module. sso_service_principal ) > 0 ? module . sso_service_principal [0 ]. application_client_id : " N/A" } |
82+ | MCA | ${ length (module. mca_service_principal ) > 0 ? " ✅ Yes" : " ❌ No" } | ${ var . mca != null ? join (" , " , var. mca . service_principal_names ) : " N/A" } | ${ length (module. mca_service_principal ) > 0 ? " Multiple SPs" : " N/A" } |
83+
84+ ## Configuration Details
85+
86+ ### Azure AD Tenant
87+ - **Tenant ID**: ${ data . azuread_client_config . current . tenant_id }
88+
89+ ### Authentication Methods
90+ - **Password Authentication**: ${ var . create_passwords ? " ✅ Enabled" : " ❌ Disabled" }
91+ - **Workload Identity Federation**: ${ var . workload_identity_federation != null ? " ✅ Enabled" : " ❌ Disabled" }
92+ ${ var . workload_identity_federation != null ? " - **Issuer**: ${ var . workload_identity_federation . issuer } " : " " }
93+
94+ ${ var . replicator_enabled || var . replicator_rg_enabled ? <<- REPLICATOR
95+ ### Replicator Service Principal
96+ The replicator service principal manages Azure subscriptions and resources.
97+
98+ - **Name**: ${ var . replicator_service_principal_name }
99+ - **Custom Role Scope**: ${ var . replicator_custom_role_scope }
100+ - **Assignment Scopes**:
101+ ${ join (" \n " , formatlist (" - %s" , var. replicator_assignment_scopes ))}
102+ - **Can Cancel Subscriptions**: ${ length (var. can_cancel_subscriptions_in_scopes ) > 0 ? join (" , " , var. can_cancel_subscriptions_in_scopes ) : " None" }
103+ - **Can Delete Resource Groups**: ${ length (var. can_delete_rgs_in_scopes ) > 0 ? join (" , " , var. can_delete_rgs_in_scopes ) : " None" }
104+ REPLICATOR
105+ : " " }
106+
107+ ${ var . metering_enabled ? <<- METERING
108+ ### Metering Service Principal (Kraken)
109+ The metering service principal collects cost and usage data.
110+
111+ - **Name**: ${ var . metering_service_principal_name }
112+ - **Assignment Scopes**:
113+ ${ join (" \n " , formatlist (" - %s" , var. metering_assignment_scopes ))}
114+ METERING
115+ : " " }
116+
117+ ${ var . sso_enabled ? <<- SSO
118+ ### SSO Service Principal
119+ The SSO service principal enables single sign-on integration.
120+
121+ - **Name**: ${ var . sso_service_principal_name }
122+ - **meshStack IDP Domain**: ${ var . sso_meshstack_idp_domain }
123+ - **Identity Provider Alias**: ${ var . sso_identity_provider_alias }
124+ - **App Role Assignment Required**: ${ var . sso_app_role_assignment_required ? " Yes" : " No" }
125+ SSO
126+ : " " }
127+
128+ ${ var . mca != null ? <<- MCA
129+ ### MCA Service Principal
130+ The MCA service principal manages Microsoft Customer Agreement billing.
131+
132+ - **Service Principal Names**: ${ join (" , " , var. mca . service_principal_names )}
133+ - **Billing Account**: ${ var . mca . billing_account_name }
134+ - **Billing Profile**: ${ var . mca . billing_profile_name }
135+ - **Invoice Section**: ${ var . mca . invoice_section_name }
136+ MCA
137+ : " " }
138+
139+ ## Additional Configuration
140+
141+ ${ var . administrative_unit_name != null ? " ### Administrative Unit\n - **Name**: ${ var . administrative_unit_name } \n " : " " }
142+
143+ ### Application Owners
144+ ${ length (var. application_owners ) > 0 ? join (" \n " , formatlist (" - %s" , var. application_owners )) : " - None specified" }
145+
146+ ## Outputs Available
147+
148+ The following outputs are available after deployment:
149+
150+ | Output | Description | Sensitive | Available |
151+ |--------|-------------|-----------|-----------|
152+ | replicator_service_principal | Replicator service principal credentials | No | ${ length (module. replicator_service_principal ) > 0 ? " ✅" : " ❌" } |
153+ | replicator_service_principal_password | Replicator service principal password | Yes | ${ length (module. replicator_service_principal ) > 0 ? " ✅" : " ❌" } |
154+ | mca_service_principal | MCA service principal credentials | No | ${ length (module. mca_service_principal ) > 0 ? " ✅" : " ❌" } |
155+ | mca_service_principal_password | MCA service principal password | Yes | ${ length (module. mca_service_principal ) > 0 ? " ✅" : " ❌" } |
156+ | mca_service_billing_scope | MCA billing scope | No | ${ length (module. mca_service_principal ) > 0 ? " ✅" : " ❌" } |
157+ | metering_service_principal | Metering service principal credentials | No | ${ length (module. metering_service_principal ) > 0 ? " ✅" : " ❌" } |
158+ | metering_service_principal_password | Metering service principal password | Yes | ${ length (module. metering_service_principal ) > 0 ? " ✅" : " ❌" } |
159+ | sso_service_principal_client_id | SSO service principal client ID | No | ${ length (module. sso_service_principal ) > 0 ? " ✅" : " ❌" } |
160+ | sso_service_principal_password | SSO service principal password | Yes | ${ length (module. sso_service_principal ) > 0 ? " ✅" : " ❌" } |
161+ | sso_discovery_url | SSO OpenID Connect discovery URL | Yes | ${ length (module. sso_service_principal ) > 0 ? " ✅" : " ❌" } |
162+ | azure_ad_tenant_id | Azure AD tenant ID | No | ✅ |
163+ | documentation | This documentation in markdown format | No | ✅ |
164+
165+ ## meshStack Integration Details
166+
167+ This AAD tenant is configured as a meshPlatform, with tenant-level service principals allowing meshStack to access data and orchestrate Azure platform functionality.
168+
169+ ${ length (module. replicator_service_principal ) > 0 ? <<- REPLICATOR_DETAILS
170+ ### Replicator Service Principal
171+ The replicator manages user roles and permissions in your Azure subscriptions and workloads.
172+
173+ - **Application Client ID**: ${ module . replicator_service_principal [0 ]. credentials . Application_Client_ID }
174+ - **Enterprise Application Object ID**: ${ module . replicator_service_principal [0 ]. credentials . Enterprise_Application_Object_ID }
175+ REPLICATOR_DETAILS
176+ : " ### Replicator Service Principal\n ❌ Not deployed" }
177+
178+ ${ length (module. metering_service_principal ) > 0 ? <<- METERING_DETAILS
179+ ### Metering Service Principal
180+ The metering service principal reads resource usage for billing and cost management.
181+
182+ - **Application Client ID**: ${ module . metering_service_principal [0 ]. credentials . Application_Client_ID }
183+ - **Enterprise Application Object ID**: ${ module . metering_service_principal [0 ]. credentials . Enterprise_Application_Object_ID }
184+ METERING_DETAILS
185+ : " ### Metering Service Principal\n ❌ Not deployed" }
186+
187+ ${ length (module. mca_service_principal ) > 0 ? <<- MCA_DETAILS
188+ ### Microsoft Customer Agreement (MCA) Service Principal(s)
189+ For MCA subscription provisioning, these service principals have "Azure subscription creator" role on the invoice section level.
190+
191+ ${ join (" \n " , [for name , properties in module . mca_service_principal [0 ]. credentials : << EOT
192+ **${ name } **:
193+ - **Application Client ID**: ${ properties . Application_Client_ID }
194+ - **Enterprise Application Object ID**: ${ properties . Enterprise_Application_Object_ID }
195+ EOT
196+ ])}
197+ MCA_DETAILS
198+ : " ### MCA Service Principal\n ❌ Not deployed" }
199+
200+ ${ length (module. sso_service_principal ) > 0 ? <<- SSO_DETAILS
201+ ### SSO Service Principal
202+ Enables single sign-on integration between meshStack and your identity provider.
203+
204+ - **Application Client ID**: ${ module . sso_service_principal [0 ]. application_client_id }
205+ SSO_DETAILS
206+ : " ### SSO Service Principal\n ❌ Not deployed" }
207+
208+ ## Usage Examples
209+
210+ ### Available Commands for Current Configuration
211+ ```bash
212+ # Always available
213+ terraform output azure_ad_tenant_id
214+ terraform output documentation
215+
216+ ${ length (module. replicator_service_principal ) > 0 ? " # Replicator Service Principal (✅ deployed)\n terraform output replicator_service_principal\n terraform output -raw replicator_service_principal_password # sensitive" : " # Replicator Service Principal (❌ not deployed)" }
217+
218+ ${ length (module. metering_service_principal ) > 0 ? " # Metering Service Principal (✅ deployed)\n terraform output metering_service_principal\n terraform output -raw metering_service_principal_password # sensitive" : " # Metering Service Principal (❌ not deployed)" }
219+
220+ ${ length (module. sso_service_principal ) > 0 ? " # SSO Service Principal (✅ deployed)\n terraform output sso_service_principal_client_id\n terraform output -raw sso_service_principal_password # sensitive\n terraform output -raw sso_discovery_url # sensitive" : " # SSO Service Principal (❌ not deployed)" }
221+
222+ ${ length (module. mca_service_principal ) > 0 ? " # MCA Service Principal (✅ deployed)\n terraform output mca_service_principal\n terraform output -raw mca_service_principal_password # sensitive\n terraform output mca_service_billing_scope" : " # MCA Service Principal (❌ not deployed)" }
223+
224+ # Save documentation to file
225+ terraform output -raw documentation > meshplatform-docs.md
226+ ```
227+
228+ ### Integration with meshStack
229+ 1. Use the service principal credentials in your meshStack platform configuration
230+ 2. Configure the appropriate scopes and permissions based on your requirements
231+ 3. Set up workload identity federation if enabled for enhanced security
232+
233+ ## Security Considerations
234+
235+ - Sensitive outputs (passwords, discovery URLs) are marked as sensitive in Terraform
236+ - Consider using workload identity federation instead of passwords for enhanced security
237+ - Regularly rotate service principal passwords if using password authentication
238+ - Follow principle of least privilege when assigning scopes and permissions
239+
240+ ## Support
241+
242+ For issues and questions regarding this module, please refer to the project repository or contact your meshStack administrator.
243+
244+ ---
245+ *This documentation was automatically generated by Terraform*
246+ EOT
247+ }
0 commit comments