terraformterraform-provider-azureterraform-provider

Issue using third party providers in terraform for azure-devops and mysql provider


While doing terraform init getting error, following the terraform official documentation, I am trying to create azure-pipeline via terraform and have created modules for it, but unable to initialize, its working fine if i am passing it directly in .tf file, but when adding to module, the terraform init command itself is failing.

╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/mysql: provider registry registry.terraform.io does not have a provider named       
│ registry.terraform.io/hashicorp/mysql
│
│ Did you intend to use terraform-providers/mysql? If so, you must specify that source address in each module which requires that provider. To see which       
│ modules are currently depending on hashicorp/mysql, run the following command:
│     terraform providers
╵

╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/azuredevops: provider registry registry.terraform.io does not have a provider named 
│ registry.terraform.io/hashicorp/azuredevops
│
│ Did you intend to use microsoft/azuredevops? If so, you must specify that source address in each module which requires that provider. To see which modules   
│ are currently depending on hashicorp/azuredevops, run the following command:
│     terraform providers

Solution

  • Anyone here looking for answer, For any third party provider we need to add the source in modules as well. Like I had to add the azure-devops source in the module

    terraform {
      required_providers {
        azuredevops = {
          source = "microsoft/azuredevops"
          version = "0.1.7"
        }
      }
    }
    
    #Create Azure Repo and Azure Pipeline
    data "azuredevops_project" "project" {
      name = "Test"
    }
    
    #Create New Repo
    resource "azuredevops_git_repository" "repo" {
      project_id = data.azuredevops_project.project.id
      name       = var.name
      initialization {
        init_type   = "Import"
        source_type = "Git"
        source_url  = lookup(var.template_map,var.template)
      }
    }