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: Commitments and commitment assignments support #300

Merged
merged 81 commits into from
May 8, 2024

Conversation

maxtwardowski
Copy link
Member

@maxtwardowski maxtwardowski commented Apr 23, 2024

The purpose of this PR is to ship a new resource type responsible for CAST AI's commitments and commitment assignments provisioning.

@mindaugasCast
Copy link
Contributor

LGTM

Copy link
Contributor

@furkhat furkhat left a comment

Choose a reason for hiding this comment

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

I see that the api responses converted to tf resources in an unconventional way. Other resources follow a flow of api call -> flattenXYZ/expandXYZ -> set to state. Though that mapping logic is well polished and not bad I think it would make sense to follow common convention with flatten/expand functions.
What do you think?

castai/resource_commitments_test.go Outdated Show resolved Hide resolved
@maxtwardowski
Copy link
Member Author

maxtwardowski commented May 7, 2024

As discussed during the meeting - I don't follow the flatten/expand convention as I figured out that Terraform SDK uses https://github.com/mitchellh/mapstructure under the hood. So instead of mapping API types to map[string]any where keys are defined by constant strings, we can just define resources using structs with mapstructure tags. In this way the decoding part is automatically done by the library and there's no need to do the mapping manually.

Also, as agreed, I did the following changes (in #302 and #304 as well):

  • flatten the structure by getting rid of the separate commitments package, now I just keep the other stuff in resource_commitments_xyz.go files
  • don't export helpers

@maxtwardowski maxtwardowski requested a review from furkhat May 7, 2024 08:48
Copy link
Contributor

@furkhat furkhat left a comment

Choose a reason for hiding this comment

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

Thank you for adding extensive tests. Feel free to merge after you address comments however way you think best.

castai/resource_commitments_mapping.go Outdated Show resolved Hide resolved
castai/resource_commitments.go Show resolved Hide resolved
* types preparation

* more mapping impls for azure

* working import + update

* fix getReservationResources

* add term mapping to MapReservationImportToResource to mimic API's behavior

* fix tests

* TestMapCommitmentToReservationResource

* rename

* mapping functions tests

* working first step of acc test

* CheckDestroy

* working state import step

* working azure acceptance tests

* get rid of the dummy test

* add usage examples

* fix populateCommitmentsResourceData

* full acc tests

* get rid of productname from the matcher

* flatten matcher

* regenerate docs

* format tf

* regenerate docs

* add descriptions

* MapConfigsToCommitments impl

* regenerate docs

* newline

* return err from MapReservationImportToResource

* get rid of attr schema config

* use common fields for cast ai commitment fields

* flatten the structure, get rid of the separate commitments package

* regenerate sdk

* renames

* renames

* dont export mapping functions

* dont export field names

* Feature: Commitment assignments support (#304)

* working assignments

* add example

* adjust tests

* more test adjustments

* add config nil check

* priority computed field

* regenerate docs

* fix replacing assignments

* working acceptance tests with assignments for gke

* add assignment checks

* azure assignments acc tests

* rearrange acc tests

* use common fields for cast ai commitment fields

* flatten the structure, get rid of the separate commitments package

* renames

* renames

* imports fix

* renames

* dont export field names

---------

Co-authored-by: Max Twardowski <[email protected]>

---------

Co-authored-by: Max Twardowski <[email protected]>
@maxtwardowski maxtwardowski changed the title Feature: Commitments support for GCP's CUDs Feature: Commitments and commitment assignments support May 7, 2024
@maxtwardowski maxtwardowski changed the title Feature: Commitments and commitment assignments support feat: Commitments and commitment assignments support May 8, 2024
@maxtwardowski maxtwardowski merged commit 5ed41c7 into master May 8, 2024
10 checks passed
@maxtwardowski maxtwardowski deleted the max/PRICE-32/commitments branch May 8, 2024 08:31
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