I am trying to run terragrunt plan and get past the initialization, but when “refreshing tfstate in-memory”, I get below error. Feels like a misconfig, but not sure what the regex is matching against.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
[terragrunt] 2019/12/30 13:41:37 Running command: terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
------------------------------------------------------------------------
Error: "name" ("demo_stage-router") doesn't match regexp "^(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)$"
on main.tf line 32, in resource "google_compute_router" "vpc_router":
32: resource "google_compute_router" "vpc_router" {
Error: "name" ("demo_stage-subnetwork-public") doesn't match regexp "^(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)$"
on main.tf line 45, in resource "google_compute_subnetwork" "vpc_subnetwork_public":
45: resource "google_compute_subnetwork" "vpc_subnetwork_public" {
Error: "name" ("demo_stage-subnetwork-private") doesn't match regexp "^(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)$"
on main.tf line 92, in resource "google_compute_subnetwork" "vpc_subnetwork_private":
92: resource "google_compute_subnetwork" "vpc_subnetwork_private" {
[terragrunt] 2019/12/30 13:41:38 Hit multiple errors:
exit status 1
main.tf
Pasting just the vpc and vpc router resource blocks for now, let me know if you want to see more config from the tf file. Note that I don’t get any errors for the vpc resource…
resource "google_compute_network" "vpc" {
name = "${var.name_prefix}-network"
project = var.project
# Always define custom subnetworks
auto_create_subnetworks = "false"
# A global routing mode can have an unexpected impact on load balancers; always use a regional mode
routing_mode = "REGIONAL"
}
resource "google_compute_router" "vpc_router" {
name = "${var.name_prefix}-router"
project = var.project
region = var.region
network = google_compute_network.vpc.self_link
}
vpc terragrunt.hcl file
I am explicitly defining the inputs here because apparently, I cannot reference inputs defined in the root terragrunt.hcl.
terraform {
source = "github.com/<my_module_repo>//gcp_vpc_network?ref=v0.1"
}
# Include all settings from the root terragrunt.hcl file
include {
path = "../../../../terragrunt.hcl"
}
# These are the variables we have to pass in to use the module specified in the terragrunt configuration above
inputs = {
name_prefix = "demo_stage"
project = "<project_name>"
region = "asia-northeast1"
}
Self-resolved. I found may way to one of the google provider’s validation helpers, and saw some test code that tells me I should take out the underscore…someone can correct me but guess I can’t use them. After I change to a hypen, the plan succeeds.
func TestValidateGCPName(t *testing.T) {
x := []StringValidationTestCase{
// No errors
{TestName: "basic", Value: "foobar"},
{TestName: "with numbers", Value: "foobar123"},
{TestName: "short", Value: "f"},
{TestName: "long", Value: "foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo"},
{TestName: "has a hyphen", Value: "foo-bar"},
// With errors
{TestName: "empty", Value: "", ExpectError: true},
{TestName: "starts with a capital", Value: "Foobar", ExpectError: true},
{TestName: "starts with a number", Value: "1foobar", ExpectError: true},
**{TestName: "has an underscore", Value: "foo_bar", ExpectError: true},**
{TestName: "too long", Value: "foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob", ExpectError: true},
}
es := testStringValidationCases(x, validateGCPName)
if len(es) > 0 {
t.Errorf("Failed to validate GCP names: %v", es)
}
}