11# Copyright (c) HashiCorp, Inc.
22# SPDX-License-Identifier: MPL-2.0
33
4- provider "azurerm" {
5- features {}
6- }
7-
8- provider "azuread" {
9- }
4+ # Data source used to get information about the current Azure AD tenant.
5+ #
6+ # https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/data-sources/client_config
7+ data "azuread_client_config" "current" {}
108
119# Data source used to get the current subscription's ID.
1210#
@@ -19,14 +17,16 @@ data "azurerm_subscription" "current" {
1917# https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application
2018resource "azuread_application" "tfc_application" {
2119 display_name = " tfc-application"
20+ owners = [data . azuread_client_config . current . object_id ]
2221}
2322
2423# Creates a service principal associated with the previously created
2524# application registration.
2625#
2726# https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/service_principal
2827resource "azuread_service_principal" "tfc_service_principal" {
29- application_id = azuread_application. tfc_application . application_id
28+ # application_id = azuread_application.tfc_application.application_id
29+ client_id = azuread_application. tfc_application . client_id
3030}
3131
3232# Creates a role assignment which controls the permissions the service
@@ -44,22 +44,22 @@ resource "azurerm_role_assignment" "tfc_role_assignment" {
4444#
4545# https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application_federated_identity_credential
4646resource "azuread_application_federated_identity_credential" "tfc_federated_credential_plan" {
47- application_object_id = azuread_application. tfc_application . object_id
48- display_name = " my-tfc-federated-credential-plan"
49- audiences = [var . tfc_azure_audience ]
50- issuer = " https://${ var . tfc_hostname } "
51- subject = " organization:${ var . tfc_organization_name } :project:${ var . tfc_project_name } :workspace:${ var . tfc_workspace_name } :run_phase:plan"
47+ application_id = azuread_application. tfc_application . id
48+ display_name = " my-tfc-federated-credential-plan"
49+ audiences = [var . tfc_azure_audience ]
50+ issuer = " https://${ var . tfc_hostname } "
51+ subject = " organization:${ var . tfc_organization_name } :project:${ var . tfc_project_name } :workspace:${ var . tfc_workspace_name } :run_phase:plan"
5252}
5353
5454# Creates a federated identity credential which ensures that the given
5555# workspace will be able to authenticate to Azure for the "apply" run phase.
5656#
5757# https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application_federated_identity_credential
5858resource "azuread_application_federated_identity_credential" "tfc_federated_credential_apply" {
59- application_object_id = azuread_application. tfc_application . object_id
60- display_name = " my-tfc-federated-credential-apply"
61- audiences = [var . tfc_azure_audience ]
62- issuer = " https://${ var . tfc_hostname } "
63- subject = " organization:${ var . tfc_organization_name } :project:${ var . tfc_project_name } :workspace:${ var . tfc_workspace_name } :run_phase:apply"
59+ application_id = azuread_application. tfc_application . id
60+ display_name = " my-tfc-federated-credential-apply"
61+ audiences = [var . tfc_azure_audience ]
62+ issuer = " https://${ var . tfc_hostname } "
63+ subject = " organization:${ var . tfc_organization_name } :project:${ var . tfc_project_name } :workspace:${ var . tfc_workspace_name } :run_phase:apply"
6464}
6565
0 commit comments