From aa0f0a7a2d8c983febab9421d54a11eb55785887 Mon Sep 17 00:00:00 2001 From: magodo Date: Fri, 15 Oct 2021 10:28:20 +0800 Subject: [PATCH] cleanup --- .gitignore | 1 - .vscode/launch.json | 15 ------------ README.md | 29 ------------------------ internal/meta/tfinstall_find.go | 14 ++---------- internal/meta/tfinstall_find_fallback.go | 5 ++++ internal/meta/tfinstall_find_windows.go | 3 +++ main.go | 12 ---------- 7 files changed, 10 insertions(+), 69 deletions(-) delete mode 100644 .vscode/launch.json create mode 100644 internal/meta/tfinstall_find_fallback.go create mode 100644 internal/meta/tfinstall_find_windows.go diff --git a/.gitignore b/.gitignore index 3134c8b..cde0123 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ dist/ -aztfylogs.log \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 7402ec1..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Attach to Process", - "type": "go", - "request": "attach", - "mode": "local", - "processId": 28180 //change with your pid - } - ] -} \ No newline at end of file diff --git a/README.md b/README.md index 0e88240..d4ba68a 100644 --- a/README.md +++ b/README.md @@ -46,32 +46,3 @@ For example, the `azurerm_lb_backend_address_pool_address` is actually a propert Another popular case is that in the AzureRM provider, there are a bunch of "association" resources, e.g. the `azurerm_network_interface_security_group_association`. These "association" resources represent the association relationship between two Terraform resources (in this case they are `azurerm_network_interface` and `azurerm_network_security_group`). They also have some synthetic resource ID, e.g. `/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/microsoft.network/networkInterfaces/example|/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/networkSecurityGroups/group1`. Currently, this tool only works on the assumption that there is 1:1 mapping between Azure resources and the Terraform resources. - -## Development: How to debug using vscode - -### requirement -install vs code and go extension - -In vscode -> Ctrl + Shift + P -> -> Go: Install/Update Tools - - -### Debug -0. Uncoment line in the main.go - -1. go build -gcflags=all="-N -l" - -2. run the program - ./aztfy rg-my-demo - -4. Get pid - - Linux : pgrep aztfy - - Windows : Task manager / tab detail - -5. Update launch.json processId with aztfy pid - -6. launch debug session - -7. Press enter \ No newline at end of file diff --git a/internal/meta/tfinstall_find.go b/internal/meta/tfinstall_find.go index fc27df9..9c22967 100644 --- a/internal/meta/tfinstall_find.go +++ b/internal/meta/tfinstall_find.go @@ -3,7 +3,6 @@ package meta import ( "context" "fmt" - "log" "os" "path/filepath" "strconv" @@ -17,19 +16,10 @@ import ( // FindTerraform finds the path to the terraform executable whose version meets the min version constraint. // It first tries to find from the local OS PATH. If there is no match, it will then download the release of the minVersion from hashicorp to the tfDir. func FindTerraform(ctx context.Context, tfDir string, minVersion *version.Version) (string, error) { - var terraformPath, terraformExe string - - log.Println("FindTerraform loaded") - - if os.PathSeparator == '\\' { // windows - terraformExe = "terraform.exe" - } else { - terraformExe = "terraform" - } - + var terraformPath string opts := []tfinstall.ExecPathFinder{ tfinstall.LookPath(), - tfinstall.ExactPath(filepath.Join(tfDir, terraformExe)), + tfinstall.ExactPath(filepath.Join(tfDir, terraformBinary)), tfinstall.ExactVersion(minVersion.String(), tfDir), } diff --git a/internal/meta/tfinstall_find_fallback.go b/internal/meta/tfinstall_find_fallback.go new file mode 100644 index 0000000..9060266 --- /dev/null +++ b/internal/meta/tfinstall_find_fallback.go @@ -0,0 +1,5 @@ +//go:build !windows + +package meta + +const terraformBinary = "terraform" diff --git a/internal/meta/tfinstall_find_windows.go b/internal/meta/tfinstall_find_windows.go new file mode 100644 index 0000000..47e8266 --- /dev/null +++ b/internal/meta/tfinstall_find_windows.go @@ -0,0 +1,3 @@ +package meta + +const terraformBinary = "terraform.exe" diff --git a/main.go b/main.go index 7f41ade..0fd4ed2 100644 --- a/main.go +++ b/main.go @@ -19,22 +19,10 @@ func init() { flagVersion = flag.Bool("v", false, "Print version") } -// var reader = bufio.NewReader(os.Stdin) - const usage = `aztfy [option] ` func main() { - // os.Setenv("AZTFY_DEBUG", "true") - // os.Setenv("AZTFY_MOCK_CLIENT", "false") - // os.Setenv("AZTFY_LOGFILE", "aztfylogs.log") - - // log.Println("Main hitted") - - // input, _ := reader.ReadString('\n') - // value := strings.TrimSpace(input) - // fmt.Printf("input: %v", value) - flag.Usage = func() { fmt.Fprintf(flag.CommandLine.Output(), "%s\n", usage) flag.PrintDefaults()