TeliaSoneraNorge / telia-terraform-modules

Terraform modules for creating cloud infrastucture
MIT License
9 stars 7 forks source link

Errors in variables passed by module #69

Open lukaspour opened 6 years ago

lukaspour commented 6 years ago

Hi, I have an issue with variables which are used in rds-instance-full in case where I use them in a simple module:

module "neo_custom_rds" {
  source = "git::git@github.com:TeliaSoneraNorge/telia-terraform-modules.git//rds-instance-full"

  allocated_storage             = "${var.allocated_storage}"
  instance_class                = "${var.instance_class}"
  engine_version                = "${var.engine_version}"
  manual_db_snapshot_identifier = "${var.manual_db_snapshot_identifier}"
  database_name                 = "${var.database_name}"
  database_username             = "${var.database_username}"
  database_password             = "${var.database_password}"
  database_port                 = "${var.database_port}"
  tags                          = "${var.tags}"
  multi_az                      = "${var.multi_az}"
  maintenance_window            = "${var.maintenance_window}"
  backup_window                 = "${var.backup_window}"
  backup_retention_period       = "${var.backup_retention_period}"
  monitoring_interval           = "${var.monitoring_interval}"
  engine                        = "${var.engine}"
  family                        = "${var.family}"
  ingress_rule                  = "${var.ingress_rule}"
  parameters                    = "${var.parameters}"
  license_model                 = "${var.license_model}"
  custom_sg_id                  = "${data.terraform_remote_state.ecs.security_group_id}"
}

These are the errors:

Error: resource 'aws_ssm_parameter.database_username' config: unknown variable referenced: 'local_environment'; define it with a 'variable' block

Error: resource 'aws_ssm_parameter.database_password' config: unknown variable referenced: 'local_environment'; define it with a 'variable' block

Error: resource 'data.terraform_remote_state.vpc' config: unknown variable referenced: 'terraform_state_region'; define it with a 'variable' block

Error: resource 'data.terraform_remote_state.vpc' config: unknown variable referenced: 'terraform_state_bucket'; define it with a 'variable' block

Error: resource 'data.terraform_remote_state.vpc' config: unknown variable referenced: 'aws_region'; define it with a 'variable' block

Error: resource 'data.terraform_remote_state.vpc' config: unknown variable referenced: 'terraform_state_keys'; define it with a 'variable' block

Error: resource 'aws_ssm_parameter.database_url' config: unknown variable referenced: 'local_environment'; define it with a 'variable' block

And it seems pretty reasonable since none of those variables are defined in variables.ft of the module. When I use rds-instance-full directly in terraform.tfvars I have no problem.

I would change the rds module not use those variables or I would have to edit the module instead, which we said is not a good idea. Is there any other way how to pass the variables from one module to another? Thanks

antonbabenko commented 6 years ago

Make sure that you are using Terragrunt to run hook which will copy ./common/main_variables.tf AND lock version of the module.

lukaspour commented 6 years ago

Well the only thing I do is terragrunt plan at directory where I have terragrunt.tfvars file with source pointing to local RDS module:

terragrunt = {
  terraform {
    source = "${path_relative_from_include()}/../../..//modules/neo-rds"
  }
...

neo-rds module is doing nothing interesting so far, if I am going to get around this issue, I'll add there the remote state for ecs security group. neo-rds itself have reference in module to rds-instance-full.

Any advice is very appreciated, I guess I just missed something, that's why I struggle. Thanks!

antonbabenko commented 6 years ago

Could you show the code in git? Paste URL here.

lukaspour commented 6 years ago

Here is the branch https://github.com/TeliaSoneraNorge/devops/tree/rds_custom_sg, also WIP PR https://github.com/TeliaSoneraNorge/devops/pull/395

lukaspour commented 6 years ago

@mikael-lindstrom do you maybe have any idea how to go around this issue?

mikael-lindstrom commented 6 years ago

This seems to be related with terragrunt. I'm assuming that it has something to do with the hook that is supposed to copy some stuff automatically not working correctly.

These modules should be rewritten to be pure terraform so you can use them without terragrunt but for now I recommend double-checking the terragrunt hooks.

lukaspour commented 6 years ago

I've tried to pass the variables explicitly with no luck. What if I rewrite the module to terraform instead? It just seems to me faster than exploring not working hooks.