clong / DetectionLab

Automate the creation of a lab environment complete with security tooling and logging best practices
MIT License
4.59k stars 979 forks source link

Terraform AWS Provider Credentials are Inflexible #838

Closed zwinnerman-fleetdm closed 1 year ago

zwinnerman-fleetdm commented 2 years ago

Please verify that you are building from an updated Master branch before filing an issue.

Description of the issue:

The provider block, current reading this, is inflexible:

provider "aws" {
  shared_credentials_file = var.shared_credentials_file
  region                  = var.region
  profile                 = var.profile
}

This is because defaults are overridden and are not fixable without editing the code itself. A possible solution would be to remove the contents of the block, relying on default autoconfiguration and using data "aws_caller_identity" "current" {} to get the region variable. This should dramatically simplify setup, since there are less variable to specify, and allow for greater flexability for deployments.

Link to Gist Containing Build Logs:

│ Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
│ 
│ Please see https://registry.terraform.io/providers/hashicorp/aws
│ for more information about providing credentials.
│ 
│ Error: NoCredentialProviders: no valid providers in chain
│ caused by: EnvAccessKeyNotFound: failed to find credentials in the environment.
│ SharedCredsLoad: failed to load profile, terraform.
│ EC2RoleRequestError: no EC2 instance role found
│ caused by: RequestError: send request failed
│ caused by: Get "http://169.254.169.254/latest/meta-data/iam/security-credentials/": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
│ 
│ 
│   with module.detectionlabs.provider["registry.terraform.io/hashicorp/aws"],
│   on .terraform/modules/detectionlabs/AWS/Terraform/main.tf line 2, in provider "aws":
│    2: provider "aws" {
│ 
clong commented 1 year ago

Hi @zwinnerman-fleetdm - thanks so much for submitting a PR for this! Give me a couple of days (my free time is severely limited lately) to review and I should hopefully have this merged by Sunday. Really appreciate you improving this!