Skip to content

Commit

Permalink
dev (#147)
Browse files Browse the repository at this point in the history
* Chores

- updated to latest dependencies
- require go 1.22 as the minimum
- added the public key that is used to sign the provider

* January 2025 update

- keep dependencies up-to-date
- check for proper CML address (protocol must be https and hostname not
  empty, also URL must parse) and associated test
- small documentation update

* disable doc generation for the time being
* provide specific terraform versions
* renamed package
  • Loading branch information
rschmied authored Jan 18, 2025
1 parent 45ab482 commit 7e9f3fb
Show file tree
Hide file tree
Showing 79 changed files with 417 additions and 379 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ permissions:
env:
# Go language version to use for building. This value should also be updated
# in the release workflow if changed.
GO_VERSION: "1.21"
GO_VERSION: "1.22"

jobs:
# Ensure project builds before running testing matrix
Expand All @@ -37,8 +37,17 @@ jobs:
- run: go mod download
- run: go build -v .

- name: Install Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ matrix.terraform }}
terraform_wrapper: false

generate:
# this seems to cause an error as the generation now wants to exec
# terraform and it's not available here. need to consider what to do.
runs-on: ubuntu-latest
if: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand All @@ -65,13 +74,13 @@ jobs:
# specific IDs which must be unique... some test resource randomization
# is needed but doesn't exist... Currently only testing w/ 1.6
# max-parallel: 1 should fix this!
# Specific versions needed!
# NOTE: required tests are configured in branch protection!
terraform:
# - "1.0.*"
# - "1.1.*"
# - "1.3.*"
- "1.7.*"
- "1.8.*"
- "1.8.5"
- "1.9.8"
- "1.10.4"

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand Down Expand Up @@ -100,6 +109,7 @@ jobs:
TF_VAR_username: ${{ secrets.USERNAME }}
TF_VAR_password: ${{ secrets.PASSWORD }}
TF_VAR_token: ${{ secrets.TOKEN }}
TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }}
run: go test -timeout 1h -race -v -covermode atomic -coverprofile=covprofile ./internal/...
timeout-minutes: 60

Expand Down
29 changes: 29 additions & 0 deletions A97E6292972408AB.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQINBGNZjN0BEADAbapQMl5+2i/nzhfV0Qa9QOs8CQxVYepZIMnzO0VUyYX2aeuZ
ceSttm9tU7tMfHoibwxgCQsYBA8eemQYX+HAvR8mhFrA/nG0t2wsdzMyYOUySaUw
pgft2TuTPeZI0BMK8JKAHG3HCUdgjUc4ScJGTMXO7kiPR5q86RN+IaVyEs38F0zZ
nfvSKY8MqGUjD5cwEa1OuHDzG2K2iw7eugEgyfPxaHQOjFkeyN/NKtP6Fdy7Xqpz
guboSgH2P/t3ml7lkqzLXgtSlHCZjoXdAQIb6c4FRIepEYioaAWN8X69EwuMrK2b
tiqKMQyj5l/B/1i+zpaYEJpnl3pHWao5xxgE/OeraEFkE7kuKRS055oc2Q1lNaQf
eUtM8lA3XsNNlfwo7jKk799iBDb84AObFW42ujLMo2EuK79bc2UWzGAJze9VLgiR
VCQ6qNX3mDfyJfync3revGAijNuM+ebpmUtjYv0CfR3tjyrDG5YsUzVVp25950D2
QNCO0UTbBHVmWsdJIVmBd9yqILvgFfThmmtnClq2NctfP/MAWSjEwo2k53F9i79L
jyTayPHVohxrt9BEo5XvdoHEvrrau+uTW+fe1uCfmu6QKa/H6VPPqn+/+BaNVCHP
Ltama+1a0I3fqhRIZwaoAS0gdXERg2jMOoOYHJq2M1BuIJ1P/5KeZqMblQARAQAB
tCRSYWxwaCBTY2htaWVkZXIgPHJzY2htaWVkQGNpc2NvLmNvbT6JAlQEEwEKAD4C
GwMFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AWIQR6BE7VxsdbFSLEb5ypfmKSlyQI
qwUCZw0itAUJBZTJVwAKCRCpfmKSlyQIq5XMD/0bxlctuLifQTq6o+Wx5YXqWQOP
8AzdELvHbovsI2tvn1yrxjIkJZt8xBmzoQ87gnZdSQqldFCiMgI8SwllYkfTw/Os
IhSXLOFsxIXxl2Zpo40MRwcR2qynQipp1qPqB6dmYWaauoJ5zLNHIRydbmENYuIZ
vzD/ebg7kQ7RuZvYL/1M0/pBSCy4ZsEuCg2E+tAANo3YDZ9EkvHk4kAsy7c/N1aZ
cwYKxFtkMupc3R4EAc2q7c3yXlv6vc1vqF4QcVUzvgGpYCOZRjSEgHIwhGCJi/nB
Mqgw1vlsTf7Mj/qCA50WzRjkMxHOwGhsYX0vp3lVm5CKnHsM4fJLwVgV/oxmbjhw
ZENtc5L67FvPWExNXoHghq5PH1eLFxbQzZumH/GBhfv7YwVRzy/pN2JUih/kRUnr
P4OSqW7N9fA2EvtW/XebsgYhcQVCJZSbXnf3KV42oPY6QcQ8PQyKN8TPmK69rbct
lwJz0U2A9s9IZQfNnIswDrBnNRXtCNvdjdJCB++VBQT7LoesPIJLlr/UXnq7z9jX
V/a1GILwbleCxGQxI+QO5cTlhZdtmpksFTfAGS0fsFYSznIuz+tWepfY7pgFo7gu
iGwUP0mp0GiX2las1sYA7o61umV8R/8pYvr78g8Ub472CUj1MS04NnKviWpwf8xq
S7lGuBQRzXig7GYYLA==
=C3qi
-----END PGP PUBLIC KEY BLOCK-----
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

