Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding Marketplace Subscription capability to Fabric Cloud Router Resource #762

Merged
merged 9 commits into from
Sep 10, 2024

Conversation

srushti-patl
Copy link
Contributor

  • Added marketplace_subscription schema to fabric_cloud_router resource
  • Marked 'account' schema as optional and computed because this parameter is optional while creating Fabric Cloud Router using Marketplace Subscription id.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 46.55172% with 31 lines in your changes missing coverage. Please review.

Project coverage is 34.43%. Comparing base (4b6af14) to head (fcaef23).
Report is 3 commits behind head on main.

Files Patch % Lines
equinix/resource_fabric_cloud_router.go 46.55% 31 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #762      +/-   ##
==========================================
+ Coverage   34.38%   34.43%   +0.04%     
==========================================
  Files         154      154              
  Lines       21080    21116      +36     
==========================================
+ Hits         7249     7271      +22     
- Misses      13670    13686      +16     
+ Partials      161      159       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@thogarty thogarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR also needs the document changes to the schema for the cloud router resource. We should also update the Cloud Router data source schemas for the same changes to allow users to grab that data as well.

We should merge Charles' docs PR first

@@ -273,6 +313,10 @@ func resourceFabricCloudRouterCreate(ctx context.Context, d *schema.ResourceData
package_ := packageCloudRouterTerraformToGo(schemaPackage)
createCloudRouterRequest.SetPackage(package_)

schemaMarketplaceSubscription := d.Get("marketplace_subscription").(*schema.Set).List()
marketplaceSubscription := marketplaceSubscriptionCloudRouterTerraformToGo(schemaMarketplaceSubscription)
createCloudRouterRequest.SetMarketplaceSubscription(marketplaceSubscription)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should only set the subscription if the value is provided. Do a reflect deep equal check on empty return struct to avoid empty value in JSON request body.

}
marketplaceSubscription := fabricv4.MarketplaceSubscription{}
marketplaceSubscriptionMap := marketplaceSubscriptionTerraform[0].(map[string]interface{})
subscriptionUUID := marketplaceSubscriptionMap["uuid"].(string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added type as Optional/Computed but you aren't accounting for type as an input here. Additionally, do empty string checks before setting, and use setters instead of direct assignment on attributes.

return map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Computed: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double checking, you can send type and uuid in the request AND they will be returned in the response if not provided, correct? We need to be spot on with attribute behaviors to prepare for terraform-plugin-framework migration when we move to tf-plugin-protocol v6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we can send type and UUID in the request.
UUID is required parameter in marketplacesubscription filed. I have marked it as required in schema definition.
we will get the type in response if it's not provided.

"account": {
Type: schema.TypeSet,
Required: true,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question about account. I believe this is correct but double checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

account number is required in the account filed and I have marked it as required in schema definition.

Copy link
Contributor

@thogarty thogarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last changes requested. Other than that it looks good.

@@ -0,0 +1,29 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Unnecessary change. You can remove lines 2, 3, 5, and 6. They aren't being added by the default implementation and aren't needed.

## Example Usage

Fabric Cloud Router
{{tffile "examples/resources/equinix_fabric_cloud_router/example_1.tf"}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I don't know how the resources/fabric_cloud_router.md got updated correctly based on how you've oriented the examples in this template. The Code shows that example_1.tf is for the marketplace subscription and example_2.tf is for the standard cloud router. Could you run this again and see if it shows a diff? I think there's a disconnect here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will rename example files.

Copy link
Contributor

@thogarty thogarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Ship it

@srushti-patl srushti-patl merged commit 692594c into main Sep 10, 2024
8 of 11 checks passed
@srushti-patl srushti-patl deleted the CXF-100674-Create-FCR-Subscription branch September 10, 2024 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants