Terraform Vcloud provider is crashing when using terraform plan - terraform

I am trying to automate the deployment of VM's in Vcloud using terraform.
The server that I am using doesn't have an internet connection so I had to install terraform and VCD provider offline.
Terrafom init worked but when I use terraform plan is crashing...
Terraform version: 1.0.11
VCD provider version: 3.2.0(I am using this version because we have vcloud 9.7).
This is a testing script, to see if terraform works
terraform {
required_providers {
vcd = {
source = "vmware/vcd"
version = "3.2.0"
}
}
}
provider "vcd" {
user = "test"
password = "test"
url = "https://test/api"
auth_type = "integrated"
vdc = "Org1VDC"
org = "System"
max_retry_timeout = "60"
allow_unverified_ssl = "true"
}
resource "vcd_org_user" "my-org-admin" {
org = "my-org"
name = "my-org-admin"
description = "a new org admin"
role = "Organization Administrator"
password = "change-me"
}
When I run terraform plan I get the following error:
Error: Plugin did not respond
...
The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ConfigureProvider call. The plugin logs may contain more details
Stack trace from the terraform-provider-vcd_v3.2.0 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0xaf3b75]
...
Error: The terraform-provider-vcd_v3.2.0 plugin crashed!
In the logs I can see a lot of DEBUG messages where the provider is trying to connect to github. provider.terraform-provider-vcd_v3.2.0: github.com/vmware/go-vcloud-director/v2/govcd.(*VCDClient).Authenticate(...)
And for ERROR messages I only saw 2:
plugin.(*GRPCProvider).ConfigureProvider: error="rpc error: code = Unavailable desc = transport is closing"
Failed to read plugin lock file .terraform/plugins/linux_amd64/lock.json: open .terraform/plugins/linux_amd64/lock.json: no such file or directory
This is the first time when am I am configuring Terraform offline and am using VCD provider.
Did I miss something?

I have found the issue.
At the URL I was using the IP address of the Vcloud api, and for some reason terraform didn't like that and was causing the crash, after changing to the FQDN, terraform started working again.
Kind regards

Related

Unable to create EventHub Authorization Rule in Azure using terraform

While trying to create EventHub Authorization Rule, getting the below error message. Not able to really get through this.
TF Code:
resource "azurerm_eventhub_authorization_rule" "jdBulkMessenger" {
name = "jd-bulk-messenger"
namespace_name = azurerm_eventhub_namespace.eventhub_ns.name
eventhub_name = azurerm_eventhub.eventhub.name
resource_group_name = data.azurerm_resource_group.rg.name
listen = true
send = false
manage = false
}
Tried with Different Provider Version but the same issue persists:
terraform {
required_providers {
azurerm = {
version = "~> 2.29.0"
}
}
}
Error:
Error: Error making Read request on Azure EventHub Authorization Rule : eventhub.EventHubsClient#GetAuthorizationRule: Invalid input: autorest/validation: validation failed: parameter=authorizationRuleName constraint=MinLength value="" details: value length must be greater than or equal to 1
I tried to reproduce the same :
Even I had similar error Error: Error making Read request on Azure EventHub Authorization Rule: parameter=authorizationRuleName constraint=MinLength value="" details: value length must be greater than or equal to 1 when I had older arurerm provider version 2.15.0
Providers.tf
azurerm = {
source = "hashicorp/azurerm"
version = "2.15.0"
}
Then I changed the azurerm provider version to 3.0.2 and it worked .
Check if both AzureRM Provider and Terraform Core versions are old
and upgrade to the latest versions as it may be fixed in latest
versions.
Also check if that azurerm provider version is compatible with terraform core/ cli version such that it supports azurerm provider version in order to create
authorization rules smoothly.

How can I fix Failed to query available provider packages when doing local provider development with terraform init?

Context: I'm developing a new TF provider. In order to test it, I use the following piece of advice from TF docs:
provider_installation {
# Use /home/developer/tmp/terraform-null as an overridden package directory
# for the hashicorp/null provider. This disables the version and checksum
# verifications for this provider and forces Terraform to look for the
# null provider plugin in the given directory.
dev_overrides {
"hashicorp/null" = "/home/developer/tmp/terraform-null"
}
# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use
# the dev_overrides block, and so no other providers will be available.
direct {}
}
And when I run terraform plan / terraform apply my provider does work without any issues. However when I try to run terraform init I'm running into:
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider
hashicorp/null: could not connect to hashicorp: Failed
to request discovery document: Get
"https://hashicorp/.well-known/terraform.json": dial tcp: lookup hashicorp on
100.217.9.1:53: no such host
Is there a way I could fix it?
For the context, my main.tf file starts with
terraform {
required_providers {
null = {
source = "hashicorp/null"
}
}
}
When I googled around, I found a related blog post and terraform plan seems to work for the author since he doesn't uses other plugins which is not the case for me unfortunately.
This issue on GitHub seems to show the same issues.

