redpanda-data / deployment-automation

Cluster configuration best practices
https://redpanda.com
Apache License 2.0
64 stars 47 forks source link

Terraform outside of AWS us-west-2 improperly attempts to create AZ still inside us-west-2 #183

Closed deniscoady closed 1 year ago

deniscoady commented 1 year ago

Attempting to create a cluster outside of AWS us-west-2 gives me an error with Terraform still attempting to create availability zones in us-west-2.

(base) deniscoady@MacBook-Pro aws % terraform apply -var="aws_region=us-east-2" -var="vpc_id=vpc-01832e9d82c782393" -var="subnet_id=subnet-085ca0e2cc01adcc1"
time_static.timestamp: Refreshing state... [id=2023-05-31T19:59:50Z]
random_uuid.cluster: Refreshing state... [id=62b090bf-4cf8-3157-5e95-ff8d17aee275]
data.aws_caller_identity.current: Reading...
data.aws_ami.ami: Reading...
data.aws_caller_identity.current: Read complete after 0s [id=605419575229]
data.aws_arn.caller_arn: Reading...
data.aws_arn.caller_arn: Read complete after 0s [id=arn:aws:iam::605419575229:user/deniscoady]
aws_key_pair.ssh: Refreshing state... [id=redpanda-62b090bf-1685563190-key]
data.aws_ami.ami: Read complete after 0s [id=ami-0b8f3e26fd8c1769f]

...

  # aws_instance.redpanda[2] will be created
  + resource "aws_instance" "redpanda" {
      + ami                                  = "ami-0b8f3e26fd8c1769f"
      + arn                                  = (known after apply)
      + associate_public_ip_address          = false
      + availability_zone                    = "us-west-2a"
      + cpu_core_count                       = (known after apply)
      + cpu_threads_per_core                 = (known after apply)
      + disable_api_stop                     = (known after apply)
      + disable_api_termination              = (known after apply)
      + ebs_optimized                        = (known after apply)
      + get_password_data                    = false
...

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_security_group.node_sec_group: Creating...
aws_security_group.node_sec_group: Creation complete after 2s [id=sg-04bad2aacef64bbec]
aws_instance.redpanda[1]: Creating...
aws_instance.redpanda[2]: Creating...
aws_instance.prometheus[0]: Creating...
aws_instance.redpanda[0]: Creating...
aws_instance.prometheus[0]: Still creating... [10s elapsed]
aws_instance.prometheus[0]: Creation complete after 12s [id=i-0ca530303b2717f18]
╷
│ Error: creating EC2 Instance: InvalidParameterValue: Invalid availability zone: [us-west-2a]
│   status code: 400, request id: 9e98579c-0d9e-4dd1-8836-d28c83a13012
│ 
│   with aws_instance.redpanda[1],
│   on cluster.tf line 74, in resource "aws_instance" "redpanda":
│   74: resource "aws_instance" "redpanda" {
│ 
╵
╷
│ Error: creating EC2 Instance: InvalidParameterValue: Invalid availability zone: [us-west-2a]
│   status code: 400, request id: 0c5db163-e036-4a5b-a3ab-ad665d7562b0
│ 
│   with aws_instance.redpanda[2],
│   on cluster.tf line 74, in resource "aws_instance" "redpanda":
│   74: resource "aws_instance" "redpanda" {
│ 
╵
╷
│ Error: creating EC2 Instance: InvalidParameterValue: Invalid availability zone: [us-west-2a]
│   status code: 400, request id: 710c6439-b677-459d-a002-e5e4c36a7cdb
│ 
│   with aws_instance.redpanda[0],
│   on cluster.tf line 74, in resource "aws_instance" "redpanda":
│   74: resource "aws_instance" "redpanda" {
│ 
╵
gene-redpanda commented 1 year ago

Currently it has a default value of

variable "availability_zone" {
  description = "The AWS AZ to deploy the infrastructure on"
  default     = ["us-west-2a"]
  type        = list(string)
}

It can be changed to other values.

I'm leaning toward nulling it by default because people don't really care about the AZ their instance is in in most cases, and if they do care then they'll want to set it themselves rather than use the default. Thanks for the issue!

deniscoady commented 1 year ago

Hey @gene-redpanda I also attempted to manually specify the AZ but got an error.

(base) deniscoady@MacBook-Pro aws % terraform apply -var="aws_region=us-east-2" -var="vpc_id=vpc-01832e9d82c782393" -var="subnet_id=subnet-085ca0e2cc01adcc1" -var="availability_zone=us-east-2"
╷
│ Error: Variables not allowed
│ 
│   on <value for var.availability_zone> line 1:
│   (source code not available)
│ 
│ Variables may not be used here.
╵
gene-redpanda commented 1 year ago

Has to be specified as a list, not an individual item!

deniscoady commented 1 year ago

Gotcha. I did the following and it worked.

-var='availability_zone=["us-east-2a"]'