Skip to content

Commit

Permalink
feat: adding fabric market place subscription data source (#765)
Browse files Browse the repository at this point in the history
- Added fabric_market_place_subscription_data_source
- Added Acceptance Test for abric_market_place_subscription_data_source
  • Loading branch information
srushti-patl authored Sep 18, 2024
2 parents f303197 + a82d060 commit 16ba618
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 36 deletions.
1 change: 1 addition & 0 deletions .github/workflows/fabric_acctest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ jobs:
TF_ACC: "1"
TF_ACC_FABRIC_CONNECTIONS_TEST_DATA: ${{ secrets.TF_ACC_FABRIC_CONNECTIONS_TEST_DATA }}
TF_ACC_FABRIC_DEDICATED_PORTS: ${{ secrets.TF_ACC_FABRIC_DEDICATED_PORTS }}
TF_ACC_FABRIC_MARKET_PLACE_SUBSCRIPTION_ID: ${{ secrets.TF_ACC_FABRIC_MARKET_PLACE_SUBSCRIPTION_ID }}
EQUINIX_API_CLIENTID: ${{ secrets.EQUINIX_API_CLIENTID_PFCR }}
EQUINIX_API_CLIENTSECRET: ${{ secrets.EQUINIX_API_CLIENTSECRET_PFCR }}
METAL_AUTH_TOKEN: ${{ secrets.METAL_AUTH_TOKEN }}
Expand Down
84 changes: 84 additions & 0 deletions docs/data-sources/fabric_market_place_subscription.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
subcategory: "Fabric"
---

# equinix_fabric_market_place_subscription (Data Source)

Fabric V4 API compatible data resource that allow user to fetch Marketplace Subscription detail for a given UUID

## Example Usage

```terraform
data "equinix_fabric_market_place_subscription" "subscription-test" {
uuid = "<uuid_of_marketplace_subscription>"
}
output "id" {
value = data.equinix_fabric_market_place_subscription.subscription-test.id
}
output "status" {
value = data.equinix_fabric_market_place_subscription.subscription-test.status
}
output "marketplace" {
value = data.equinix_fabric_market_place_subscription.subscription-test.marketplace
}
output "offer_type" {
value = data.equinix_fabric_market_place_subscription.subscription-test.offer_type
}
output "is_auto_renew" {
value = data.equinix_fabric_market_place_subscription.subscription-test.is_auto_renew
}
```

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

### Required

- `uuid` (String) Equinix-assigned marketplace identifier

### Read-Only

- `entitlements` (List of Object) Subscription entitlements (see [below for nested schema](#nestedatt--entitlements))
- `href` (String) Subscription URI information
- `id` (String) The ID of this resource.
- `is_auto_renew` (Boolean) Information about subscription auto renewal
- `marketplace` (String) Marketplace like; AWS, GCP, AZURE, REDHAT
- `offer_type` (String) Marketplace Offer Type like; PUBLIC, PRIVATE_OFFER
- `status` (String) Subscription Status like; ACTIVE, EXPIRED, CANCELLED, GRACE_PERIOD
- `trial` (Set of Object) Subscription Trial (see [below for nested schema](#nestedatt--trial))

<a id="nestedatt--entitlements"></a>
### Nested Schema for `entitlements`

Read-Only:

- `asset` (Set of Object) (see [below for nested schema](#nestedobjatt--entitlements--asset))
- `quantity_available` (Number)
- `quantity_consumed` (Number)
- `quantity_entitled` (Number)
- `uuid` (String)

<a id="nestedobjatt--entitlements--asset"></a>
### Nested Schema for `entitlements.asset`

Read-Only:

- `package` (Set of Object) (see [below for nested schema](#nestedobjatt--entitlements--asset--package))
- `type` (String)

<a id="nestedobjatt--entitlements--asset--package"></a>
### Nested Schema for `entitlements.asset.package`

Read-Only:

- `code` (String)




<a id="nestedatt--trial"></a>
### Nested Schema for `trial`

Read-Only:

- `enabled` (Boolean)
66 changes: 34 additions & 32 deletions equinix/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/equinix/terraform-provider-equinix/internal/config"
fabric_connection "github.com/equinix/terraform-provider-equinix/internal/resources/fabric/connection"
fabric_market_place_subscription "github.com/equinix/terraform-provider-equinix/internal/resources/fabric/marketplace"
fabric_network "github.com/equinix/terraform-provider-equinix/internal/resources/fabric/network"
metal_port "github.com/equinix/terraform-provider-equinix/internal/resources/metal/port"
"github.com/equinix/terraform-provider-equinix/internal/resources/metal/virtual_circuit"
Expand Down Expand Up @@ -79,38 +80,39 @@ func Provider() *schema.Provider {
},
},
DataSourcesMap: map[string]*schema.Resource{
"equinix_fabric_routing_protocol": dataSourceRoutingProtocol(),
"equinix_fabric_connection": fabric_connection.DataSource(),
"equinix_fabric_connections": fabric_connection.DataSourceSearch(),
"equinix_fabric_cloud_router": dataSourceFabricCloudRouter(),
"equinix_fabric_cloud_routers": dataSourceFabricGetCloudRouters(),
"equinix_fabric_network": fabric_network.DataSource(),
"equinix_fabric_networks": fabric_network.DataSourceSearch(),
"equinix_fabric_port": dataSourceFabricPort(),
"equinix_fabric_ports": dataSourceFabricGetPortsByName(),
"equinix_fabric_service_profile": dataSourceFabricServiceProfileReadByUuid(),
"equinix_fabric_service_profiles": dataSourceFabricSearchServiceProfilesByName(),
"equinix_network_account": dataSourceNetworkAccount(),
"equinix_network_device": dataSourceNetworkDevice(),
"equinix_network_device_type": dataSourceNetworkDeviceType(),
"equinix_network_device_software": dataSourceNetworkDeviceSoftware(),
"equinix_network_device_platform": dataSourceNetworkDevicePlatform(),
"equinix_metal_hardware_reservation": dataSourceMetalHardwareReservation(),
"equinix_metal_metro": dataSourceMetalMetro(),
"equinix_metal_facility": dataSourceMetalFacility(),
"equinix_metal_ip_block_ranges": dataSourceMetalIPBlockRanges(),
"equinix_metal_precreated_ip_block": dataSourceMetalPreCreatedIPBlock(),
"equinix_metal_operating_system": dataSourceOperatingSystem(),
"equinix_metal_spot_market_price": dataSourceSpotMarketPrice(),
"equinix_metal_device": dataSourceMetalDevice(),
"equinix_metal_devices": dataSourceMetalDevices(),
"equinix_metal_device_bgp_neighbors": dataSourceMetalDeviceBGPNeighbors(),
"equinix_metal_plans": dataSourceMetalPlans(),
"equinix_metal_port": metal_port.DataSource(),
"equinix_metal_reserved_ip_block": dataSourceMetalReservedIPBlock(),
"equinix_metal_spot_market_request": dataSourceMetalSpotMarketRequest(),
"equinix_metal_virtual_circuit": virtual_circuit.DataSource(),
"equinix_metal_vrf": vrf.DataSource(),
"equinix_fabric_routing_protocol": dataSourceRoutingProtocol(),
"equinix_fabric_connection": fabric_connection.DataSource(),
"equinix_fabric_connections": fabric_connection.DataSourceSearch(),
"equinix_fabric_cloud_router": dataSourceFabricCloudRouter(),
"equinix_fabric_cloud_routers": dataSourceFabricGetCloudRouters(),
"equinix_fabric_market_place_subscription": fabric_market_place_subscription.DataSourceFabricMarketplaceSubscription(),
"equinix_fabric_network": fabric_network.DataSource(),
"equinix_fabric_networks": fabric_network.DataSourceSearch(),
"equinix_fabric_port": dataSourceFabricPort(),
"equinix_fabric_ports": dataSourceFabricGetPortsByName(),
"equinix_fabric_service_profile": dataSourceFabricServiceProfileReadByUuid(),
"equinix_fabric_service_profiles": dataSourceFabricSearchServiceProfilesByName(),
"equinix_network_account": dataSourceNetworkAccount(),
"equinix_network_device": dataSourceNetworkDevice(),
"equinix_network_device_type": dataSourceNetworkDeviceType(),
"equinix_network_device_software": dataSourceNetworkDeviceSoftware(),
"equinix_network_device_platform": dataSourceNetworkDevicePlatform(),
"equinix_metal_hardware_reservation": dataSourceMetalHardwareReservation(),
"equinix_metal_metro": dataSourceMetalMetro(),
"equinix_metal_facility": dataSourceMetalFacility(),
"equinix_metal_ip_block_ranges": dataSourceMetalIPBlockRanges(),
"equinix_metal_precreated_ip_block": dataSourceMetalPreCreatedIPBlock(),
"equinix_metal_operating_system": dataSourceOperatingSystem(),
"equinix_metal_spot_market_price": dataSourceSpotMarketPrice(),
"equinix_metal_device": dataSourceMetalDevice(),
"equinix_metal_devices": dataSourceMetalDevices(),
"equinix_metal_device_bgp_neighbors": dataSourceMetalDeviceBGPNeighbors(),
"equinix_metal_plans": dataSourceMetalPlans(),
"equinix_metal_port": metal_port.DataSource(),
"equinix_metal_reserved_ip_block": dataSourceMetalReservedIPBlock(),
"equinix_metal_spot_market_request": dataSourceMetalSpotMarketRequest(),
"equinix_metal_virtual_circuit": virtual_circuit.DataSource(),
"equinix_metal_vrf": vrf.DataSource(),
},
ResourcesMap: map[string]*schema.Resource{
"equinix_fabric_network": fabric_network.Resource(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
data "equinix_fabric_market_place_subscription" "subscription-test" {
uuid = "<uuid_of_marketplace_subscription>"
}
output "id" {
value = data.equinix_fabric_market_place_subscription.subscription-test.id
}
output "status" {
value = data.equinix_fabric_market_place_subscription.subscription-test.status
}
output "marketplace" {
value = data.equinix_fabric_market_place_subscription.subscription-test.marketplace
}
output "offer_type" {
value = data.equinix_fabric_market_place_subscription.subscription-test.offer_type
}
output "is_auto_renew" {
value = data.equinix_fabric_market_place_subscription.subscription-test.is_auto_renew
}
12 changes: 8 additions & 4 deletions internal/fabric/testing_helpers/env_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package testing_helpers

import (
"encoding/json"
"github.com/equinix/equinix-sdk-go/services/fabricv4"
"os"
"testing"
)

const (
FabricDedicatedPortEnvVar = "TF_ACC_FABRIC_DEDICATED_PORTS"
"github.com/equinix/equinix-sdk-go/services/fabricv4"
)

const (
FabricDedicatedPortEnvVar = "TF_ACC_FABRIC_DEDICATED_PORTS"
FabricConnectionsTestDataEnvVar = "TF_ACC_FABRIC_CONNECTIONS_TEST_DATA"
FabricSubscriptionEnvVar = "TF_ACC_FABRIC_MARKET_PLACE_SUBSCRIPTION_ID"
)

type EnvPorts map[string]map[string][]fabricv4.PortResponse
Expand All @@ -34,3 +33,8 @@ func GetFabricEnvConnectionTestData(t *testing.T) map[string]map[string]string {
}
return connectionTestData
}

func GetFabricMarketPlaceSubscriptionId(t *testing.T) string {
subscriptionId := os.Getenv(FabricSubscriptionEnvVar)
return subscriptionId
}
40 changes: 40 additions & 0 deletions internal/resources/fabric/marketplace/datasources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package marketplace

import (
"context"
"log"
"strings"

"github.com/equinix/terraform-provider-equinix/internal/config"
equinix_errors "github.com/equinix/terraform-provider-equinix/internal/errors"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceFabricMarketplaceSubscription() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceFabricMarketplaceSubscriptionRead,
Schema: fabricMarketplaceSubscriptionDataSourceSchema(),
Description: "Fabric V4 API compatible data resource that allow user to fetch Marketplace Subscription detail for a given UUID",
}
}

func dataSourceFabricMarketplaceSubscriptionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
uuid, _ := d.Get("uuid").(string)
d.SetId(uuid)
return fabricMarketplaceSubscriptionRead(ctx, d, meta)
}

func fabricMarketplaceSubscriptionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*config.Config).NewFabricClientForSDK(d)
subscription, _, err := client.MarketplaceSubscriptionsApi.GetSubscriptionById(ctx, d.Id()).Execute()
if err != nil {
log.Printf("[WARN] Subscription %s not found , error %s", d.Id(), err)
if !strings.Contains(err.Error(), "500") {
d.SetId("")
}
return diag.FromErr(equinix_errors.FormatFabricError(err))
}
d.SetId(subscription.GetUuid())
return setFabricMap(d, subscription)
}
126 changes: 126 additions & 0 deletions internal/resources/fabric/marketplace/datasources_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package marketplace

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func fabricMarketplaceSubscriptionDataSourceSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"href": {
Type: schema.TypeString,
Computed: true,
Description: "Subscription URI information",
},
"uuid": {
Type: schema.TypeString,
Required: true,
Description: "Equinix-assigned marketplace identifier",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Subscription Status like; ACTIVE, EXPIRED, CANCELLED, GRACE_PERIOD",
},
"marketplace": {
Type: schema.TypeString,
Computed: true,
Description: "Marketplace like; AWS, GCP, AZURE, REDHAT",
},
"offer_type": {
Type: schema.TypeString,
Computed: true,
Description: "Marketplace Offer Type like; PUBLIC, PRIVATE_OFFER",
},
"is_auto_renew": {
Type: schema.TypeBool,
Computed: true,
Description: "Information about subscription auto renewal",
},
"trial": {
Type: schema.TypeSet,
Computed: true,
Description: "Subscription Trial",
Elem: marketplaceSubscriptionTrialSch(),
},
"entitlements": {
Type: schema.TypeList,
Computed: true,
Description: "Subscription entitlements",
Elem: marketplaceSubscriptionEntitlementsSch(),
},
}
}

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() *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() *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() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"code": {
Type: schema.TypeString,
Computed: true,
Description: "Cloud Router package code",
},
},
}
}
Loading

0 comments on commit 16ba618

Please sign in to comment.