aztfmod / rovergo

The next version of Rover, the command line tool for Azure CAF Landingzones. Developed in Go
MIT License
10 stars 7 forks source link

rovergo can't use caf_solutions/addons #142

Open arne21a opened 2 years ago

arne21a commented 2 years ago

rovergo only expects you to use caf_launchpad or caf_solutions. When using caf_solution/addons the cli parser fails.

Rover(sh) has the -lz option with which you can point to every terraform root directory on you machine. Here is an example how to apply the devops_v1 addon from launchpad docs using rover(sh)

rover -lz /tf/caf/caf_solution/add-ons/azure_devops_v1 \
  -tfstate azure_devops-contoso_demo.tfstate \
  -var-folder /tf/caf/caf_solution/add-ons/azure_devops_v1/scenario/200-contoso_demo \
  -parallelism 30 \
  -level level0 \
  -env sandpit \
  -a apply

when using rovergo, you can't just point to that folder, because the cli parser expects you to have one of those suffixes in your path to determine if you are rolling out caf_launchpad or caf_solution:

const cafLaunchPadDir = "/caf_launchpad"
const cafLandingzoneDir = "/caf_solution"

// SetSourcePath ensures the source path is correct and absolute
func (o *Options) SetSourcePath(sourcePath string) {
    if strings.HasSuffix(sourcePath, cafLaunchPadDir) || strings.HasSuffix(sourcePath, cafLandingzoneDir) {
        cobra.CheckErr(fmt.Sprintf("source should not include %s or %s", cafLandingzoneDir, cafLaunchPadDir))
    }

    // Convert to absolute paths as a precaution
    sourcePath, err := filepath.Abs(sourcePath)
    cobra.CheckErr(err)

    if o.LaunchPadMode {
        o.SourcePath = path.Join(sourcePath, cafLaunchPadDir)
    } else {
        o.SourcePath = path.Join(sourcePath, cafLandingzoneDir)
    }

So when I run

rover plan \
  --level level0 \
  --config-dir ./terraform-landingzones-configuration/configuration/prod/level0-addon-devops \
  --source ./terraform-landingzones/caf_solution/add-ons/azure_devops_v1/ \
  --environment prod \
  --statename azure_devops.tfstate \
  --debug

I get this response:

> $HOME/custom_actions directory exists - will not extract example files
>Unable to open source directory: /Users/me/Documents/......./terraform-landingzones/caf_solution/add-ons/azure_devops_v1/caf_solution
> Error: Source directory must exist for rover to run

Workaround: Move the addon content to a nested caf_solution folder so the path is: /Users/me/Documents/......./terraform-landingzones/caf_solution/add-ons/azure_devops_v1/caf_solution/. then use this command to configure your source:

--source ./terraform-landingzones/caf_solution/add-ons/azure_devops_v1/

Expected Behavior

Either of those:

  1. Have a way to disable input validation for --source parameter
  2. Have rovergo recognize that it is using an landingzone addon

Actual Behavior

rovergo fails with a misleading error message and does not allow to rollout the addon.

Steps to Reproduce the Problem

Theoretically it should be reproducible with every addon. In my specific case, I used the azure_devops_v1 with modified defaults.

Environment Details