Skip to content

Commit 5c6abc6

Browse files
committed
fixing some tfc related issues and adding a github pat
1 parent 701a559 commit 5c6abc6

File tree

3 files changed

+17
-40
lines changed

3 files changed

+17
-40
lines changed

terraform/main.tf

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ data "azuread_client_config" "current" {}
22

33

44
### Create a new Azure DevOps project
5-
resource "azuredevops_project" "this_project" {
5+
resource "azuredevops_project" "this" {
66
name = "python-fastapi"
77
visibility = "private"
88
version_control = "Git"
@@ -18,22 +18,18 @@ resource "azuredevops_project" "this_project" {
1818
}
1919

2020
### Create a new Git repository for FastAPI
21-
resource "azuredevops_git_repository" "fast_api_git_repo" {
22-
project_id = azuredevops_project.this_project.id
23-
name = "azure-python-fastapi"
24-
25-
initialization {
26-
init_type = "Import"
27-
source_type = "Git"
28-
source_url = var.fast_api_git_repo
29-
}
21+
resource "azuredevops_serviceendpoint_github" "this" {
22+
project_id = azuredevops_project.this.id
23+
service_endpoint_name = "python-fastapi"
3024

25+
auth_personal {
26+
personal_access_token = var.TFC_AZ_DEVOPS_GITHUB_PAT
27+
}
3128
}
3229

33-
3430
### Create Build Definition ###
35-
resource "azuredevops_build_definition" "this_definition" {
36-
project_id = azuredevops_project.this_project.id
31+
resource "azuredevops_build_definition" "this" {
32+
project_id = azuredevops_project.this.id
3733
name = "Default"
3834

3935
ci_trigger {
@@ -42,10 +38,11 @@ resource "azuredevops_build_definition" "this_definition" {
4238

4339

4440
repository {
45-
repo_type = "default"
46-
repo_id = azuredevops_git_repository.fast_api_git_repo.id
41+
repo_type = "GitHub"
42+
repo_id = "devsecblueprint/azure-python-fastapi"
4743
branch_name = "main"
4844
yml_path = ".azdo-pipelines/azure-pipelines.yml"
45+
service_connection_id = azuredevops_serviceendpoint_github.this.id
4946
}
5047

5148

@@ -96,13 +93,13 @@ resource "azurerm_federated_identity_credential" "ado_fed-id" {
9693
# sc://thogue1267/DevSecOps-FastApi/TimBoslice-Connection
9794
## sc://<organization>/<project>/<service-connection-name> "this = subject"
9895

99-
depends_on = [azuredevops_build_definition.this_definition]
96+
depends_on = [azuredevops_build_definition.this]
10097
}
10198

10299
### Create Service Connection to Azure Container Registry ###
103100
### Authenticates the pipeline to ACR using OIDC and a User-Assigned Managed Identity ###
104101
resource "azuredevops_serviceendpoint_azurecr" "acr_registry_endpoint" {
105-
project_id = azuredevops_project.this_project.id
102+
project_id = azuredevops_project.this.id
106103
resource_group = var.resource_group_name
107104
service_endpoint_name = "AzureCR Endpoint"
108105
service_endpoint_authentication_scheme = "WorkloadIdentityFederation"

terraform/variable-group.tf

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "azuredevops_variable_group" "infra_variable_group" {
2-
project_id = azuredevops_project.this_project.id
2+
project_id = azuredevops_project.this.id
33
name = "Infrastructure Pipeline Variables"
44
description = "Managed by Terraform"
55
allow_access = true
@@ -16,19 +16,11 @@ resource "azuredevops_variable_group" "infra_variable_group" {
1616
secret_value = azuredevops_serviceendpoint_azurecr.acr_registry_endpoint.id
1717
is_secret = true
1818
}
19-
20-
variable {
21-
name = "image_repo"
22-
secret_value = var.fast_api_git_repo
23-
is_secret = true
24-
25-
}
26-
2719
}
2820

2921

3022
resource "azuredevops_variable_group" "image_repo_variable" {
31-
project_id = azuredevops_project.this_project.id
23+
project_id = azuredevops_project.this.id
3224
name = "Image Repository Variables"
3325
description = "Managed by Terraform"
3426
allow_access = true

terraform/variables.tf

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ variable "TFC_AZ_TENANT_ID" {}
55
variable "TFC_AZ_SUBSCRIPTION_ID" {}
66
variable "TFC_AZ_DEVOPS_ORG_SERVICE_URL" {}
77
variable "TFC_AZ_DEVOPS_PAT" {}
8+
variable "TFC_AZ_DEVOPS_GITHUB_PAT" {}
89

910
### Resource Group Variables ###
1011

@@ -21,19 +22,6 @@ variable "location" {
2122

2223
}
2324

24-
### Repo Variables ###
25-
variable "infra_git_repo" {
26-
type = string
27-
description = "name of the infra git repo"
28-
default = "https://github.com/devsecblueprint/azure-devsecops-pipeline.git"
29-
}
30-
31-
variable "fast_api_git_repo" {
32-
type = string
33-
description = "name of the fast api git repo"
34-
default = "https://github.com/devsecblueprint/azure-python-fastapi.git"
35-
}
36-
3725
#### Azure Container Registry and Kubernetes Variables ###
3826
variable "acr_name" {
3927
type = string

0 commit comments

Comments
 (0)