-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding fabric market place subscription data source (#765)
- Added fabric_market_place_subscription_data_source - Added Acceptance Test for abric_market_place_subscription_data_source
- Loading branch information
Showing
9 changed files
with
447 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
examples/data-sources/equinix_fabric_market_place_subscription/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
126
internal/resources/fabric/marketplace/datasources_schema.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.