Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fmc_smart_license #161

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ website/node_modules
./*.tfstate
.terraform/
.vscode/settings.json
.vscode/private.env
*.log
*.bak
*~
Expand Down
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
"mode": "auto",
"program": "gen/generator.go",
"cwd": "./"
},
{
"name": "Debug Terraform Provider",
"type": "go",
"request": "launch",
"mode": "debug",
// this assumes your workspace is the root of the repo
"program": "${workspaceFolder}",
"env": {},
"args": [
"-debug",
],
"envFile": "${workspaceFolder}/.vscode/private.env"
}
]
}
39 changes: 39 additions & 0 deletions docs/resources/smart_license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fmc_smart_license Resource - terraform-provider-fmc"
subcategory: "License"
description: |-
This resource can manage a Smart License.
---

# fmc_smart_license (Resource)

This resource can manage a Smart License.

## Example Usage

```terraform
resource "fmc_smart_license" "example" {
registration_type = "REGISTER"
token = "X2M3YmJlY..."
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `registration_type` (String) Action to be executed on the smart license.
- Choices: `REGISTER`, `EVALUATION`

### Optional

- `domain` (String) The name of the FMC domain
igiai marked this conversation as resolved.
Show resolved Hide resolved
- `force` (Boolean) Set to true to re-register smart license.
- `token` (String) Registration token.

### Read-Only

- `id` (String) The id of the object
- `registration_status` (String) Status of a smart license.
4 changes: 4 additions & 0 deletions examples/resources/fmc_smart_license/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "fmc_smart_license" "example" {
registration_type = "REGISTER"
token = "X2M3YmJlY..."
}
33 changes: 33 additions & 0 deletions gen/definitions/smart_license.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Smart License
rest_endpoint: /api/fmc_platform/v1/license/smartlicenses
doc_category: License
no_update: true
no_delete: true
no_import: true
no_data_source: true
attributes:
- model_name: registrationType
type: String
description: Action to be executed on the smart license.
enum_values: [REGISTER, EVALUATION]
mandatory: true
example: REGISTER
- model_name: token
type: String
description: Registration token.
example: "X2M3YmJlY..."
exclude_test: true
- model_name: regStatus
igiai marked this conversation as resolved.
Show resolved Hide resolved
tf_name: registration_status
type: String
description: Status of a smart license.
example: EVALUATION
exclude_test: true
exclude_example: true
- model_name: force
type: Bool
description: Set to true to re-register smart license.
example: false
exclude_test: true
exclude_example: true
112 changes: 112 additions & 0 deletions internal/provider/model_fmc_smart_license.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// Licensed under the Mozilla Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://mozilla.org/MPL/2.0/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: MPL-2.0

package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"context"

"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)

// End of section. //template:end imports

// Section below is generated&owned by "gen/generator.go". //template:begin types

type SmartLicense struct {
Id types.String `tfsdk:"id"`
Domain types.String `tfsdk:"domain"`
RegistrationType types.String `tfsdk:"registration_type"`
Token types.String `tfsdk:"token"`
RegistrationStatus types.String `tfsdk:"registration_status"`
Force types.Bool `tfsdk:"force"`
}

// End of section. //template:end types

// Section below is generated&owned by "gen/generator.go". //template:begin getPath

func (data SmartLicense) getPath() string {
return "/api/fmc_platform/v1/license/smartlicenses"
}

// End of section. //template:end getPath

func (data SmartLicense) toBody(ctx context.Context, state SmartLicense) string {
body := ""
if data.Id.ValueString() != "" {
body, _ = sjson.Set(body, "id", data.Id.ValueString())
}
if !data.RegistrationType.IsNull() {
body, _ = sjson.Set(body, "registrationType", data.RegistrationType.ValueString())
}
if !data.Token.IsNull() {
body, _ = sjson.Set(body, "token", data.Token.ValueString())
}
return body
}

func (data *SmartLicense) fromBody(ctx context.Context, res gjson.Result) {
if value := res.Get("regStatus"); value.Exists() {
data.RegistrationStatus = types.StringValue(value.String())
} else {
data.RegistrationStatus = types.StringNull()
}
}

// Section below is generated&owned by "gen/generator.go". //template:begin fromBodyPartial

// fromBodyPartial reads values from a gjson.Result into a tfstate model. It ignores null attributes in order to
// uncouple the provider from the exact values that the backend API might summon to replace nulls. (Such behavior might
// easily change across versions of the backend API.) For List/Set/Map attributes, the func only updates the
// "managed" elements, instead of all elements.
func (data *SmartLicense) fromBodyPartial(ctx context.Context, res gjson.Result) {
if value := res.Get("registrationType"); value.Exists() && !data.RegistrationType.IsNull() {
data.RegistrationType = types.StringValue(value.String())
} else {
data.RegistrationType = types.StringNull()
}
if value := res.Get("token"); value.Exists() && !data.Token.IsNull() {
data.Token = types.StringValue(value.String())
} else {
data.Token = types.StringNull()
}
if value := res.Get("regStatus"); value.Exists() && !data.RegistrationStatus.IsNull() {
data.RegistrationStatus = types.StringValue(value.String())
} else {
data.RegistrationStatus = types.StringNull()
}
if value := res.Get("force"); value.Exists() && !data.Force.IsNull() {
data.Force = types.BoolValue(value.Bool())
} else {
data.Force = types.BoolNull()
}
}

// End of section. //template:end fromBodyPartial

// Section below is generated&owned by "gen/generator.go". //template:begin fromBodyUnknowns

// fromBodyUnknowns updates the Unknown Computed tfstate values from a JSON.
// Known values are not changed (usual for Computed attributes with UseStateForUnknown or with Default).
func (data *SmartLicense) fromBodyUnknowns(ctx context.Context, res gjson.Result) {
}

// End of section. //template:end fromBodyUnknowns
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ func (p *FmcProvider) Resources(ctx context.Context) []func() resource.Resource
NewPortGroupResource,
NewRangeResource,
NewSecurityZoneResource,
NewSmartLicenseResource,
NewStandardACLResource,
NewURLResource,
NewURLGroupResource,
Expand Down
Loading
Loading