Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TerraformTask@v4 Plan Multiple Provider Warning conflicts with tflint terraform_required_providers #229

Open
bn-jswick opened this issue Aug 2, 2024 · 3 comments

Comments

@bn-jswick
Copy link

bn-jswick commented Aug 2, 2024

Hello,
I recently converted a pipeline over to using TerraformTasks from running terraform directly via script commands and it is giving me the following warning for provider settings a submodule:

##[warning]Multiple provider blocks specified in the .tf files in the current working directory.

If I remove the provider constraints in the submodule, it conflicts with tflint in that submodules should declare required provider versions:

https://github.com/terraform-linters/tflint-ruleset-terraform/blob/v0.4.0/docs/rules/terraform_required_providers.md

Can someone point me to some documentation as to why TerraformTasks is throwing a warning for submodules declaring their provider constraints?

Thank you.

@mericstam
Copy link
Collaborator

Hi, Not sure why it was implemented in that way. Let me take a look and see if I can decipher why. Br Manuel

@mericstam
Copy link
Collaborator

mericstam commented Oct 7, 2024

Hi, the purpose of this warning is to warn if you have multiple cloud providers. like you should not have aws and azure in the same .tf file. What version of the task do you use? And if you could supply an example of a submodule that throws the warning.

Br
Manuel

@bn-jswick
Copy link
Author

bn-jswick commented Oct 8, 2024

I am using TerraformTaskV4@4, I get it with both the plan and apply commands.

                - task: TerraformTaskV4@4
                  displayName: "Apply Plan"
                  inputs:
                    provider: azurerm
                    command: apply
                    commandOptions: tfplan
                    environmentServiceNameAzureRM: $(TF-SERVICE-CONN)

In the main part of my config I have:

terraform {
  required_version = ">= 1.9.2"

  # Backend parameters configured via --backend-config file passed during terraform init
  backend "azurerm" {
  }

  required_providers {
    azurerm = {
      version = "~> 3.115"
      source  = "hashicorp/azurerm"
    }
    azuread = {
      source  = "hashicorp/azuread"
      version = "~> 2.53"
    }
    local = {
      source  = "hashicorp/local"
      version = "~> 2.4"
    }
    time = {
      source  = "hashicorp/time"
      version = "0.12.0"
    }
    tls = {
      source  = "hashicorp/tls"
      version = "~> 4.0"
    }
  }
}

provider "azurerm" {
  subscription_id     = local.management_sub_id
  storage_use_azuread = true

  features {}
}

provider "azuread" {
  tenant_id = data.azurerm_client_config.current.tenant_id
}

And in a local submodule (path modules/testmodule), it just needs azuread and is defined as such:

terraform {
  required_version = ">= 1.9.2"

  required_providers {
    azuread = {
      source  = "hashicorp/azuread"
      version = "~> 2.53"
    }
  }
}

I've double checked that I'm not passing any other provider statements in elsewhere in the configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants