From 0fa0ca5e02069c9ef03bdd341e416735626a16e5 Mon Sep 17 00:00:00 2001 From: srushti-patl Date: Tue, 17 Sep 2024 14:57:29 -0700 Subject: [PATCH] fix: Updating schema definition as per comment --- internal/fabric/testing_helpers/env_data.go | 10 +- .../fabric/marketplace/datasources_schema.go | 118 +++++++++--------- .../resources/fabric/marketplace/models.go | 9 +- 3 files changed, 64 insertions(+), 73 deletions(-) diff --git a/internal/fabric/testing_helpers/env_data.go b/internal/fabric/testing_helpers/env_data.go index ab2075c97..7325bdd8a 100644 --- a/internal/fabric/testing_helpers/env_data.go +++ b/internal/fabric/testing_helpers/env_data.go @@ -9,15 +9,9 @@ import ( ) const ( - FabricDedicatedPortEnvVar = "TF_ACC_FABRIC_DEDICATED_PORTS" -) - -const ( + FabricDedicatedPortEnvVar = "TF_ACC_FABRIC_DEDICATED_PORTS" FabricConnectionsTestDataEnvVar = "TF_ACC_FABRIC_CONNECTIONS_TEST_DATA" -) - -const ( - FabricSubscriptionEnvVar = "TF_ACC_FABRIC_MARKET_PLACE_SUBSCRIPTION_ID" + FabricSubscriptionEnvVar = "TF_ACC_FABRIC_MARKET_PLACE_SUBSCRIPTION_ID" ) type EnvPorts map[string]map[string][]fabricv4.PortResponse diff --git a/internal/resources/fabric/marketplace/datasources_schema.go b/internal/resources/fabric/marketplace/datasources_schema.go index 573b275da..ada92a4ce 100644 --- a/internal/resources/fabric/marketplace/datasources_schema.go +++ b/internal/resources/fabric/marketplace/datasources_schema.go @@ -40,87 +40,87 @@ func fabricMarketplaceSubscriptionDataSourceSchema() map[string]*schema.Schema { Type: schema.TypeSet, Computed: true, Description: "Subscription Trial", - Elem: &schema.Resource{ - Schema: marketplaceSubscriptionTrialSch(), - }, + Elem: marketplaceSubscriptionTrialSch(), }, "entitlements": { Type: schema.TypeList, Computed: true, Description: "Subscription entitlements", - Elem: &schema.Resource{ - Schema: marketplaceSubscriptionEntitlementsSch(), - }, + Elem: marketplaceSubscriptionEntitlementsSch(), }, } } -func marketplaceSubscriptionTrialSch() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "enabled": { - Type: schema.TypeBool, - Computed: true, - Description: "Marketplace Subscription Trial Enabled", +func marketplaceSubscriptionTrialSch() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "enabled": { + Type: schema.TypeBool, + Computed: true, + Description: "Marketplace Subscription Trial Enabled", + }, }, } } -func marketplaceSubscriptionEntitlementsSch() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "uuid": { - Type: schema.TypeString, - Computed: true, - Description: "Subscription Entitlement Id", - }, - "quantity_entitled": { - Type: schema.TypeInt, - Computed: true, - Description: "Entitled Quantity", - }, - "quantity_consumed": { - Type: schema.TypeInt, - Computed: true, - Description: "Consumed Quantity", - }, - "quantity_available": { - Type: schema.TypeInt, - Computed: true, - Description: "Available Quantity", - }, - "asset": { - Type: schema.TypeSet, - Computed: true, - Description: "Asset information", - Elem: &schema.Resource{ - Schema: marketplaceSubscriptionAssetSch(), +func marketplaceSubscriptionEntitlementsSch() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "uuid": { + Type: schema.TypeString, + Computed: true, + Description: "Subscription Entitlement Id", + }, + "quantity_entitled": { + Type: schema.TypeInt, + Computed: true, + Description: "Entitled Quantity", + }, + "quantity_consumed": { + Type: schema.TypeInt, + Computed: true, + Description: "Consumed Quantity", + }, + "quantity_available": { + Type: schema.TypeInt, + Computed: true, + Description: "Available Quantity", + }, + "asset": { + Type: schema.TypeSet, + Computed: true, + Description: "Asset information", + Elem: marketplaceSubscriptionAssetSch(), }, }, } } -func marketplaceSubscriptionAssetSch() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "type": { - Type: schema.TypeString, - Computed: true, - Description: "Defines the FCR type like; XF_ROUTER", - }, - "package": { - Type: schema.TypeSet, - Computed: true, - Description: "Fabric Cloud Router Package Type", - Elem: &schema.Resource{ - Schema: marketplaceSubscriptionPackageSch(), +func marketplaceSubscriptionAssetSch() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": { + Type: schema.TypeString, + Computed: true, + Description: "Defines the FCR type like; XF_ROUTER", + }, + "package": { + Type: schema.TypeSet, + Computed: true, + Description: "Fabric Cloud Router Package Type", + Elem: marketplaceSubscriptionPackageSch(), }, }, } } -func marketplaceSubscriptionPackageSch() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "code": { - Type: schema.TypeString, - Computed: true, - Description: "Cloud Router package code", +func marketplaceSubscriptionPackageSch() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "code": { + Type: schema.TypeString, + Computed: true, + Description: "Cloud Router package code", + }, }, } } diff --git a/internal/resources/fabric/marketplace/models.go b/internal/resources/fabric/marketplace/models.go index d3de60133..5e8c328d9 100644 --- a/internal/resources/fabric/marketplace/models.go +++ b/internal/resources/fabric/marketplace/models.go @@ -43,8 +43,7 @@ func subscriptionTrialGoToTerraform(trial *fabricv4.SubscriptionTrial) *schema.S mappedTrial := make(map[string]interface{}) mappedTrial["enabled"] = trial.GetEnabled() trialSet := schema.NewSet( - schema.HashResource(&schema.Resource{ - Schema: marketplaceSubscriptionTrialSch()}), + schema.HashResource(marketplaceSubscriptionTrialSch()), []interface{}{mappedTrial}, ) return trialSet @@ -76,8 +75,7 @@ func subscriptionAssetGoToTerraform(asset *fabricv4.SubscriptionAsset) *schema.S package_ := asset.GetPackage() mappedAsset["package"] = subscriptionPackageGoToTerraform(&package_) assetSet := schema.NewSet( - schema.HashResource(&schema.Resource{ - Schema: marketplaceSubscriptionAssetSch()}), + schema.HashResource(marketplaceSubscriptionAssetSch()), []interface{}{mappedAsset}, ) return assetSet @@ -90,8 +88,7 @@ func subscriptionPackageGoToTerraform(package_ *fabricv4.SubscriptionRouterPacka mappedPackage := make(map[string]interface{}) mappedPackage["code"] = string(package_.GetCode()) packageSet := schema.NewSet( - schema.HashResource(&schema.Resource{ - Schema: marketplaceSubscriptionPackageSch()}), + schema.HashResource(marketplaceSubscriptionPackageSch()), []interface{}{mappedPackage}, ) return packageSet