diff --git a/internal/deploy/devops_service.go b/internal/deploy/devops_service.go index 7f71f59..49e761d 100644 --- a/internal/deploy/devops_service.go +++ b/internal/deploy/devops_service.go @@ -79,36 +79,65 @@ func (c *DevOpsServiceClient) RestartServer() error { return nil } -func (c *DevOpsServiceClient) InstallDependencies() ([]string, error) { - installed_dependencies := []string{} - _, ok := c.client.(*localclient.LocalClient) - if !ok { - if err := c.InstallBrew(); err != nil { - return installed_dependencies, err +func containsDependency(arr []string, value string) bool { + for _, v := range arr { + if v == value { + return true } + } + return false +} - gitPresent := c.findPath("git") - if gitPresent == "" { - if err := c.InstallGit(); err != nil { - return installed_dependencies, err - } - installed_dependencies = append(installed_dependencies, "git") - } +func (c *DevOpsServiceClient) InstallDependencies(listToInstall []string) ([]string, error) { + installed_dependencies := []string{} + _, ok := c.client.(*localclient.LocalClient) - packerPresent := c.findPath("packer") - if packerPresent == "" { - if err := c.InstallPacker(); err != nil { - return installed_dependencies, err - } - installed_dependencies = append(installed_dependencies, "packer") - } + if err := c.InstallBrew(); err != nil { + return installed_dependencies, err + } + installed_dependencies = append(installed_dependencies, "brew") - vagrantPresent := c.findPath("vagrant") - if vagrantPresent == "" { - if err := c.InstallVagrant(); err != nil { - return installed_dependencies, err + if !ok { + for _, dep := range listToInstall { + switch dep { + case "brew": + brewPresent := c.findPath("brew") + if brewPresent == "" { + if err := c.InstallBrew(); err != nil { + return installed_dependencies, err + } + installed_dependencies = append(installed_dependencies, "brew") + } + case "git": + gitPresent := c.findPath("git") + brewPresent := c.findPath("brew") + if gitPresent == "" && brewPresent == "" { + if err := c.InstallGit(); err != nil { + return installed_dependencies, err + } + installed_dependencies = append(installed_dependencies, "git") + } + case "packer": + packerPresent := c.findPath("packer") + brewPresent := c.findPath("brew") + if packerPresent == "" && brewPresent == "" { + if err := c.InstallPacker(); err != nil { + return installed_dependencies, err + } + installed_dependencies = append(installed_dependencies, "packer") + } + case "vagrant": + vagrantPresent := c.findPath("vagrant") + brewPresent := c.findPath("brew") + if vagrantPresent == "" && brewPresent == "" { + if err := c.InstallVagrant(); err != nil { + return installed_dependencies, err + } + installed_dependencies = append(installed_dependencies, "vagrant") + } + default: + return installed_dependencies, errors.New("Unsupported dependency") } - installed_dependencies = append(installed_dependencies, "vagrant") } } else { return installed_dependencies, errors.New("Unsupported client") diff --git a/internal/deploy/resource.go b/internal/deploy/resource.go index 5aca4ca..61ced5e 100644 --- a/internal/deploy/resource.go +++ b/internal/deploy/resource.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "strings" + "terraform-provider-parallels-desktop/internal/common" "terraform-provider-parallels-desktop/internal/deploy/schemas" "terraform-provider-parallels-desktop/internal/interfaces" @@ -851,9 +852,14 @@ func (r *DeployResource) installParallelsDesktop(parallelsClient *DevOpsServiceC diag := diag.Diagnostics{} var installDependenciesError error var installed_dependencies []string + mandatoryDependencies := []string{ + "brew", + "git", + "vagrant", + } // installing dependencies - installed_dependencies, installDependenciesError = parallelsClient.InstallDependencies() + installed_dependencies, installDependenciesError = parallelsClient.InstallDependencies(mandatoryDependencies) if installDependenciesError != nil { if uninstallErrors := parallelsClient.UninstallDependencies(installed_dependencies); len(uninstallErrors) > 0 { for _, uninstallError := range uninstallErrors {