Skip to content

create_environment_v3 submodule fail to create a composer environment if create_network_attachment is false. #161

@jalonsoa

Description

@jalonsoa

TL;DR

Hi team !
when we try to create a composer environment using de v2 submodule, the apply fail with error about the network attach not belongs to the composer project.

Reviewing the code, you have a typo in the network attachment name. In the file modules/create_environment_v3/main.tf, line 51, you have:

composer_network_attachment = var.create_network_attachment ? null : "projects/{var.project_id}/regions/${var.region}/networkAttachments/${var.composer_network_attachment_name}"

Note the lack of the $ before de var.project_interpolation.

Please fix this typo !

thanks

Expected behavior

The environment is created fine.

Observed behavior

Error with the message:


│ Error: googleapi: Error 400: Found 1 problem:
│ 1) Network Attachment ('projects/{var.project_id}/regions/europe-west1/networkAttachments/composer-network-attachment') does not belong to Composer project ('my-project')., badRequest

│ with module.env.module.composer_environment.google_composer_environment.composer_env,
│ on .terraform/modules/env.composer_environment/modules/create_environment_v3/main.tf line 23, in resource "google_composer_environment" "composer_env":
│ 23: resource "google_composer_environment" "composer_env" {

Terraform Configuration

resource "google_compute_network_attachment" "composer-atachment" {
  provider = google-beta
  project  = var.project_id

  name   = "composer-network-attachment"
  region = var.region
  description = "Composer network attachment"

  subnetworks = [var.base_subnet_self_link]
  connection_preference = "ACCEPT_AUTOMATIC"
}

module "gcp_composer_jerry_environment" {
  source  = "terraform-google-modules/composer/google//modules/create_environment_v3"
  version = "~> 6.1.0"

  composer_env_name         = "composer"
  composer_service_account  = module.sa_composer.email
  grant_sa_agent_permission = false

  project_id = var.project_id
  region     = var.region

  network                          = 
  subnetwork                       = data.google_compute_subnetwork.composer.name
  network_project_id               = data.google_compute_subnetwork.composer.project

  composer_network_attachment_name = google_compute_network_attachment.composer-atachment.name
  create_network_attachment        = false

  environment_size                 = "ENVIRONMENT_SIZE_SMALL"
  storage_bucket                   = module.buckets_composer.names["config"]

  kms_key_name                     = module.kms_composer.keys["composer-key"]

  use_private_environment    = true
  enable_private_builds_only = true
  web_server_plugins_mode    = "DISABLED"
}

Terraform Version

Terraform v1.10.4
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v6.31.0
+ provider registry.terraform.io/hashicorp/google-beta v6.31.0
+ provider registry.terraform.io/hashicorp/null v3.2.4
+ provider registry.terraform.io/hashicorp/random v3.7.2

Your version of Terraform is out of date! The latest version
is 1.11.3. You can update by downloading from https://www.terraform.io/downloads.html

Terraform Provider Versions

Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/google-beta] >= 3.77.0, < 7.0.0
├── provider[registry.terraform.io/hashicorp/null] ~> 3.0
├── provider[terraform.io/builtin/terraform]
├── provider[registry.terraform.io/hashicorp/random] ~> 3.1
├── provider[registry.terraform.io/hashicorp/google] >= 3.77.0, < 7.0.0
└── module.env
    ├── provider[registry.terraform.io/hashicorp/null] ~> 3.0
    ├── provider[registry.terraform.io/hashicorp/random] ~> 3.1
    ├── provider[registry.terraform.io/hashicorp/google] >= 3.61.0
    ├── provider[registry.terraform.io/hashicorp/google-beta] >= 3.61.0
    ├── module.gcp_sa_jerry_datalake
    │   └── provider[registry.terraform.io/hashicorp/google] >= 3.53.0, < 7.0.0
    ├── module.gcp_artifact_registry_jerry_repository_iam_bindings
    │   ├── provider[registry.terraform.io/hashicorp/google] >= 3.53.0, < 7.0.0
    │   ├── provider[registry.terraform.io/hashicorp/google-beta] >= 3.53.0, < 7.0.0
    │   └── module.helper
    ├── module.gcp_sa_jerry_cloud_run
    │   └── provider[registry.terraform.io/hashicorp/google] >= 3.53.0, < 7.0.0
    ├── module.gcp_kms_jerry_datalake_crypto_key_iam_bindings
    │   ├── provider[registry.terraform.io/hashicorp/google] >= 3.53.0, < 7.0.0
    │   └── module.helper
    ├── module.gcs_buckets_jerry_datalake
    │   ├── provider[registry.terraform.io/hashicorp/google] >= 5.22.0, < 7.0.0
    │   └── provider[registry.terraform.io/hashicorp/random] >= 2.1.0
    ├── module.gcs_buckets_tom_rrhh
    │   ├── provider[registry.terraform.io/hashicorp/random] >= 2.1.0
    │   └── provider[registry.terraform.io/hashicorp/google] >= 5.22.0, < 7.0.0
    ├── module.gcp_composer_jerry_environment
    │   ├── provider[registry.terraform.io/hashicorp/google] >= 6.0.0, < 7.0.0
    │   └── provider[registry.terraform.io/hashicorp/google-beta] >= 6.0.0, < 7.0.0
    ├── module.gcp_kms_jerry_composer_crypto_key_iam_bindings
    │   ├── provider[registry.terraform.io/hashicorp/google] >= 3.53.0, < 7.0.0
    │   └── module.helper
    ├── module.gcp_sa_jerry_project_iam_bindings
    │   ├── provider[registry.terraform.io/hashicorp/google] >= 3.53.0, < 7.0.0
    │   └── module.helper
    ├── module.gcp_kms_jerry_composer
    │   └── provider[registry.terraform.io/hashicorp/google] >= 5.31.0, < 7.0.0
    ├── module.gcs_buckets_tom_financiero
    │   ├── provider[registry.terraform.io/hashicorp/google] >= 5.22.0, < 7.0.0
    │   └── provider[registry.terraform.io/hashicorp/random] >= 2.1.0
    ├── module.gcp_secret_manager_jerry_cloud_run_iam_bindings
    │   ├── provider[registry.terraform.io/hashicorp/google] >= 3.53.0, < 7.0.0
    │   └── module.helper
    ├── module.gcs_buckets_jerry_composer
    │   ├── provider[registry.terraform.io/hashicorp/random] >= 2.1.0
    │   └── provider[registry.terraform.io/hashicorp/google] >= 5.22.0, < 7.0.0
    ├── module.gcp_sa_jerry_composer
    │   └── provider[registry.terraform.io/hashicorp/google] >= 3.53.0, < 7.0.0
    └── module.gcp_kms_jerry_datalake
        └── provider[registry.terraform.io/hashicorp/google] >= 5.31.0, < 7.0.0

Providers required by state:

    provider[registry.terraform.io/hashicorp/google]

    provider[registry.terraform.io/hashicorp/google-beta]

    provider[registry.terraform.io/hashicorp/random]

    provider[terraform.io/builtin/terraform]

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions