Skip to content

Commit

Permalink
fix(ftd-onboarding): map more FMC licensing states to CDO licensing s…
Browse files Browse the repository at this point in the history
…tates (#85)
  • Loading branch information
siddhuwarrier authored Oct 21, 2023
1 parent cc7126c commit b10a0a6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
39 changes: 27 additions & 12 deletions client/model/ftd/license/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,37 @@ package license

import (
"fmt"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/sliceutil"
"strconv"
"strings"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/sliceutil"
)

type Type string

// https://www.cisco.com/c/en/us/td/docs/security/firepower/70/fdm/fptd-fdm-config-guide-700/fptd-fdm-license.html
const (
Base Type = "BASE"
Carrier Type = "CARRIER"
Threat Type = "THREAT"
Malware Type = "MALWARE"
URLFilter Type = "URLFilter"
Essentials Type = "ESSENTIALS"
Base Type = "BASE"
Essentials Type = "ESSENTIALS"
Carrier Type = "CARRIER"
Threat Type = "THREAT"
IPS Type = "IPS"
Malware Type = "MALWARE"
MalwareDefense Type = "MALWARE_DEFENSE"
URLFilter Type = "URLFilter"
URL Type = "URL"
)

var All = []Type{
Base,
Essentials,
Carrier,
Threat,
IPS,
Malware,
MalwareDefense,
URLFilter,
Essentials,
URL,
}

var AllAsString = make([]string, len(All))
Expand Down Expand Up @@ -55,14 +62,22 @@ func (t *Type) UnmarshalJSON(b []byte) error {
return nil
}

// ReplaceEssentialsWithBase is used to tell terraform license of `BASE` is equal to `ESSENTIALS` during read.
// This is because FMC will modify the FTD's license from `BASE` to `ESSENTIALS` outside terraform,
// and they are the same thing, so when reading it back, we need the conversion
func ReplaceEssentialsWithBase(licenses []string) []string {
// ReplaceFmcLicenseTermsWithCdoTerms is used to tell terraform how the licenses returned by FMC map to licenses expected by CDO
// We need to tell Terraform during read that they are the same thing, so when reading it back, we need the conversion
func ReplaceFmcLicenseTermsWithCdoTerms(licenses []string) []string {
for i, l := range licenses {
if l == string(Essentials) {
licenses[i] = string(Base)
}
if l == string(IPS) {
licenses[i] = string(Threat)
}
if l == string(URL) {
licenses[i] = string(URLFilter)
}
if l == string(MalwareDefense) {
licenses[i] = string(Malware)
}
}
return licenses
}
Expand Down
5 changes: 3 additions & 2 deletions provider/internal/device/ftd/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package ftd

import (
"context"
"strings"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudftd"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/ftd/license"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/ftd/tier"
"github.com/CiscoDevnet/terraform-provider-cdo/internal/util"
"github.com/CiscoDevnet/terraform-provider-cdo/internal/util/sliceutil"
"github.com/hashicorp/terraform-plugin-framework/types"
"strings"
)

func ReadDataSource(ctx context.Context, resource *DataSource, stateData *DataSourceModel) error {
Expand Down Expand Up @@ -52,7 +53,7 @@ func Read(ctx context.Context, resource *Resource, stateData *ResourceModel) err
stateData.AccessPolicyName = types.StringValue(res.Metadata.AccessPolicyName)
stateData.AccessPolicyUid = types.StringValue(res.Metadata.AccessPolicyUid)
stateData.Virtual = types.BoolValue(res.Metadata.PerformanceTier != nil)
stateData.Licenses = util.GoStringSliceToTFStringList(license.ReplaceEssentialsWithBase(strings.Split(res.Metadata.LicenseCaps, ",")))
stateData.Licenses = util.GoStringSliceToTFStringList(license.ReplaceFmcLicenseTermsWithCdoTerms(strings.Split(res.Metadata.LicenseCaps, ",")))
if res.Metadata.PerformanceTier != nil { // nil means physical cloudftd
stateData.PerformanceTier = types.StringValue(string(*res.Metadata.PerformanceTier))
}
Expand Down

0 comments on commit b10a0a6

Please sign in to comment.