turbot / steampipe

Zero-ETL, infinite possibilities. Live query APIs, code & more with SQL. No DB required.
https://steampipe.io
GNU Affero General Public License v3.0
6.84k stars 264 forks source link

Running `steampipe mod install <mod URL>` in a dir with an existing mod.sp adds invalid `plugins` and modifies `documentation` #3279

Closed cbruno10 closed 1 year ago

cbruno10 commented 1 year ago

Describe the bug If I have a mod.sp in a dir:

mod "aws_well_architected" {
  # hub metadata
  title         = "AWS Well Architected"
  description   = "TO-DO"
  color         = "#FF9900"
  documentation = file("./docs/index.md")
  icon          = "/images/mods/turbot/aws_well_architected.svg"
  categories    = ["aws", "cis", "compliance", "pci dss", "public cloud", "security"]

  opengraph {
    title       = "Steampipe Mod for AWS Well Architected"
    description = "TO-DO"
    image       = "/images/mods/turbot/aws_well_architected_social_graphic.png"
  }

  require {
    steampipe = "0.19.1"
    plugin "aws"{
      version = "0.90"
    }
    mod "github.com/turbot/steampipe-mod-aws-compliance" {
      version = "0.57"
    }
  }
}

If I run steampipe mod install github.com/turbot/steampipe-mod-aws-compliance, it changes my mod.sp to:

mod "aws_well_architected" {
  title         = "AWS Well Architected"
  description   = "TO-DO"
  color         = "#FF9900"
  documentation = "---\nrepository: \"https://github.com/turbot/steampipe-mod-aws-well-architected\"\n---\n"
  icon          = "/images/mods/turbot/aws_well_architected.svg"
  categories    = ["aws", "cis", "compliance", "pci dss", "public cloud", "security"]
  opengraph {
    title       = "Steampipe Mod for AWS Well Architected"
    description = "TO-DO"
    image       = "/images/mods/turbot/aws_well_architected_social_graphic.png"
  }
  require {
    steampipe = "0.19.1"
    plugins   = [""]
    mod "github.com/turbot/steampipe-mod-aws-compliance" {
      version = "latest"
    }
  }
}

Notably, the documentation has changed and under require, my plugin was removed and now it has plugins = [""]

Steampipe version (steampipe -v) v0.19.3

To reproduce See steps above

Expected behavior The documentation field should not change and the plugins field should not change either.

Additional context Add any other context about the problem here.

stgarf-sx commented 1 year ago

I just ran into this issue as well.

I fixed it by removing the mod repo directory, cd'ing to my home directory and re-installing the mod and then steampipe instead downloaded the module and installed it to ~/.steampipe/mods.

This error occured becase I did sp mod install github.com/turbot/steampipe-mod-aws-insights while I was inside the repo that I downloaded to my repos directory, steampipe-mod-aws-insights.

binaek commented 1 year ago

When there's a plugin block in the require block, the update from mod install or mod uninstall corrupts the mod.sp file.

Example:

Starting withe the following mod.sp:

mod "local" {
  title = "modtest"

  require {
    mod "github.com/pskrbasu/steampipe-mod-dependency-vars-1" {
      version = "*"
    }
    mod "github.com/pskrbasu/steampipe-mod-m4" {
      version = "*"
    }
    plugin "aws" {
      version = "0.86.0"
    }
  }
}

Running steampipe mod uninstall github.com/pskrbasu/steampipe-mod-m4 corrupts the mod.sp file and leaves behind the following:

mod "local" {
  title = "modtest"
  require {
    plugins = [""]
    mod "github.com/pskrbasu/steampipe-mod-dependency-vars-1" {
      version = "*"
    }
  }
}

Trying to run steampipe with the corrupt mod.sp results in a fatal error with the message:

Error: failed to load mod definition: Failed to load mod:
Unsupported argument: An argument named "plugins" is not expected here.
(/Users/binaek/modtest/mod.sp:5,5-12)
binaek commented 1 year ago

Variables set on mod requires are not retained after mod install before

after running steampipe mod uninstall github.com/pskrbasu/steampipe-mod-m4

after