Terraform - Azure RM - Error: Failed to instantiate provider "azuread" to obtain schema: Unrecognized remote plugin message:

I'm getting this error when runnig Terraform validate or Terraform plan. What's strange is that the code used to work without a problem from my VsCode terminal window. The same code executes well if run from the Azure Command Shell. Any pointers would be great.
Error: Failed to instantiate provider "azuread" to obtain schema: Unrecognized remote plugin message:
This usually means that the plugin is either invalid or simply
needs to be recompiled to support the latest protocol.
Error: Failed to instantiate provider "azurerm" to obtain schema: Unrecognized remote plugin message:
This usually means that the plugin is either invalid or simply
needs to be recompiled to support the latest protocol.```
Here's the provider information:
```terraform {
required_version = "0.12.9"
}
provider "azurerm" {
version = "2.11"
subscription_id = "my first subscription id goes here"
features {}
}
provider "azurerm" {
version = "2.11"
alias = "shared"
subscription_id = "my second subscription id goes here"
features {}
}
provider "azuread" {
version = "0.11.0"
}```
The same issue resolved for me by using the bellow changes,
First In the main.tf file,
provider "azurerm" {
version = "=2.0.0"
features { }
}
Second run the upgrade command from Visual Studio Code for deploy the resources,
terraform init -upgrade
terraform init
terraform plan
terraform apply

Providing Terraform with credentials in terraform files instead of env variable

I have set-up a terraform project with a remote back-end on GCP. Now when I want to deploy the infrastructure, I run into issues with credentials. I have a credentials file in
\home\mike\.config\gcloud\credentials.json
In my terraform project I have the following data referring to the remote state:
data "terraform_remote_state" "project_id" {
backend = "gcs"
workspace = "${terraform.workspace}"
config {
bucket = "${var.bucket_name}"
prefix = "${var.prefix_project}"
}
}
and I specify the cloud provider with a the details of my credentials file.
provider "google" {
version = "~> 1.16"
project = "${data.terraform_remote_state.project_id.project_id}"
region = "${var.region}"
credentials = "${file(var.credentials)}"
}
However, this runs into
data.terraform_remote_state.project_id: data.terraform_remote_state.project_id:
error initializing backend:
storage.NewClient() failed: dialing: google: could not find default
credentials.
if I add
export GOOGLE_APPLICATION_CREDENTIALS=/home/mike/.config/gcloud/credentials.json
I do get it to run as desired. My issue is that I would like to specify the credentials in the terraform files as I am running the terraform commands in an automated way from a python script where I cannot set the environment variables. How can I let terraform know where the credentials are without setting the env variable?
I was facing the same error when trying to run terraform (version 1.1.5) commands in spite of having successfully authenticated via gcloud auth login.
Error message in my case:
Error: storage.NewClient() failed: dialing: google: could not find default credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
It turned out that I had to also authenticate via gcloud auth application-default login and was able to run terraform commands thereafter.
I figured this out in the end.
Also the data needs to have the credentials.
E.g.
data "terraform_remote_state" "project_id" {
backend = "gcs"
workspace = "${terraform.workspace}"
config = {
bucket = "${var.bucket_name}"
prefix = "${var.prefix_project}"
credentials = "${var.credentials}" <- added
}
}

Error creating sql server when applying terraform plan

I have the following resources to create a sql server and database using terraform
# Configure the Microsoft Azure Provider
provider "azurerm" {
version = "0.2.2"
}
# ...
resource "azurerm_sql_server" "demo" {
name = "${var.sql_server_name}"
resource_group_name = "${azurerm_resource_group.demo.name}"
location = "${azurerm_resource_group.demo.location}"
version = "12.0"
administrator_login = "${var.sql_server_account}"
administrator_login_password = "${var.sql_server_password}"
}
# Create SQL Database
resource "azurerm_sql_database" "demo" {
name = "demo"
resource_group_name = "${azurerm_resource_group.demo.name}"
location = "${azurerm_resource_group.demo.location}"
server_name = "${azurerm_sql_server.demo.name}"
}
When I run terraform plan it says it will create these resources, but when running terraform apply I get this error:
Error applying plan:
1 error(s) occurred:
* azurerm_sql_server.demo: 1 error(s) occurred:
* azurerm_sql_server.demo: sql.ServersClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="Unknown" Message="Unknown service error"
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
I tried changing the version of the azurerm plugin I'm using, but nothing has changed. I use the azurerm plugin version 0.2.2, same error occurs with versions 0.2.1, 0.2.0 does not work with some other resources.
It was silly, I looked into my azure logs and in turns out I was using the login name "admin" for sql server and that is not valid in the current version.
I guess Terraform has some problem to propogate the error from Azure to the command line.
In my case there was a mismatch with the values supplied to the variables:
edition requested_service_objective_name

Resources