hashicorp / hashicorp/web-unified-docs
local-exec provisioner doesn't run with the configured AWS provider account
- Dominant language
- MDX
- Stars
- 86
- Forks
- 275
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 196
Description
Summary: we have multiple AWS accounts configured for our users, one per deployment environment. We configure the Terraform AWS provider to use the right one for the right environment. However, when using the local-exec provisioner after creating a resource, the script provided to local-exec doesn't execute with the same AWS environment as
### Terraform Version
```
Terraform v0.12.3
```
### Terraform Configuration Files
Terraform resource with local-exec provisioner:
```hcl
resource "aws_eks_cluster" "eks" {
name = var.service_name
enabled_cluster_log_types = ["api", "audit", "authenticator", "controllerManager", "scheduler"]
provisioner "local-exec" {
command = "${path.module}/setup.sh ${var.service_name}"
}
role_arn = aws_iam_role.eks.arn
vpc_config {
endpoint_private_access = true
endpoint_public_access = false
security_group_ids = [aws_security_group.eks.id]
subnet_ids = var.subnet_ids
}
}
```
local-exec script for execution:
```sh
#!/bin/bash
aws eks list-clusters
aws eks wait cluster-active --name "$1"
aws eks update-kubeconfig --name "$1"
```
### Expected Behavior
Correctly runs script and configures local environment with the new EKS cluster details for further configuration, which is necessary as long as there's no dynamic provider configuration (see: hashicorp/terraform#4149).
### Actual Behavior
Script fails because it's run with the default AWS config and not the credentials configured in the provider:
```
available clusters...
{
"clusters": []
}
Waiter ClusterActive failed: No cluster found for name: eks-ci.
```
### Steps to Reproduce
1. configure an aws provider with an account other than the default.
2. configure a resource with a local-exec provisioner which runs aws commands.
3. watch it fail after running `terraform init && terraform apply`
### References
- this will go away if hashicorp/terraform#4149 gets addressed, since then we can dynamically configure the kubernetes provider after setting up the EKS cluster.
Contributor guide
Assessment
This issue has not been assessed yet.