-
Notifications
You must be signed in to change notification settings - Fork 190
fix: Fixes network_container
resource update
#2055
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
Conversation
thanks @BrettFolkins for your contribution, this PR is based on yours |
@@ -51,6 +50,7 @@ func Resource() *schema.Resource { | |||
Type: schema.TypeString, | |||
Optional: true, | |||
Default: constant.AWS, | |||
ForceNew: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provider change forces a replace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to understand the why behind this change, the API does not support updating the providerName?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was under that impression but i checked again and it looks like it's allowed (although it's a bit tricky because they need different attributes).
updated
if d.HasChange("region") { | ||
region, _ := conversion.ValRegion(d.Get("region")) | ||
container.Region = ®ion | ||
if regionList, ok := d.GetOk("regions"); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regions was not updated before
@@ -24,7 +24,7 @@ func TestAccNetworkContainer_basicAWS(t *testing.T) { | |||
projectID = acc.ProjectIDExecution(t) | |||
randInt = acctest.RandIntRange(0, 255) | |||
cidrBlock = fmt.Sprintf("10.8.%d.0/24", randInt) | |||
randIntUpdated = acctest.RandIntRange(0, 255) | |||
randIntUpdated = (randInt + 1) % 256 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make sure cidr and updated cidr are always different
@@ -211,40 +211,33 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di | |||
} | |||
|
|||
func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { | |||
if !d.HasChange("atlas_cidr_block") && !d.HasChange("region_name") && !d.HasChange("region") && !d.HasChange("regions") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing provider_name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no because I've set it to ForceNew, so if it changes it'll delete and create instead of update
regionName, _ := conversion.ValRegion(d.Get("region_name")) | ||
region, _ := conversion.ValRegion(d.Get("region")) | ||
|
||
params := &admin.CloudProviderContainer{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One behaviour change compared to before is that we're going to pass all the values no matter if they have changed or not (As long as at least one has changed) - why are we changing this behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's same behavior, we're not really passing all values, only the ones that are set, it will pass nil if the string is empty so it won't go as now (because StringPtr).
and for the values that are set, the change is precisely to pass all of them because the API will fail if we don't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From #2031 it would seem that regionName is the only property that must be included in the update. For the rest we can include them only if they have mainly for consistency with how we handle other attributes in this same function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you change the provider name you might want to change other attributes as different providers require different attributes. i've change it to send the require argument depending on the provider. It's the same idea as we're doing in Create
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looping in @BrettFolkins for this just for awareness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar enough with best practices in terraform providers to have an opinion about sending the request with only the necessary changes or the full target state, but this version lgtm. Thanks!
if err != nil { | ||
return diag.FromErr(fmt.Errorf(errorContainerUpdate, containerID, err)) | ||
} | ||
params.SetRegionName(regionName) | ||
case constant.AZURE: | ||
region, err := conversion.ValRegion(d.Get("region")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checking errors, it was not done before
resource.TestCheckResourceAttrSet(resourceName, "project_id"), | ||
resource.TestCheckResourceAttr(resourceName, "provider_name", constant.AWS), | ||
resource.TestCheckResourceAttrSet(resourceName, "provisioned"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines seems to be repeated many times. Maybe refactor into a helper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think there was a similar comment in another PR, I don't disagree but let's talk to use the same approach in all resources
@@ -211,42 +210,49 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di | |||
} | |||
|
|||
func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { | |||
if !d.HasChange("region_name") && !d.HasChange("atlas_cidr_block") && !d.HasChange("region_name") && !d.HasChange("region") && !d.HasChange("regions") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think region_name
is repeated twice? and missing provider_name
? Sorry if I am missing some further context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, thanks! i was doing multiple tests and at the end i didn't revert this, updated
Let's make sure @BrettFolkins has the opportunity to review this PR (already sent a Slack DM) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for picking up where I left off and getting a full solution to this ready so quickly!
regionName, _ := conversion.ValRegion(d.Get("region_name")) | ||
region, _ := conversion.ValRegion(d.Get("region")) | ||
|
||
params := &admin.CloudProviderContainer{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar enough with best practices in terraform providers to have an opinion about sending the request with only the necessary changes or the full target state, but this version lgtm. Thanks!
resource.TestCheckResourceAttrSet(dataSourcePluralName, "results.0.provider_name"), | ||
resource.TestCheckResourceAttrSet(dataSourcePluralName, "results.0.provisioned"), | ||
), | ||
Check: resource.ComposeTestCheckFunc(commonChecks(constant.AWS)...), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EspenAlbert at then end i did the refactor you recommended following @AgustinBettati example in search_deployment. a lot of duplication gone and clearer to read. (still this resource might have more specific attribute checks, not only that they exist). cc @marcosuma
* failing test * recreate resource if provider_name changes * fix update * allow update in place when provider_name changes * fix regions error handling * refactor tests checks * refactor checks in mig tests as well * fix change check
…ted (#2052) * schedule compatibility matrix first day of month * WIP: test if status can be retrieved * test * test echo job status * change * Revert "change" This reverts commit 4b0e49e. * Revert "test echo job status" This reverts commit 4a83862. * test getting outputs of matrix * result * send slack * checkout step * fix name * correct json * formating * Revert "formating" This reverts commit f584822. * format * try * Revert "try" This reverts commit 7029f54. * use cat * Revert "use cat" This reverts commit 9503cd2. * remove unnecesary double quote * try cat * Revert "try cat" This reverts commit a2df8ff. * return json * unify json * fix * enrich message * TEMP: tag oncall on success * chore: Updates Atlas Go SDK (#2044) * build(deps): bump go.mongodb.org/atlas-sdk * fix tags * undo changes to admin20231001002 * API breaking change fixes --------- Co-authored-by: lantoli <[email protected]> * chore: Follow-up to Atlas SDK upgrade (#2051) * remove unused NewGroup * unify List call thanks to new API * refactor: Uses mocks on admin.APIClient for Project+Teams+ClustersAPIs instead of custom service (#2045) * refactor: Uses mocks on admin.APIClient instead of custom ClusterService (#2056) * fix: Fixes `network_container` resource update (#2055) * failing test * recreate resource if provider_name changes * fix update * allow update in place when provider_name changes * fix regions error handling * refactor tests checks * refactor checks in mig tests as well * fix change check * use MONGODB_ATLAS_PROJECT_ID (#2060) * chore: Removes old service from mockery (#2063) * feat: Allows user to specify to use an existing tag for release (#2053) * remove TEMP oncall tag on success * initialize oncall_tag * send notification when test suite fails * revert back testing change * remove temporary trigger of action * use oncall tag from secrets * Revert "use oncall tag from secrets" This reverts commit 5a7944f. * use SHA * new line * make oncall tag a secret --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: lantoli <[email protected]> Co-authored-by: Espen Albert <[email protected]> Co-authored-by: maastha <[email protected]>
Description
Fixes
network_container
resource update when only one field changes.Based on this PR: #2031
Type of change:
Required Checklist:
Further comments