Skip to content

Commit d74fff8

Browse files
committed
made sure the code works with latest providers
1 parent 4c26b48 commit d74fff8

File tree

4 files changed

+60
-18
lines changed

4 files changed

+60
-18
lines changed

azure/azure.tf

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
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
2018
resource "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
2827
resource "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
4646
resource "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
5858
resource "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

azure/providers.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
terraform {
2+
required_providers {
3+
azurerm = {
4+
source = "hashicorp/azurerm"
5+
version = "4.44.0"
6+
}
7+
azuread = {
8+
source = "hashicorp/azuread"
9+
version = "3.5.0"
10+
}
11+
tfe = {
12+
source = "hashicorp/tfe"
13+
version = "0.69.0"
14+
}
15+
}
16+
}
17+
18+
provider "azurerm" {
19+
features {}
20+
subscription_id = var.az_subscription_id
21+
}
22+
23+
provider "azuread" {
24+
}
25+
26+
provider "tfe" {
27+
hostname = var.tfc_hostname
28+
token = var.tfc_token
29+
}

azure/terraform.tfvars.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
tfc_organization_name = "my-organization"
1+
tfc_organization_name = "<my_organization>"
2+
az_subscription_id = "<my_azure_subscription_id>"
3+
tfc_token = "<my_tfc_token>"
4+
tfc_hostname = "<my_tfc_hostname>"

azure/vars.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,13 @@ variable "tfc_workspace_name" {
2929
default = "my-azure-workspace"
3030
description = "The name of the workspace that you'd like to create and connect to Azure"
3131
}
32+
33+
variable "az_subscription_id" {
34+
type = string
35+
description = "Azure Subscription ID where resources will be created"
36+
}
37+
38+
variable "tfc_token" {
39+
type = string
40+
description = "Terraform Cloud API token"
41+
}

0 commit comments

Comments
 (0)