The tool can simplify the process to test an ARM REST API. It can generate a terraform file containing dependencies and a terraform file containing the testing resource which is based on the azapi provider. It can also generate a markdown report when found API issues.
For ARM review, please refer to guidance for API test.
-
Download the binary from releases.
-
It's recommended to add the directory containing the binary to your
PATH
, so that you can runarmstrong
directly.
-
Install Go.
-
Run
go install github.com/azure/armstrong@latest
to install the latest version. -
It's recommended to add
$GOPATH/bin
to yourPATH
, so that you can runarmstrong
directly.
Usage: armstrong [--version] [--help] <command> [<args>]
Available commands are:
cleanup Clean up dependencies and testing resource
credscan Scan the credential in given Terraform configuration
generate Generate testing files including terraform configuration for dependencies and testing resource.
report Generate test report for a set of test results
test Update dependencies for tests and run tests
validate Generates a speculative execution plan, showing what actions Terraform would take to apply the current configuration
Armstrong supports generate testcases from different kinds of input.
Supported options:
-working-dir
: Specify the working directory which stores the output config, default is current directory.-raw
: Generatebody
with raw json format, default is false.-v
: Enable verbose mode, default is false.
Supported inputs:
- Generate testcase from swagger 'Create' example:
armstrong generate -path {path to a swagger 'Create' example}
In this mode, it supports -overwrite
option to clean up the existing files, default is false, which means append more testcases.
And it supports -type
option to specify the resource type, allowed values: resource
(supports CRUD) and data
(read-only), default is resource
.
- Generate multiple testcases from swagger spec, it supports both path to the swagger file and the directory containing swagger files.
armstrong generate -swagger {path/dir to swagger spec}
- Generate multiple testcases from an autorest configuration file and its tag:
armstrong generate -readme {path to autorest configuration file} -tag {tag name}
This command generates a speculative execution plan, showing what actions Terraform would take to apply the current configuration.
armstrong validate
Supported options:
-working-dir
: Specify the working directory which stores the output config, default is current directory.-v
: Enable verbose mode, default is false.
This command will set up dependencies and test the ARM resource API.
armstrong test
Supported options:
-working-dir
: Specify the working directory which stores the output config, default is current directory.-v
: Enable verbose mode, default is false.-destroy-after-test
: Destroy the testing resource after test, default is false.-swagger
: Specify the swagger file path or directory path.
Armstrong also output different kinds of reports:
Onboard Terraform - all_passed_report.md
: A markdown report which contains all passed testcases. It will be generated when all testcases passed. It also contains thecoverage report
which shows the tested properties and the total properties.Onboard Terraform - partial_passed_report.md
: A markdown report which contains all passed testcases. It will be generated when there are failed testcases. It also contains thecoverage report
which shows the tested properties and the total properties.Error - api error report
: A markdown report which contains one API error when creating the testing resource. It will be generated when there are API issues. It also contains other details like http traces to help debugging.Error - api issue report
: A markdown report which contains one API issue when testing the resource. It will be generated when there are API issues. It also contains other details like http traces to help debugging.API Test - swagger accuracy report
: A html report which contains the swagger accuracy analysis result. It will be generated when-swagger
option is specified andoav
is installed.API Test - CoverageReport
: A markdown report which contains the operation request body coverage report. It will be generated when-swagger
option is specified andoav
is installed.
Notice:
- How to install
oav
, please refer to oav. - The
coverage report
is generated based on the public swagger repo by default, but it can be changed to the local swagger specs by specifying-swagger
option.
armstrong cleanup
Supported options:
-working-dir
: Specify the working directory which stores the output config, default is current directory.-v
: Enable verbose mode, default is false.
Armstrong also output different kinds of reports:
Onboard Terraform - cleanup_all_passed_report
: A markdown report which contains all passed testcases. It will be generated when all testcases passed.Onboard Terraform - cleanup_partial_passed_report
: A markdown report which contains all passed testcases. It will be generated when there are failed testcases.Error - cleanup_api error report
: A markdown report which contains one API error when deleting the testing resource. It will be generated when there are API issues.
Notice: The oav
must be installed, please refer to oav.
After multiple testcases are generated from swagger spec and tested, swagger accuracy report
are generated in each testcase directory.
This command will generate a summary report which contains all swagger accuracy report
from each testcase directory.
armstrong report -swagger {path/dir to swagger spec}
Supported options:
-working-dir
: Specify the working directory which stores the output config, default is current directory.-swagger
: Specify the swagger file path or directory path.
armstrong credscan
Supported options:
-working-dir
: Specify the working directory containing Terraform config files, default is current directory.-swagger-repo
: Specify the swagger repo path used to match credentials, omit this will use the online swagger repo.-swagger-index-file
: Specify the path to the swagger index file, omit this will use the online swagger index file or locally build index. If the specified file is not found, the downloaded or built index will be saved in the provided file.-output-dir
: Specify the working directory to save output files, default is working directory.-v
: Enable verbose mode, default is false.
Armstrong also output different kinds of reports:
errors.json
: A json report which contains scan errors.errors.md
: A markdown report which contains scan errors.
- Install this tool:
go install github.com/azure/armstrong
, or download it from releases. - Generate terraform files and Test
-
Generate testing files by running
armstrong generate -path {path to a swagger 'Create' example}
. Here's an example:armstrong generate -path .\2021-07-01\examples\Compute\createOrUpdate\ComputeInstanceMinimal.json
.Then
dependency.tf
andtesting.tf
will be generated. It also supports generatebody
with raw json format, by adding option-raw
. You can append more test cases by executing this command with different example paths, this feature is enabled by default, to get a clean working directory, use-overwrite
option to clean up the existing files. -
Run API tests by running
armstrong test
. This command will set up dependencies and test the ARM resource API.
-
-
Q: When use
test
commands, server side validation error happens.A: You may need to modify the dependency.tf or testing.tf to meet the server side's requirements. It happens when the testing resource requires running in specific region or some configurations of its dependencies. After modification, run
test
command to continue the test. -
Q: Will dependencies be removed after testing is done?
A: If using
test
command, resources won't be removed after testing, user must usecleanup
command to remove these resources. -
Q: If some properties are on purpose missing from API response, how to skip this in test validation?
A: You can modify the
testing.tf
to addignore_missing_property = true
in targetazapi_resource
, you may also add justification in comment, e.g.:
resource "azapi_resource" "missingPropertyResource" {
...
// reason: xxx is a secret value
ignore_missing_property = true
}
- Support extension scoped resource, ex:
{resourceUri}/providers/Microsoft.Advisor/recommendations/{recommendationId}
- Support the API path whose key segment is a variable, ex:
.../providers/Microsoft.Web/sites/{name}/host/default/{keyType}/{keyName}
- Generate
body
placeholder with all configurable properties when the example is invalid or empty. - Support the API paths that don't follow the ARM guidelines: give warning message or handle them in a special way.