From eb0547b51df9fb4610a48c7b51a2a856d7771734 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 15 Sep 2021 19:26:15 +0200 Subject: [PATCH] added awsCredentials function --- .../provs/workplace/infrastructure/DevOps.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/infrastructure/DevOps.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/infrastructure/DevOps.kt index dec4f92..e9bf39f 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/infrastructure/DevOps.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/infrastructure/DevOps.kt @@ -4,9 +4,12 @@ import org.domaindrivenarchitecture.provs.core.Prov import org.domaindrivenarchitecture.provs.core.ProvResult import org.domaindrivenarchitecture.provs.ubuntu.filesystem.base.createDirs import org.domaindrivenarchitecture.provs.ubuntu.filesystem.base.dirExists +import org.domaindrivenarchitecture.provs.ubuntu.filesystem.base.createFile + fun Prov.installDevOps() = def { installTerraform() + installAwsCredentials("", "") // TODO: get credentials from gopass } fun Prov.installTerraform(): ProvResult = def { @@ -23,3 +26,28 @@ fun Prov.installTerraform(): ProvResult = def { cmd ("tfenv use latest:^0.13", sudo = true) } +fun Prov.installAwsCredentials(id:String, key:String): ProvResult = def { + val dir = "~/.aws" + + if(!dirExists(dir)) { + createDirs(dir) + createFile("~/.aws/config", awsConfig()) + createFile("~/.aws/credentials", awsCredentials(id, key)) + } +} + +fun awsConfig(): String { + return """ + [default] + region = eu-central-1 + output = json + """.trimIndent() +} + +fun awsCredentials(id:String, key:String): String { + return """ + [default] + aws_access_key_id = $id + aws_secret_access_key = $key + """.trimIndent() +} \ No newline at end of file