terraform-aws-opennext icon indicating copy to clipboard operation
terraform-aws-opennext copied to clipboard

Invalid AWS region error when using providers.tf

Open andylamp opened this issue 8 months ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing Issues

Current Behavior

Current behavior has a regression when you use the module and create a terraform plan with a providers.tf and a non-specific AWS region in the credentials used causes an invalid AWS region error as is shown in the output of terraform plan:

var.deploy-env
  The domain name to use.

  Enter a value: staging

module.opennext.module.cloudfront_logs.data.archive_file.cloudfront_logs_zip: Reading...
module.opennext.module.cloudfront_logs.data.archive_file.cloudfront_logs_zip: Read complete after 0s [id=36462a90b27335319e6d9356845c763c29fc07ba]
module.opennext.module.cloudfront_logs.data.aws_canonical_user_id.current: Reading...
module.opennext.module.cloudfront_logs.data.aws_region.current: Reading...
module.opennext.module.cloudfront_logs.data.aws_caller_identity.current: Reading...
module.opennext.module.cloudfront_logs.data.aws_iam_policy_document.cloudfront_logs_assume_role: Reading...
module.opennext.module.cloudfront_logs.data.aws_region.current: Read complete after 0s [id=eu-west-1]
data.aws_route53_zone.zone: Reading...
module.opennext.module.cloudfront_logs.data.aws_iam_policy_document.cloudfront_logs_assume_role: Read complete after 0s [id=2690255455]
module.opennext.data.aws_region.current: Reading...
module.opennext.data.aws_caller_identity.current: Reading...
module.opennext.data.aws_region.current: Read complete after 0s [id=eu-west-1]
module.opennext.module.cloudfront_logs.data.aws_canonical_user_id.current: Read complete after 1s [id=ca48308bbee5e7392497917a400b3819ccdf5c429a1bd4b26d81dd97f0ab1c7f]
module.opennext.data.aws_caller_identity.current: Read complete after 1s [id=161132967934]
module.opennext.module.cloudfront_logs.data.aws_caller_identity.current: Read complete after 1s [id=161132967934]
module.opennext.module.cloudfront_logs.data.aws_iam_policy_document.cloudwatch_logs_key_policy[0]: Reading...
module.opennext.module.cloudfront_logs.data.aws_iam_policy_document.cloudwatch_logs_key_policy[0]: Read complete after 0s [id=3898385926]
data.aws_route53_zone.zone: Read complete after 2s [id=Z3060VNZRGFCJY]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create
 <= read (data resources)

Terraform planned the following actions, but then encountered a problem:
.... more stuff here

Plan: 19 to add, 0 to change, 0 to destroy.
╷
│ Error: Invalid AWS Region: 
│ 
│   with module.opennext.module.assets.provider["registry.terraform.io/hashicorp/aws"],
│   on .terraform/modules/opennext/modules/opennext-assets/main.tf line 12, in provider "aws":
│   12: provider "aws" {
│ 
╵
╷
│ Error: Invalid AWS Region: 
│ 
│   with module.opennext.module.cloudfront.provider["registry.terraform.io/hashicorp/aws"],
│   on .terraform/modules/opennext/modules/opennext-cloudfront/main.tf line 12, in provider "aws":
│   12: provider "aws" {
│ 
╵
╷
│ Error: Invalid AWS Region: 
│ 
│   with module.opennext.module.revalidation_function.provider["registry.terraform.io/hashicorp/aws"],
│   on .terraform/modules/opennext/modules/opennext-lambda/main.tf line 16, in provider "aws":
│   16: provider "aws" {
│ 
╵
╷
│ Error: Invalid AWS Region: 
│ 
│   with module.opennext.module.warmer_function.provider["registry.terraform.io/hashicorp/aws"],
│   on .terraform/modules/opennext/modules/opennext-lambda/main.tf line 16, in provider "aws":
│   16: provider "aws" {
│ 
╵
╷
│ Error: Invalid AWS Region: 
│ 
│   with module.opennext.module.server_function.provider["registry.terraform.io/hashicorp/aws"],
│   on .terraform/modules/opennext/modules/opennext-lambda/main.tf line 16, in provider "aws":
│   16: provider "aws" {
│ 
╵
╷
│ Error: Invalid AWS Region: 
│ 
│   with module.opennext.module.image_optimization_function.provider["registry.terraform.io/hashicorp/aws"],
│   on .terraform/modules/opennext/modules/opennext-lambda/main.tf line 16, in provider "aws":
│   16: provider "aws" {
│ 
╵
╷
│ Error: Invalid AWS Region: 
│ 
│   with module.opennext.module.revalidation_queue.provider["registry.terraform.io/hashicorp/aws"],
│   on .terraform/modules/opennext/modules/opennext-revalidation-queue/main.tf line 12, in provider "aws":
│   12: provider "aws" {
│ 

Expected Behavior

To pass without an error.

Steps To Reproduce

Use the project as a resource within a project. The acm.tf are taken verbatim whereas the providers are put in providers.tf.

providers.tf:

provider "aws" {
  region = var.region
  default_tags {
    tags = local.default_tags
  }
}

provider "aws" {
  alias  = "global"
  region = "us-east-1"

  default_tags {
    tags = local.default_tags
  }
}

main.tf

# The main file that provisions the infra for the open-next cloudfront distributions

locals {
  domain_name = join(".", [var.deploy-env, var.domain-suffix])
  default_tags = {
    Project     = "my-next"
    Environment = var.deploy-env
    ManagedBy   = "Terraform"
  }
}

module "opennext" {
  source  = "nhs-england-tools/opennext/aws"
  version = "1.0.3"

  prefix              = "opennext"
  default_tags        = local.default_tags
  opennext_build_path = "../.open-next"
  hosted_zone_id      = data.aws_route53_zone.zone.zone_id

  cloudfront = {
    aliases             = [local.domain_name]
    acm_certificate_arn = aws_acm_certificate_validation.ssl_certificate.certificate_arn
    assets_paths        = ["/images/*"]
  }
}

Output

The error output provided above.

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

Sensitive Information Declaration

  • [X] I confirm that neither PII/PID nor sensitive data are included in this form

andylamp avatar Oct 31 '23 01:10 andylamp