I'm trying to create a Postgres server on Azure using the azurerm_postgresql_server resource block. I've got the azurerm version pinned to 2.4.0 which means I should be up to date and can use the examples from the documentation. Instead, I'm getting missing required argument errors and seeing messages refer to missing attributes, that according to the documentation are deprecated.
So far I've tried running terraform init -upgrade in case I had previously tried a Postgres creation with an older version of the provider and it caused a cached version of the plugin but it's not had any effect. I have no idea what's wrong - if it's the code itself or the terraform setup on my machine. Simplified code snippet and error output are below, thanks!
provider "azurerm" {
version = "=2.4.0"
subscription_id = "xxxxxxxxxxxxxxx"
features {
key_vault {
purge_soft_delete_on_destroy = true
}
}
}
resource "azurerm_postgresql_server" "postgres" {
name = "sarum-hymnal-postgresql-server"
location = var.resource_group.location
resource_group_name = var.resource_group.name
sku_name = "B_Gen4_1"
storage_mb = 5120
backup_retention_days = 7
geo_redundant_backup_enabled = false
auto_grow_enabled = false
administrator_login = data.azurerm_key_vault_secret.POSTGRES-USERNAME.value
administrator_login_password = data.azurerm_key_vault_secret.POSTGRES-SECRET.value
version = "11"
ssl_enforcement_enabled = true
tags = var.resource_group.tags
}
Error: Missing required argument
on sarum-hymnal/main.tf line 26, in resource "azurerm_postgresql_server" "postgres":
26: resource "azurerm_postgresql_server" "postgres" {
The argument "ssl_enforcement" is required, but no definition was found.
Error: Unsupported argument
on sarum-hymnal/main.tf line 31, in resource "azurerm_postgresql_server" "postgres":
31: storage_mb = 5120
An argument named "storage_mb" is not expected here.
by running terraform providers at the root directory I get the following output:
.
├── provider.azurerm =2.4.0
├── module.early-modern-ballot
│ └── provider.azurerm (inherited)
├── module.hands-on-reading
│ └── provider.azurerm (inherited)
├── module.poetic-transformations
│ └── provider.azurerm (inherited)
├── module.sarum-hymnal
│ └── provider.azurerm (inherited)
├── module.soundscapes-of-text
│ └── provider.azurerm (inherited)
└── module.translations
└── provider.azurerm (inherited)
You could upgrade your terraform version to v0.12 and the version of the azurerm provider to version = ">=2.7". This works on my side.
See v2.0 of the AzureRM Provider and Upgrading to Terraform v0.12 for more details.
Related
I have the below directory structure
├── main.tf
├── output.tf
├── variables.tf
├── modules
│ ├── ServicePrincipal
│ │ ├── variables.tf
│ │ ├── outputs.tf
│ │ ├── main.tf
│ ├── aks
│ │ ├── main.tf
│ │ ├── output.tf
│ │ └── variables.tf
...
Issue:
I want to use client_id and client_secret generated from service principal module as an input to create my aks cluster. I am able to reference the below output variables from my root main.tf by module.modulename.outputvarname however, I cannot access it in another child module(aks) as var.client_id or module.serviceprincipal.client_id
main.tf of root module where I am able to use client_id and client_secret
module "ServicePrincipal" {
source = "./modules/ServicePrincipal"
service_principal_name = var.service_principal_name
redirect_uris = var.redirect_uris
}
module "aks" {
source = "./modules/aks/"
service_principal_name = var.service_principal_name
serviceprinciple_id = module.ServicePrincipal.service_principal_object_id
serviceprinciple_key = module.ServicePrincipal.client_secret
location = var.location
resource_group_name = var.rgname
depends_on = [
module.ServicePrincipal
]
}
main.tf of aks module
service_principal {
client_id = var.client_id
client_secret = var.client_secret
}
output.tf for my ServicePrincipal module
output "client_id" {
description = "The application id of AzureAD application created."
value = azuread_application.main.application_id
}
output "client_secret" {
description = "Password for service principal."
value = azuread_service_principal_password.main.*.value
}
Below is the error I am getting:
Error: Missing required argument
on main.tf line 136, in module "aks":
136: module "aks" {
The argument "client_id" is required, but no definition was found.
Error: Missing required argument
on main.tf line 136, in module "aks":
136: module "aks" {
The argument "client_secret" is required, but no definition was found.
I already defined those as variables in aks module and root module, am I missing something here?
Thanks in advance!
Piyush
Child modules can't reference each others outputs. You have to explicitly pass them in the root module from one module to the second, e.g.
in root:
module "ServicePrincipal" {
}
module "aks" {
client_id = module.ServicePrincipal.client_id
}
You're using output name as client_id and client_secret but in module you're calling with different names ?
module.ServicePrincipal.service_principal_object_id
│ Error: Failed to load plugin schemas
│
│ Error while loading schemas for plugin components: Failed to obtain provider schema: Could not load the schema for
│ provider registry.terraform.io/hashicorp/azurerm: failed to instantiate provider
│ "registry.terraform.io/hashicorp/azurerm" to obtain schema: fork/exec
│ .terraform/providers/registry.terraform.io/hashicorp/azurerm/3.10.0/windows_386/terraform-provider-azurerm_v3.10.0_x5.exe:
│ The parameter is incorrect...
The error you are receving due to you already have lockfile for specific version and now you are trying to intatite with another version and do terraform plan.
Resoulation : Delete your .terraform.lock.hcl file and (.tfstate file if created) then again do terraform init to intialize the update version of terraform.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.3.0"
}
}
}
provider "azurerm" {
features{}
}
I am not sure how to resolve this error, tried various combination of versions but can not get this working;
Within my modules:
terraform {
required_version = "~> 1.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 2.98.0". #or 2.62.1 ,1.6.0 depending on the what resource the module is for
}
}
}
Within my main.tf file:
terraform {
required_version = "~> 1.0.1"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
}
azuread = {
source = "hashicorp/azuread"
}
external = {
source = "hashicorp/external"
}
random = {
source = "hashicorp/random"
}
sops = {
source = "carlpett/sops"
}
}
}
Error upon terraform init:
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/azurerm: locked provider registry.terraform.io/hashicorp/azurerm 2.56.0 does not match
│ configured version constraint ~> 2.62.1, ~> 2.98.0; must use terraform init -upgrade to allow selection of new versions
╵
This is providers requirements.
user:$ terraform providers
Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/random]
├── provider[registry.terraform.io/carlpett/sops] 0.6.3
├── provider[registry.terraform.io/hashicorp/azurerm]
├── provider[registry.terraform.io/hashicorp/azuread] ~> 1.6.0
├── provider[registry.terraform.io/hashicorp/external]
├── module.azurerm_storagecontainer_container1
│ └── provider[registry.terraform.io/hashicorp/azurerm] ~> 2.98.0
├── module.azurerm_servicebusqueue_bus1
│ └── provider[registry.terraform.io/hashicorp/azurerm] ~> 2.62.1
├── module.azurerm_storageaccount
│ ├── provider[registry.terraform.io/hashicorp/random]
│ └── provider[registry.terraform.io/hashicorp/azurerm] ~> 2.98.0
├── module.azurerm_key_vault
│ ├── provider[registry.terraform.io/hashicorp/azurerm] ~> 2.98.0
│ └── provider[registry.terraform.io/hashicorp/azuread]
├── module.resourcegroup
│ └── provider[registry.terraform.io/hashicorp/azurerm] ~> 2.98.0
Providers required by state:
provider[registry.terraform.io/hashicorp/azuread]
provider[registry.terraform.io/hashicorp/azurerm]
provider[registry.terraform.io/hashicorp/random]
provider[registry.terraform.io/carlpett/sops]
So the issue was one of the module dependency "servicebus" was still using older version for azurerm which cause this failure. so I updated it to 2.98.0 and that got me going. Earlier I thought that would not matter different module can have different azurerm version but that assumption was wrong. In tf consumer make sure that all module dependency should use same provide version.
I'm on TF version v1.0.0(latest) and am trying to make use of the pagerduty Tf provider and the error log says could not retrieve teh list of available versions. Below is the code snippet and complete error log.
Code:
terraform {
required_providers {
pagerduty = {
source = "PagerDuty/pagerduty"
version = "~> 1.9.8"
}
}
}
provider "pagerduty" {
token = var.token
}
resource "pagerduty_service" "example" {
name = "My Web App"
auto_resolve_timeout = 14400
acknowledgement_timeout = 600
escalation_policy = var.policy
}
resource "pagerduty_service_integration" "apiv2" {
name = "API V2"
type = "events_api_v2_inbound_integration"
service = pagerduty_service.example.id
}
Error:
- Finding latest version of hashicorp/pagerduty...
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/pagerduty: provider registry
│ registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/pagerduty
│
│ Did you intend to use pagerduty/pagerduty? If so, you must specify that source address in each module which
│ requires that provider. To see which modules are currently depending on hashicorp/pagerduty, run the following
│ command:
│ terraform providers
Answering my question.
Separating the first terraform required_providers blocks into its own versions.tf file has solved the issue.
As you can see below, I'm trying to pass a specific provider to a module, which then passes it as the main provider (aws = aws.some_profile) to a second, nested module.
on terraform plan I get the following error:
Error: missing provider module.module_a.provider["registry.terraform.io/hashicorp/aws"].some_profile
I must be doing somethig basic wrong or assuming the language works in a way that it doesn't. Ideas?
File structure:
├── main.tf
├── module_a
│ ├── main.tf
│ └── module_b
│ └── main.tf
└── providers.tf
main.tf (top level):
module "module_a" {
source = "./module_a"
providers = {
aws.some_profile = aws.some_profile
}
}
main.tf (inside module_a):
module "module_b" {
source = "./module_b"
providers = {
aws = aws.some_profile
}
}
main.tf (inside module b):
resource "null_resource" "null" {}
providers.tf:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.22.0"
}
}
}
provider "aws" {
profile = "default"
region = "us-west-2"
}
provider "aws" {
alias = "some_profile"
profile = "some_profile"
region = "us-west-2"
}
Ok, so after getting some answers on Reddit, it looks like although you are passing providers down to submodules you still need to declare said providers in each submodule like so:
provider "aws" { alias = "some_provider" }
And it seems like the terraform "required providers" block is only required on the very top level. However, if it isn't working you can try adding it to each submodule as well.
Hope this helps someone out.