diff --git a/environment_setup/iac-create-environment-pipeline-tf.yml b/environment_setup/iac-create-environment-pipeline-tf.yml index ef184546..40d2f11c 100644 --- a/environment_setup/iac-create-environment-pipeline-tf.yml +++ b/environment_setup/iac-create-environment-pipeline-tf.yml @@ -15,18 +15,18 @@ pr: - environment_setup/tf-templates/* pool: - vmImage: 'ubuntu-latest' + name: mlopspool variables: - group: devopsforai-aml-vg steps: -- task: charleszipp.azure-pipelines-tasks-terraform.azure-pipelines-tasks-terraform-installer.TerraformInstaller@0 +- task: TerraformInstaller@1 displayName: 'Use Terraform 0.12.24' inputs: - terraformVersion: 0.12.24 + terraformVersion: 1.9.8 -- task: charleszipp.azure-pipelines-tasks-terraform.azure-pipelines-tasks-terraform-cli.TerraformCLI@0 +- task: TerraformCLI@0 displayName: 'TF init - Deploy MLOps resources to Azure' inputs: command: init @@ -41,14 +41,16 @@ steps: backendAzureRmStorageAccountSku: 'Standard_LRS' backendAzureRmContainerName: 'tfstate-cont' backendAzureRmKey: 'mlopsinfra.tfstate' + env: + ARM_USE_AZUREAD: true -- task: charleszipp.azure-pipelines-tasks-terraform.azure-pipelines-tasks-terraform-cli.TerraformCLI@0 +- task: TerraformCLI@0 displayName: 'TF validate - Deploy MLOps resources to Azure' inputs: command: validate workingDirectory: '$(Build.SourcesDirectory)/environment_setup/tf-templates' -- task: charleszipp.azure-pipelines-tasks-terraform.azure-pipelines-tasks-terraform-cli.TerraformCLI@0 +- task: TerraformCLI@0 displayName: 'TF plan - Deploy MLOps resources to Azure' inputs: command: plan @@ -59,7 +61,7 @@ steps: TF_VAR_RESOURCE_GROUP: $(RESOURCE_GROUP) TF_VAR_WORKSPACE_NAME: $(WORKSPACE_NAME) -- task: charleszipp.azure-pipelines-tasks-terraform.azure-pipelines-tasks-terraform-cli.TerraformCLI@0 +- task: TerraformCLI@0 displayName: 'TF apply - Deploy MLOps resources to Azure' inputs: command: apply diff --git a/environment_setup/iac-pipeline.yml b/environment_setup/iac-pipeline.yml new file mode 100644 index 00000000..f156e977 --- /dev/null +++ b/environment_setup/iac-pipeline.yml @@ -0,0 +1,74 @@ +trigger: +- main + +pool: + name: 'mlopspool' + +variables: + - group: devopsforai-aml-vg + +steps: +# Step 1: Install Terraform +# - task: TerraformInstaller@0 +# displayName: 'Install Terraform' +# inputs: +# terraformVersion: 'latest' + +# - task: TerraformTaskV4@4 +# displayName: 'terraform init' +# inputs: +# provider: 'azurerm' +# command: 'init' +# workingDirectory: $(Build.SourcesDirectory)/environment_setup/tf-templates +# backendServiceArm: 'azure-resource-connection' +# backendAzureRmResourceGroupName: '$(RESOURCE_GROUP)' +# backendAzureRmStorageAccountName: '$(BASE_NAME)statestor' +# backendAzureRmContainerName: 'tfstate-cont' +# backendAzureRmKey: 'mlopsinfra.tfstate' +# env: +# ARM_USE_AZUREAD: true +# - task: TerraformCLI@0 +# displayName: 'Terraform Init' +# inputs: +# command: 'init' +# workingDirectory: $(Build.SourcesDirectory)/environment_setup/tf-templates +# environmentServiceName: 'azure-resource-connection' +# environmentVariables: +# ARM_CLIENT_ID: $(ARM_CLIENT_ID) +# ARM_CLIENT_SECRET: $(ARM_CLIENT_SECRET) +# ARM_TENANT_ID: $(ARM_TENANT_ID) +# ARM_SUBSCRIPTION_ID: $(ARM_SUBSCRIPTION_ID) +# Step 2: Login to Azure using Service Principal +- task: AzureCLI@2 + inputs: + azureSubscription: 'azure-resource-connection' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | + echo "Logging in with Service Principal..." + az login --service-principal -u $(ARM_CLIENT_ID) -p $(ARM_CLIENT_SECRET) --tenant $(ARM_TENANT_ID) + +# Step 3: Initialize Terraform Backend +- script: | + terraform init \ + -backend-config="storage_account_name=$(BASE_NAME)statestor" \ + -backend-config="container_name=tfstate-cont" \ + -backend-config="key=mlopsinfra.tfstate" \ + -backend-config="resource_group_name=$(RESOURCE_GROUP)" \ + -backend-config="client_id=$(ARM_CLIENT_ID)" \ + -backend-config="client_secret=$(ARM_CLIENT_SECRET)" \ + -backend-config="tenant_id=$(ARM_TENANT_ID)" + workingDirectory: $(Build.SourcesDirectory)/environment_setup/tf-templates + displayName: 'Terraform Init' + +# # Step 4: Terraform Plan +# - script: | +# terraform plan -out=tfplan +# workingDirectory: $(Build.SourcesDirectory)/environment_setup/tf-templates +# displayName: 'Terraform Plan' + +# # Step 5: Terraform Apply +# - script: | +# terraform apply -auto-approve tfplan +# workingDirectory: $(Build.SourcesDirectory)/environment_setup/tf-templates +# displayName: 'Terraform Apply' diff --git a/environment_setup/tf-templates/backend.tf b/environment_setup/tf-templates/backend.tf index 0aec0499..5817fca6 100644 --- a/environment_setup/tf-templates/backend.tf +++ b/environment_setup/tf-templates/backend.tf @@ -1,4 +1,10 @@ terraform { backend "azurerm" { + resource_group_name = "mlops-RG" + storage_account_name = "mlopsstatestor" + container_name = "tfstate-cont" + key = "mlopsinfra.tfstate" + + # These environment variables will be used for Service Principal authentication } } diff --git a/environment_setup/tf-templates/main.tf b/environment_setup/tf-templates/main.tf index c57a5a84..e399d512 100644 --- a/environment_setup/tf-templates/main.tf +++ b/environment_setup/tf-templates/main.tf @@ -1,6 +1,7 @@ provider "azurerm" { version = "=2.3.0" features {} + use_oidc_token = true } variable BASE_NAME {}