Hi all! I was wondering if anyone could shed some ...
# fleet
k
Hi all! I was wondering if anyone could shed some light on deploying fleet with terraform? I've had good success thus far but am running into issues when trying to apply the terraform state, looks like hte EC2 instance is trying to be created in the us-east regions, this is simply no good for me, i need it to be in us-west. Anyone know the easiest way for me to achieve this? This is more or less my first TF project, so hopefully I am just missing something simple. I've been following this guide https://fleetdm.com/deploy/deploying-fleet-on-aws-with-terraform
r
Hi Kolbe, you should be able to configure the aws provider
region
to
us-west
using something like:
Copy code
provider "aws" {
  region = "us-west"
}
k
thanks for the response @Rachel Perkins so I already have that in my code and did a little more digging, and the error occurs when I run this
Copy code
terraform apply -target module.fleet.module.vpc
it doesn't occur if I run a normal
Copy code
terraform apply
this guide tells me to first run the terraform apply -target command to create the VPC is there a way to force this command to us-west or do I need to BYO my own VPC?
start of my code block looks like this
Copy code
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
}

provider "aws" {
  region = "us-west-2"
  profile = "security" 
}
and still everything is being created in us-west
r
Hmm, let me ask our terraform expert
k
It may be because the other resources have already been built. What happens if you run
terraform destroy
and rebuild everything?
k
so terraform apply seems to work great, I am still encountering this one error
Copy code
│ Error: Invalid for_each argument
│ 
│   on .terraform/modules/fleet/terraform/byo-vpc/main.tf line 68, in data "aws_subnet" "redis":
│   68:   for_each = toset(var.redis_config.subnets)
│     ├────────────────
│     │ var.redis_config.subnets is list of string with 3 elements
but no issues with region however if I use
Copy code
terraform apply -target module.fleet.module.vpc
as per the documentation it tries to set all the regions to us-east
And yes I have tried destroying and rebuilding
k
@Benjamin Edwards Amy insight there?
k
ah so that invalid for_each error seems to be referring to due to the modules trying to reference data from something that is being created, so that makes sense why the
Copy code
terraform apply -target module.fleet.module.vpc
is required first. I just don't understand why it is defaulting to west, I even tried
Copy code
export AWS_DEFAULT_REGION=us-west-2
to no avail
b
What’s set in your profile file?
k
aws config?
b
Yessir
k
us-west-2
Copy code
cat ~/.aws/config         
[default]
region = us-west-2
output = yaml
Copy code
[profile security]
role_arn = arn:aws:iam::<private>:role/security_admin
source_profile = default
region = us-west-2