Skip to content

Commit

Permalink
Add an option to force disable using AWS to get configuration from th…
Browse files Browse the repository at this point in the history
…e parameter store

Also add environment variables to disable mapping of the home and temp folders
AWS_NO_HOME == --no-home
AWS_NO_TEMP == --no-temp
AWS_NO_AWS == --no-aws
  • Loading branch information
jocgir committed Apr 24, 2019
1 parent 81c52f5 commit 389e924
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ or install it through command line:
On `OSX`:

```bash
curl -sL https://github.com/coveo/tgf/releases/download/v1.19.1/tgf_1.19.1_macOS_64-bits.zip | bsdtar -xf- -C /usr/local/bin
curl -sL https://github.com/coveo/tgf/releases/download/v1.19.2/tgf_1.19.2_macOS_64-bits.zip | bsdtar -xf- -C /usr/local/bin
```

On `Linux`:

```bash
curl -sL https://github.com/coveo/tgf/releases/download/v1.19.1/tgf_1.19.1_linux_64-bits.zip | gzip -d > /usr/local/bin/tgf && chmod +x /usr/local/bin/tgf
curl -sL https://github.com/coveo/tgf/releases/download/v1.19.2/tgf_1.19.2_linux_64-bits.zip | gzip -d > /usr/local/bin/tgf && chmod +x /usr/local/bin/tgf
```

On `Windows` with Powershell:

```powershell
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest https://github.com/coveo/tgf/releases/download/v1.19.1/tgf_1.19.1_windows_64-bits.zip -OutFile tgf.zip
Invoke-WebRequest https://github.com/coveo/tgf/releases/download/v1.19.2/tgf_1.19.2_windows_64-bits.zip -OutFile tgf.zip
```

## Configuration
Expand Down Expand Up @@ -150,7 +150,7 @@ IMPORTANT: Most of the tgf command line arguments are in uppercase to avoid pote
It is also possible to specify additional arguments through environment variable TGF_ARGS or enable debugging mode through TGF_DEBUG.
VERSION: 1.19.1
VERSION: 1.19.2
AUTHOR: Coveo
Expand All @@ -159,8 +159,9 @@ Flags:
-D, --debug-docker Print the docker command issued
-F, --flush-cache Invoke terragrunt with --terragrunt-update-source to flush the cache
--get-image-name Just return the resulting image name (alias --gi)
--no-home Disable the mapping of the home directory (alias --nh)
--no-temp Disable the mapping of the temp directory (alias --nt)
--no-home Disable the mapping of the home directory (alias --nh) or set TGF_NO_HOME
--no-temp Disable the mapping of the temp directory (alias --nt) or set TGF_NO_TEMP
--no-aws Disable use of AWS to get configuration (alias --na) or set TGF_NO_AWS
--refresh-image Force a refresh of the docker image (alias --ri)
--local-image If set, TGF will not pull the image when refreshing (alias --li)
--interactive On by default, use --no-interactive or --no-it to disable launching Docker in interactive mode or set TGF_INTERACTIVE to 0 or false
Expand Down
6 changes: 5 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,17 @@ func parseSsmConfig(parameterValues map[string]string) string {
// We call this function before trying to init an AWS session. This avoid trying to init a session in a non AWS context
// and having to wait for metadata resolution or generating an error.
func awsConfigExist() bool {
if noAWS {
return false
}

if os.Getenv("AWS_PROFILE")+os.Getenv("AWS_ACCESS_KEY_ID")+os.Getenv("AWS_CONFIG_FILE") != "" {
// If any AWS identification variable is defined, we consider that we are in an AWS environment.
return true
}

if _, err := exec.LookPath("aws"); err == nil {
// If aws program is installed, we also consider that we are in an AWS environment.
// If aws program is installed, we also consider that we are in an AWS environment.
return true
}

Expand Down
14 changes: 10 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

// Version is initialized at build time through -ldflags "-X main.Version=<version number>"
var version = "1.19.1"
var version = "1.19.2"

var description = `
DESCRIPTION:
Expand Down Expand Up @@ -69,6 +69,7 @@ var (
mountPoint string
noHome bool
noTemp bool
noAWS bool
refresh bool
useLocalImage bool
dockerInteractive = true
Expand Down Expand Up @@ -96,6 +97,9 @@ const (
envLocation = "TGF_CONFIG_LOCATION"
envConfigFiles = "TGF_CONFIG_FILES"
envInteractive = "TGF_INTERACTIVE"
envNoHome = "TGF_NO_HOME"
envNoTemp = "TGF_NO_TEMP"
envNoAWS = "TGF_NO_AWS"
)

func main() {
Expand Down Expand Up @@ -143,8 +147,9 @@ func main() {
app.Switch("debug-docker", "Print the docker command issued", 'D').BoolVar(&debugMode)
app.Switch("flush-cache", "Invoke terragrunt with --terragrunt-update-source to flush the cache", 'F').BoolVar(&flushCache)
app.Switch("get-image-name", "Just return the resulting image name (alias --gi)").BoolVar(&getImageName)
app.Switch("no-home", "Disable the mapping of the home directory (alias --nh)").BoolVar(&noHome)
app.Switch("no-temp", "Disable the mapping of the temp directory (alias --nt)").BoolVar(&noTemp)
app.Switch("no-home", "Disable the mapping of the home directory (alias --nh) or set "+envNoHome).Envar(envNoHome).BoolVar(&noHome)
app.Switch("no-temp", "Disable the mapping of the temp directory (alias --nt) or set "+envNoTemp).Envar(envNoTemp).BoolVar(&noTemp)
app.Switch("no-aws", "Disable use of AWS to get configuration (alias --na) or set "+envNoAWS).Envar(envNoAWS).BoolVar(&noAWS)
app.Switch("refresh-image", "Force a refresh of the docker image (alias --ri)").BoolVar(&refresh)
app.Switch("local-image", "If set, TGF will not pull the image when refreshing (alias --li)").BoolVar(&useLocalImage)
app.Switch("interactive", "On by default, use --no-interactive or --no-it to disable launching Docker in interactive mode or set "+envInteractive+" to 0 or false").Envar(envInteractive).BoolVar(&dockerInteractive)
Expand Down Expand Up @@ -172,6 +177,7 @@ func main() {
app.Switch("gi", "alias for get-image-name").Hidden().BoolVar(&getImageName)
app.Switch("nh", "alias for no-home").Hidden().BoolVar(&noHome)
app.Switch("nt", "alias for no-temp").Hidden().BoolVar(&noTemp)
app.Switch("na", "alias for no-aws").Hidden().BoolVar(&noAWS)
app.Switch("cv", "alias for current-version").Hidden().BoolVar(getCurrentVersion)
app.Switch("av", "alias for all-versions").Hidden().BoolVar(getAllVersions)
app.Switch("wd", "alias for with-docker").Hidden().BoolVar(withDockerMount)
Expand All @@ -183,7 +189,7 @@ func main() {
app.Argument("iu", "alias for ignore-user-config").Hidden().BoolVar(&disableUserConfig)
app.Argument("iuc", "alias for ignore-user-config").Hidden().BoolVar(&disableUserConfig)

// Split up the managed parameters from the unmanaged onese
// Split up the managed parameters from the unmanaged ones
if extraArgs, ok := os.LookupEnv(envArgs); ok {
os.Args = append(os.Args, strings.Split(extraArgs, " ")...)
}
Expand Down

0 comments on commit 389e924

Please sign in to comment.