What is the correct form of terragrunt terraform source to get module from private gitlab terraform registry - gitlab

Could you kindly help me with my issue?
I have terraform module on private gitlab instance and I can obtain it with http-source from terragrunt like this:
terraform {
source = "https://gitlab.mysite.com/gitlab_group_name/gitlab_subgroup_name/project_name"
extra_arguments "init_args" {
commands = [
"init"
]
arguments = [
]
}
}
Then I've pushed this module to gitlab terraform registry with version number 0.0.1 and tried huge amount of variants of terragrunt source like
source = "tfr://gitlab.mysite.com/gitlab_group_name/gitlab_subgroup_name/project_name?version=0.0.1"
Terragrunt somehow rewrites URL above to something like
https://gitlab.mysite.com/api/v4/packages/terraform/modules/v1/gitlab_group_name/gitlab_subgroup_name/project_name/0.0.1/download
and throw expected error
error receiving HTTP data
Is there any way to get module from private gitlab terraform registry with terragrunt using tfr protocol?

Related

Empty summary error in terraform when runs in circleci

I'm using terraform and terragrunt to create some repositories in bitbucket, and since they do not have an official provider I'm using one from DrFaust92/bitbucket. I have done everything in my computer and I could apply all, now I'm moving the workflow to circle ci, and when I run it there I always get this error:
bitbucket_repository.repository: Creating...
╷
│ Error: Empty Summary: This is always a bug in the provider and should be reported
to the provider developers.
│
│ with bitbucket_repository.repository,
│ on main.tf line 5, in resource "bitbucket_repository" "repository":
│ 5: resource "bitbucket_repository" "repository" {
The resource does not have anything in special:
resource "bitbucket_repository" "repository" {
name = var.name
description = var.description
owner = var.owner
project_key = var.project_key
language = var.project_language
fork_policy = var.fork_policy
is_private = true
}
I'm using terraform 1.3.7 and terragrunt 0.43.1 (in my computer and in circle ci, both run with the same versions). It fails when it access any tfstate: if the tfstate already exists, it throws the error when planning, if it doesn't, the plan runs well, but when I apply it fails with the same error.
Any help to fix this will be appreciated!
This is most likely issue associated with provider version. In your local, it may have a certain version downloaded/cached. Within Circle CI, it may be fetching latest provider that is available(which may have some issues). I would suggest you find the provider version currently in use locally, and then add required_providers block accordingly to make sure that it uses the same version of the provider. You can find the version presently in use from the terminal output that is generated on 'terraform init'. Below is the sample block to specify specific provider version(taken from: https://registry.terraform.io/providers/aeirola/bitbucket/latest/docs/resources/repository).
terraform {
required_providers {
bitbucket = {
source = "DrFaust92/bitbucket"
version = "v2.30.0"
}
}
}

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 clone git repo at plan or init stage

Context:
I am building API Gateway with OpenAPI Specifications 3.0 using terraform. I have got the api-spec.yaml file in a different repo from the terraform code. So, here's what I have done so far.
Using null_resource to clone the repo at the desired location
resource "null_resource" "clone-spec-file" {
provisioner "local-exec" {
command = "git clone https://gitlab.com/dShringi/openapi-spec.git"
}
}
Using the cloned api-spec file while creating the api gateway resource
data "template_file" swagger {
template = file("./openapi-spec/api-spec.yaml")
depends_on = ["null_resource.clone-spec-file"]
}
Problem:
The script fails at terraform plan because although I have used depends_on with template_file, it doesn't actually clones the repo at plan stage but it checks if the file is present and hence it fails with file not found at template = file("./openapi-spec/api-spec.yaml").
Will appreciate any thoughts regarding how it can be best handled, thanks.

terraform sub-module changes not being recognized in plan or apply

i have a terraform repo that looks something like this:
infrastructure
global
main.tf
The main.tf file references a module in a remote repository:
module "global" {
source = "git#github.com/company/repo//domain/global"
}
and the above module makes a reference to another module within the same remote repo: main.tf
module "global" {
source = "git#github.com/company/repo//infrastructure/global"
}
If i make a change in this module thats 3 levels deep, and then run terraform get and terraform init in the top level Terraform project followed by terraform plan, those changes aren't picked up.
Is there any reason for this?
i needed to do one of the following:
1) when running terraform init, i needed to pass the flag upgrade=true
2) or if running terraform get, i needed to pass the flag update=true
this downloads the latest versions of the requested modules

The module root could not be found. There is nothing to output

Running a terraform output in my root Terraform directory I get:
The module root could not be found. There is nothing to output.
I have the following files:
iam.tf:
resource "aws_iam_user" "a_user" {
name = "a_user"
}
output.tf:
data "aws_caller_identity" "current" {}
output "account_id" {
value = "${data.aws_caller_identity.current.account_id}"
}
This https://www.terraform.io/docs/modules/index.html says:
Root module That is the current working directory when you run terraform apply or get, holding the Terraform configuration files. It is itself a valid module.
Any idea why the error message and how to fix?
Terraform refers root module from terraform.tfstate file.
This file conatains all info about your last known state from .tf files along with output variables.
Which is generated after first execution terraform apply command into current directory.
Simply run terraform apply
, then terraform output will shows your output variables.
You haven't added your module config above, but assuming you have a module file then you have to tell terraform about the source. if the source is a sub directory called example in the same location as iam.tf and output.tf, then you have to add module as bellow, then run terraform apply from the directory where output.tf and iam.tf are:
module "consul" {
source = "./example"
}
If your output is a remote location (e.g github) then source has to be as below
module "consul" {
source = "github.com/some-git.git"
}
Then you have to run "terraform get" to download your module. Then "terraform apply" to apply the module, then "terraform output" to list the output you specified above
The problem is you have not added your module config file. Something along
module "test_module" {
source = "./test_module"
}
You have to make sure the module config exists and also the source is valid. To get output, you need a state file which is created after running terraform apply. Looks like you either dont have one or you have no output in your state file.

Resources