All Projects → microsoft → Psrule

microsoft / Psrule

Licence: mit
Validate infrastructure as code (IaC) and objects using PowerShell rules.

Programming Languages

powershell
5483 projects

Projects that are alternatives of or similar to Psrule

Pytest Testinfra
With Testinfra you can write unit tests in Python to test actual state of your servers configured by management tools like Salt, Ansible, Puppet, Chef and so on.
Stars: ✭ 1,987 (+1757.01%)
Mutual labels:  infrastructure-as-code, devops, devops-tools, testing-tools
Goss
Quick and Easy server testing/validation
Stars: ✭ 4,550 (+4152.34%)
Mutual labels:  infrastructure-as-code, devops, devops-tools, testing-tools
Terraboard
🌍 📋 A web dashboard to inspect Terraform States
Stars: ✭ 1,192 (+1014.02%)
Mutual labels:  infrastructure-as-code, devops, devops-tools
Catapult
💥 Catapult is a DevOps website management platform for development teams.
Stars: ✭ 64 (-40.19%)
Mutual labels:  infrastructure-as-code, devops, devops-tools
Cintodeutilidadesdocker
My Docker templates repository 🐳 ☁️ 🐳
Stars: ✭ 74 (-30.84%)
Mutual labels:  infrastructure-as-code, devops, devops-tools
Terracognita
Reads from existing Cloud Providers (reverse Terraform) and generates your infrastructure as code on Terraform configuration
Stars: ✭ 452 (+322.43%)
Mutual labels:  infrastructure-as-code, devops, devops-tools
Lynis
Lynis - Security auditing tool for Linux, macOS, and UNIX-based systems. Assists with compliance testing (HIPAA/ISO27001/PCI DSS) and system hardening. Agentless, and installation optional.
Stars: ✭ 9,137 (+8439.25%)
Mutual labels:  devops, devops-tools
Hashi Ui
A modern user interface for @hashicorp Consul & Nomad
Stars: ✭ 1,119 (+945.79%)
Mutual labels:  devops, devops-tools
Azure
Azure-related repository
Stars: ✭ 78 (-27.1%)
Mutual labels:  devops, devops-tools
Gomplate
A flexible commandline tool for template rendering. Supports lots of local and remote datasources.
Stars: ✭ 1,270 (+1086.92%)
Mutual labels:  devops, devops-tools
Awless Templates
Repository of examples for awless templates (see https://github.com/wallix/awless)
Stars: ✭ 59 (-44.86%)
Mutual labels:  devops, devops-tools
Envkey App
Secure, human-friendly, cross-platform secrets and config.
Stars: ✭ 83 (-22.43%)
Mutual labels:  devops, devops-tools
Python Hponeview
DEPRECATED - no longer actively maintained. New repository: https://github.com/HewlettPackard/oneview-python
Stars: ✭ 87 (-18.69%)
Mutual labels:  infrastructure-as-code, devops
Webterminal
ssh rdp vnc telnet sftp bastion/jump web putty xshell terminal jumpserver audit realtime monitor rz/sz 堡垒机 云桌面 linux devops sftp websocket file management rz/sz otp 自动化运维 审计 录像 文件管理 sftp上传 实时监控 录像回放 网页版rz/sz上传下载/动态口令 django
Stars: ✭ 1,124 (+950.47%)
Mutual labels:  devops, devops-tools
Ansible Podman Collections
Repository for Ansible content that can include playbooks, roles, modules, and plugins for use with the Podman tool
Stars: ✭ 89 (-16.82%)
Mutual labels:  devops, devops-tools
Terraformize
Apply\Destory Terraform modules via a simple REST API endpoint.
Stars: ✭ 84 (-21.5%)
Mutual labels:  infrastructure-as-code, devops
Copilot Cli
The AWS Copilot CLI is a tool for developers to build, release and operate production ready containerized applications on Amazon ECS and AWS Fargate.
Stars: ✭ 1,285 (+1100.93%)
Mutual labels:  infrastructure-as-code, devops
Lambda Cost Calculator
Forecast Lambda functions costs 💰
Stars: ✭ 91 (-14.95%)
Mutual labels:  devops, devops-tools
Awstaghelper
AWS bulk tagging tool
Stars: ✭ 98 (-8.41%)
Mutual labels:  devops, devops-tools
Lambda The Terraform Way
AWS Lambda using Terraform., an Introductory Cookbook
Stars: ✭ 1,056 (+886.92%)
Mutual labels:  infrastructure-as-code, devops

PSRule

A cross-platform module to validate infrastructure as code (IaC) and objects using PowerShell rules. PSRule works great and integrates with popular continuous integration (CI) systems.

ci-badge

Features of PSRule include:

  • Extensible - Use PowerShell, a flexible scripting language.
  • Cross-platform - Run on MacOS, Linux, and Windows.
  • Reusable - Share rules across teams or organizations.
  • Recommendations - Include detailed instructions to remediate issues.

Project objectives

  1. Extensible:
    • Provide an execution environment (tools and language) to validate infrastructure code.
    • Handling of common concerns such as input/ output/ reporting should be handled by the engine.
    • Language must be flexible enough to support a wide range of use cases.
  2. DevOps:
    • Validation should support and enhance DevOps workflows by providing fast feedback in pull requests.
    • Allow quality gates to be implemented between environments such development, test, and production.
  3. Cross-platform:
    • A wide range of platforms can be used to author and deploy infrastructure code. PSRule must support rule validation and authoring on Linux, MacOS, and Windows.
    • Runs in a Linux container. For continuous integration (CI) systems that do not support PowerShell, run in a container.
  4. Reusable:
    • Validation should plug and play, reusable across teams and organizations.
    • Any reusable validation will have exceptions. Rules must be able to be disabled where they are not applicable.

Continue reading the PSRule design specification.

Support

This project uses GitHub Issues to track bugs and feature requests. Please search the existing issues before filing new issues to avoid duplicates.

  • For new issues, file your bug or feature request as a new issue.
  • For help, discussion, and support questions about using this project, join or start a discussion.

Support for this project/ product is limited to the resources listed above.

Getting the module

You can download and install the PSRule module from the PowerShell Gallery.

Module Description Downloads / instructions
PSRule Validate infrastructure as code (IaC) and objects using PowerShell rules. latest / instructions

For rule and integration modules see related projects.

Getting extensions

Companion extensions are available for the following platforms.

Platform Description Downloads / instructions
Azure Pipelines Validate infrastructure as code (IaC) and DevOps repositories using Azure Pipelines. latest / instructions
GitHub Actions Validate infrastructure as code (IaC) and DevOps repositories using GitHub Actions. latest / instructions
Visual Studio Code Visual Studio Code extension for PSRule. latest / instructions

Getting started

The following example shows basic PSRule usage for validating PowerShell objects. For specific use cases see scenarios.

For frequently asked questions, see the FAQ.

Define a rule

To define a rule, use a Rule block saved to a file with the .Rule.ps1 extension.

Rule 'NameOfRule' {
    # Rule conditions
}

Within the body of the rule provide one or more conditions. A condition is valid PowerShell that results in $True or $False.

For example:

Rule 'isFruit' {
    # Condition to determine if the object is fruit
    $TargetObject.Name -in 'Apple', 'Orange', 'Pear'
}

An optional result message can be added to by using the Recommend keyword.

Rule 'isFruit' {
    # An recommendation to display in output
    Recommend 'Fruit is only Apple, Orange and Pear'

    # Condition to determine if the object is fruit
    $TargetObject.Name -in 'Apple', 'Orange', 'Pear'
}

The rule is saved to a file named isFruit.Rule.ps1 file. One or more rules can be defined within a single file.

Execute a rule

To execute the rule use Invoke-PSRule.

For example:

# Define objects to validate
$items = @();
$items += [PSCustomObject]@{ Name = 'Fridge' };
$items += [PSCustomObject]@{ Name = 'Apple' };

# Validate each item using rules saved in current working path
$items | Invoke-PSRule;

The output of this example is:

   TargetName: Fridge

RuleName                            Outcome    Recommendation
--------                            -------    --------------
isFruit                             Fail       Fruit is only Apple, Orange and Pear


   TargetName: Apple

RuleName                            Outcome    Recommendation
--------                            -------    --------------
isFruit                             Pass       Fruit is only Apple, Orange and Pear

Additional options

To filter results to only non-fruit results, use Invoke-PSRule -Outcome Fail. Passed, failed and error results are shown by default.

# Only show non-fruit results
$items | Invoke-PSRule -Outcome Fail;

For a summary of results for each rule use Invoke-PSRule -As Summary.

For example:

# Show rule summary
$items | Invoke-PSRule -As Summary;

The output of this example is:

RuleName                            Pass  Fail  Outcome
--------                            ----  ----  -------
isFruit                             1     1     Fail

An optional failure reason can be added to the rule block by using the Reason keyword.

Rule 'isFruit' {
    # An recommendation to display in output
    Recommend 'Fruit is only Apple, Orange and Pear'

    # An failure reason to display for non-fruit
    Reason "$($PSRule.TargetName) is not fruit."

    # Condition to determine if the object is fruit
    $TargetObject.Name -in 'Apple', 'Orange', 'Pear'
}

To include the reason with output use Invoke-PSRule -OutputFormat Wide.

For example:

# Show failure reason for failing results
$items | Invoke-PSRule -OutputFormat Wide;

The output of this example is:

   TargetName: Fridge

RuleName                            Outcome    Reason                              Recommendation
--------                            -------    ------                              --------------
isFruit                             Fail       Fridge is not fruit.                Fruit is only Apple, Orange and Pear


   TargetName: Apple

RuleName                            Outcome    Reason                              Recommendation
--------                            -------    ------                              --------------
isFruit                             Pass                                           Fruit is only Apple, Orange and Pear

The final rule is saved to isFruit.Rule.ps1.

Scenarios

For walk through examples of PSRule usage see:

Language reference

PSRule extends PowerShell with domain specific language (DSL) keywords, cmdlets and automatic variables.

Keywords

The following language keywords are used by the PSRule module:

  • Rule - A rule definition.
  • Exists - Assert that a field or property must exist.
  • Match - Assert that the field must match any of the regular expressions.
  • AnyOf - Assert that any of the child expressions must be true.
  • AllOf - Assert that all of the child expressions must be true.
  • Within - Assert that the field must match any of the values.
  • TypeOf - Assert that the object must be of a specific type.
  • Reason - Return a reason for why the rule failed.
  • Recommend - Return a recommendation to resolve the issue and pass the rule.

Commands

The following commands exist in the PSRule module:

Concepts

The following conceptual topics exist in the PSRule module:

Schemas

PSRule uses the following schemas:

  • Options - Schema for PSRule YAML options file.
  • Resources - Schema for PSRule YAML resources such as baselines.

Related projects

The following projects use or integrate with PSRule.

Name Description
PSRule.Rules.Azure A suite of rules to validate Azure resources and infrastructure as code (IaC) using PSRule.
PSRule.Rules.Kubernetes A suite of rules to validate Kubernetes resources using PSRule.
PSRule.Rules.CAF A suite of rules to validate Azure resources against the Cloud Adoption Framework (CAF) using PSRule.
PSRule.Rules.GitHub A suite of rules to validate GitHub repositories using PSRule.
PSRule.Rules.MSFT.OSS A suite of rules to validate repositories against Microsoft Open Source Software (OSS) requirements.
PSRule.Monitor Send and query PSRule analysis results in Azure Monitor.
PSRule-pipelines Validate infrastructure as code (IaC) and DevOps repositories using Azure Pipelines.
ps-rule Validate infrastructure as code (IaC) and DevOps repositories using GitHub Actions.
PSRule-vscode Visual Studio Code extension for PSRule.

Changes and versioning

Modules in this repository use semantic versioning to declare breaking changes. For a list of module changes please see the change log.

Pre-release module versions are created on major commits and can be installed from the PowerShell Gallery. Pre-release versions should be considered experimental. Modules and change log details for pre-releases will be removed as stable releases are made available.

Contributing

This project welcomes contributions and suggestions. If you are ready to contribute, please visit the contribution guide.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Maintainers

License

This project is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].