Remove shared creds file

This commit is contained in:
Conor McManus 2023-01-24 17:14:05 +01:00
parent 9491a890ab
commit c97850e916
3 changed files with 10 additions and 12 deletions

View file

@ -49,7 +49,6 @@ To get the most out of Terraform workspaces it is recommended that the AWS provi
provider "aws" {
region = "${var.region}"
profile = "${var.workspace}"
shared_credentials_file = ${var.shared_credentials_file}
}
```
@ -61,7 +60,7 @@ variable "workspace" {
}
```
This will make Terraform lookup AWS credentials from the `~/.aws/credentials` file using the workspace name as the stanza name. For example the credentials file would look like the shared-creds file in this repo.
This will make Terraform lookup AWS credentials from the `~/.aws/credentials` file using the workspace name as the stanza name.
## atmos -e

View file

@ -35,7 +35,6 @@ def determine_actions(args, params):
if (args.command in env_actions) and not (args.n): # Append with env context
cmd = cmd + ' -var-file=vars/{env}.tfvars'.format(env=workspace_vars)
cmd = cmd + ' -var "workspace={env}"'.format(env=workspace)
cmd = cmd + ' -var "shared_credentials_file={aws_creds_file}"'.format(aws_creds_file=aws_creds_file)
for param in params: # Pass terraform params directly through
cmd = cmd + ' ' + param

View file

@ -22,35 +22,35 @@ class DetermineActionsTests(unittest.TestCase):
@patch("workspaces.get_env")
def test_whenCalledWithInitCommand_shouldAppendVarsAndCreds(self, mocked_get_env):
"""Case where var-file, -var workpace=xyz and -var shared_credentials is appended"""
"""Case where var-file, -var workpace=xyz is appended"""
self.input_args.command = "init"
mocked_get_env.return_value = "mytestenv"
atmos.determine_actions(self.input_args, [])
atmos.run_cmd.assert_called_with('terraform init -var-file=vars/mytestenv.tfvars -var "workspace=mytestenv" -var "shared_credentials_file=$HOME/.aws/credentials"')
atmos.run_cmd.assert_called_with('terraform init -var-file=vars/mytestenv.tfvars -var "workspace=mytestenv"')
@patch("workspaces.get_env")
def test_whenCalledWithPlanCommand_shouldAppendVarsAndCreds(self, mocked_get_env):
"""Case where var-file, -var workpace=xyz and -var shared_credentials is appended"""
"""Case where var-file, -var workpace=xyz is appended"""
self.input_args.command = "plan"
mocked_get_env.return_value = "mytestenv"
atmos.determine_actions(self.input_args, [])
atmos.run_cmd.assert_called_with('terraform plan -var-file=vars/mytestenv.tfvars -var "workspace=mytestenv" -var "shared_credentials_file=$HOME/.aws/credentials"')
atmos.run_cmd.assert_called_with('terraform plan -var-file=vars/mytestenv.tfvars -var "workspace=mytestenv"')
@patch("workspaces.get_env")
def test_whenCalledWithApplyCommand_shouldAppendVarsAndCreds(self, mocked_get_env):
"""Case where var-file, -var workpace=xyz and -var shared_credentials is appended"""
"""Case where var-file, -var workpace=xyz is appended"""
self.input_args.command = "apply"
mocked_get_env.return_value = "mytestenv"
atmos.determine_actions(self.input_args, [])
atmos.run_cmd.assert_called_with('terraform apply -var-file=vars/mytestenv.tfvars -var "workspace=mytestenv" -var "shared_credentials_file=$HOME/.aws/credentials"')
atmos.run_cmd.assert_called_with('terraform apply -var-file=vars/mytestenv.tfvars -var "workspace=mytestenv"')
@patch("workspaces.get_env")
def test_whenCalledWithDestroyCommand_shouldAppendVarsAndCreds(self, mocked_get_env):
"""Case where var-file, -var workpace=xyz and -var shared_credentials is appended"""
"""Case where var-file, -var workpace=xyz is appended"""
self.input_args.command = "destroy"
mocked_get_env.return_value = "mytestenv"
atmos.determine_actions(self.input_args, [])
atmos.run_cmd.assert_called_with('terraform destroy -var-file=vars/mytestenv.tfvars -var "workspace=mytestenv" -var "shared_credentials_file=$HOME/.aws/credentials"')
atmos.run_cmd.assert_called_with('terraform destroy -var-file=vars/mytestenv.tfvars -var "workspace=mytestenv"')
@patch("workspaces.workspace_manager")
def test_whenInAGitRepo_andManualArgIsNotGiven_andEnvironmentArgIsNotGiven_shouldCallTheWorkspaceManager(self, mocked_workspace_manager):
@ -66,4 +66,4 @@ class DetermineActionsTests(unittest.TestCase):
if __name__ == '__main__':
unittest.main()
unittest.main()