From b10a0a621d00b9337d26da0960eaa272f8ecb452 Mon Sep 17 00:00:00 2001 From: Siddhu Warrier Date: Sat, 21 Oct 2023 23:22:15 +0100 Subject: [PATCH] fix(ftd-onboarding): map more FMC licensing states to CDO licensing states (#85) --- client/model/ftd/license/license.go | 39 ++++++++++++++++------- provider/internal/device/ftd/operation.go | 5 +-- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/client/model/ftd/license/license.go b/client/model/ftd/license/license.go index 5c6eb6f4..da0b2ce2 100644 --- a/client/model/ftd/license/license.go +++ b/client/model/ftd/license/license.go @@ -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)) @@ -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 } diff --git a/provider/internal/device/ftd/operation.go b/provider/internal/device/ftd/operation.go index 3a479749..8ac75e84 100644 --- a/provider/internal/device/ftd/operation.go +++ b/provider/internal/device/ftd/operation.go @@ -2,6 +2,8 @@ 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" @@ -9,7 +11,6 @@ import ( "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 { @@ -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)) }