Lists the changes in the provider.

## Version 0.8.2

- go version 1.22 used
- updated dependencies (plugin-framework 1.13.0, plugin-go 0.25.0, plugin-testing 1.10.0)
- use newer gocmlclient which supports CML 2.8.0
- added signing public key to repo
- provider configuration check: Ensure valid CML host address (HTTPS)
- moved package name from rschmied to ciscodevnet (cosmetic)
- updated documentation

## Version 0.8.1

- updated documentation, examples and tests to match code changes.
Expand Down
43 changes: 32 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,45 @@

# Terraform Provider for Cisco CML2

This repository implements a [Terraform](https://www.terraform.io) provider for Cisco Modeling Labs version 2.4 and later. It's current state is "beta". Changes can be expected, for example:
This repository implements a [Terraform](https://www.terraform.io) provider for
Cisco Modeling Labs version 2.6 and later. It's current state is "beta". Changes
can be expected, for example:

- configuration (provider, resources, data-sources)
- provider behavior
- features (additional resources, ...)

> **Note:** The provider needs CML 2.4 or newer. This is due to some additional API capabilities which were introduced with 2.4.0. Older versions are blocked within by the `gocmlclient`.
> [!NOTE]
> The provider needs CML 2.4 or newer. This is due to some additional API
> capabilities which were introduced with 2.4.0. Older versions are blocked
> within by the `gocmlclient`.
The current implementation provides:

- Resources and a data sources (`internal/provider/`),
- resource `cml2_lab` to create, update and destroy labs
- resource `cml2_node` to create, update and destroy nodes in a lab
- resource `cml2_link` to create, update and destroy links between nodes in a lab
- resource `cml2_lifecycle` to control the state of a lab (like `STARTED`, `STOPPED`), including staged starting and configuration injection
- resource `cml2_lifecycle` to control the state of a lab (like `STARTED`,
`STOPPED`), including staged starting and configuration injection
- resource `cml2_group` to create, update and destroy groups
- resource `cml2_user` to create, update and destroy users
- data source `cml2_lab` to retrieve state of an existing lab
- data source `cml2_node` to retrieve state of an existing node in a lab
- data source `cml2_images` to retrieve the available node images from the controller
- data source `cml2_groups` to retrieve user groups from the controller
- data source `cml2_extconn` to retrieve external connector information from the controller
- data source `cml2_system` to retrieve system state (ready state, version, ...) from the controller
- data source `cml2_extconn` to retrieve external connector information from
the controller
- data source `cml2_system` to retrieve system state (ready state, version,
...) from the controller
- data source `cml2_users` to retrieve users from the controller
- Examples (`examples/`) and generated documentation (`docs/`),
- Miscellaneous meta files.

## Requirements

- [Terraform](https://www.terraform.io/downloads.html) >= 1.0
- [Go](https://golang.org/doc/install) >= 1.21
- [Go](https://golang.org/doc/install) >= 1.22
- [CML2](https://cisco.com/go/cml) >= 2.6.0

## Building The Provider
Expand All @@ -50,6 +58,13 @@ go install
Please refer to the `examples` directory and look at the built-in documentation
provided via the registry.

> [!NOTE]
>
> It's recommended to use the UI token (from the User menu, top right "Copy
> JWT") instead of the user-name and password as that will provide better
> performance. Using the token avoids repeated client authentication via the
> API which takes quite a bit of time.
### HCL

For some basic examples look in the `examples` directory
Expand All @@ -65,7 +80,7 @@ the provider binary in the `$GOPATH/bin` directory.

To generate or update documentation, run `go generate`.

In order to run the full suite of Acceptance tests, run `make testacc`. For this
In order to run the full suite of acceptance tests, run `make testacc`. For this
to work, the provider needs to be configured via environment variables. Here's
an example:

Expand All @@ -75,6 +90,8 @@ an example:
TF_VAR_username="admin"
TF_VAR_password="secret"
TF_VAR_address="https://cml-controller.cml.lab"
# alternatively, this is faster:
# TF_VAR_token="your-token-here"

export TF_VAR_username TF_VAR_password TF_VAR_address
```
Expand All @@ -85,7 +102,11 @@ Those variables are referenced for acceptance testing in `internal/provider/test
make testacc
```

Acceptance testing with Github actions can be achieved using the provided
`tunnel.sh` script which uses tools like `gh` CLI and `ngrok` to forward the API
calls to a locally installed CML instance. See `tunnel.sh` and the `ghsecret`
[CLI tool](https://github.com/rschmied/ghsecret) for additional details.
Acceptance testing with GitHub actions must properly set secrets which are used
in the test workflow:

- the NGROK_URL where where the CML API is reachable
- the USERNAME and PASSWORD or alternatively, the CML API TOKEN

This can use Ngrok or other tunneling tools if the CML API isn't directly
reachable from the internet.
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ provider "cml2" {
# credentials, either a JWT or username/password are required
# an error is raised if neither token or username / password are set
# Note: Using a token is a lot faster than using username and password
# token = var.token
username = var.username
password = var.password
Expand Down
2 changes: 2 additions & 0 deletions examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ provider "cml2" {

# credentials, either a JWT or username/password are required
# an error is raised if neither token or username / password are set
# Note: Using a token is a lot faster than using username and password

# token = var.token
username = var.username
password = var.password
Expand Down
63 changes: 33 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
module github.com/rschmied/terraform-provider-cml2
module github.com/ciscodevnet/terraform-provider-cml2

go 1.21
go 1.22.7

toolchain go1.22.10

require (
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/hashicorp/terraform-plugin-docs v0.19.4
github.com/hashicorp/terraform-plugin-framework v1.10.0
github.com/hashicorp/terraform-plugin-go v0.23.0
github.com/hashicorp/terraform-plugin-docs v0.20.1
github.com/hashicorp/terraform-plugin-framework v1.13.0
github.com/hashicorp/terraform-plugin-go v0.25.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-testing v1.9.0
github.com/hashicorp/terraform-plugin-testing v1.11.0
github.com/rschmied/gocmlclient v0.1.0
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
)

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/Kunde21/markdownfmt/v3 v3.1.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
github.com/bmatcuk/doublestar/v4 v4.7.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/hashicorp/cli v1.1.6 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand All @@ -37,21 +39,22 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.1 // indirect
github.com/hashicorp/go-plugin v1.6.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hc-install v0.7.0 // indirect
github.com/hashicorp/hcl/v2 v2.21.0 // indirect
github.com/hashicorp/hc-install v0.9.0 // indirect
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.21.0 // indirect
github.com/hashicorp/terraform-json v0.22.1 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-json v0.23.0 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.4 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand All @@ -67,22 +70,22 @@ require (
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yuin/goldmark v1.7.1 // indirect
github.com/yuin/goldmark v1.7.7 // indirect
github.com/yuin/goldmark-meta v1.1.0 // indirect
github.com/zclconf/go-cty v1.14.4 // indirect
github.com/zclconf/go-cty v1.15.0 // indirect
go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240725223205-93522f1f2a9f // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
google.golang.org/grpc v1.69.4 // indirect
google.golang.org/protobuf v1.36.3 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
Loading

0 comments on commit 7e9f3fb

Please sign in to comment.