Skip to content

Commit

Permalink
Support connectivity fields for Composer 3 (#9889) (#17423)
Browse files Browse the repository at this point in the history
* add composer_network_attachment

* indicate conflicting configs

* commas

* no need for bidirectional conflict definition (generates double errors)

* protect nit PrivateClusterConfig

* for optimizing error messages about conflicts

* add 2 step update for composer_network_attachment

* make composer_network_attachment available in beta only

* add two step update for network and subnetwork

* corrections in 2 phase update for network/subnetwork

* remove composer3 check(CustomizeDiff will solve this), filter api error, add tests (unsetting netwok/subnetwork not working)

* added ForceNewIf fot network/subnetwork, problem with unsetting these fields remains

* add docs for composer_network_attachment

* add test for network attachment

* ignore non empty plan in network attachment test

* add networkAttachment update and conflicting fields tests

* add ComputedIf for network, change isComposer3

* minor corrections

* remove computedIf

* filter equivalent values of network/subnetwork in ForceNewIf

* simplify ResourceConditionFunc, add beta/ga version conditions

* typo

* more general comparison of network references

* use tpgresource.CompareSelfLinkRelativePaths instead of custom function

* modify isComposer3 to avoid merge conflicts later.

* removing this since documentation is handled in other PR and to avoid conflicts while merging.

* replace ExpectNonEmptyPlan with lifecycle.ignore_changes

* add testcase for changing network attachment to network and subnetwork

* add third step to TestAccComposerEnvironmentComposer3_updateWithNetworkAndSubnetwork

* modify tests to use different network for attachment

* remove unused constant

* remove ExpectNonEmptyPlan (already replaced with lifecycle.ignore_changes)

[upstream:76474ecb686e095b4436de3ce17d739a2a1a4b21]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Feb 26, 2024
1 parent e45a120 commit 1e56526
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changelog/9889.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
composer: added composer_network_attachment, modified network/subnetwork to work with composer 3, modified isComposer3 function to work with multiple types
```
```release-note:none
Fixes: b/304402329, b/304432955, b/304432958
```
14 changes: 13 additions & 1 deletion google/services/composer/resource_composer_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func ResourceComposerEnvironment() *schema.Resource {
Optional: true,
ForceNew: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `The Compute Engine subnetwork to be used for machine communications, , specified as a self-link, relative resource name (e.g. "projects/{project}/regions/{region}/subnetworks/{subnetwork}"), or by name. If subnetwork is provided, network must also be provided and the subnetwork must belong to the enclosing environment's project and region.`,
Description: `The Compute Engine subnetwork to be used for machine communications, specified as a self-link, relative resource name (e.g. "projects/{project}/regions/{region}/subnetworks/{subnetwork}"), or by name. If subnetwork is provided, network must also be provided and the subnetwork must belong to the enclosing environment's project and region.`,
},
"disk_size_gb": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -2173,6 +2173,7 @@ func expandComposerEnvironmentConfigNodeConfig(v interface{}, d *schema.Resource
}
transformed.Subnetwork = transformedSubnetwork
}

transformedIPAllocationPolicy, err := expandComposerEnvironmentIPAllocationPolicy(original["ip_allocation_policy"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -2616,6 +2617,17 @@ func isComposer3(imageVersion string) bool {
return strings.Contains(imageVersion, "composer-3")
}

func forceNewCustomDiff(key string) customdiff.ResourceConditionFunc {
return func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) bool {
old, new := d.GetChange(key)
imageVersion := d.Get("config.0.software_config.0.image_version").(string)
if isComposer3(imageVersion) || tpgresource.CompareSelfLinkRelativePaths("", old.(string), new.(string), nil) {
return false
}
return true
}
}

func imageVersionChangeValidationFunc(ctx context.Context, old, new, meta any) error {
if old.(string) != "" && !isComposer3(old.(string)) && isComposer3(new.(string)) {
return fmt.Errorf("upgrade to composer 3 is not yet supported")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
const testComposerEnvironmentPrefix = "tf-test-composer-env"
const testComposerNetworkPrefix = "tf-test-composer-net"
const testComposerBucketPrefix = "tf-test-composer-bucket"
const testComposerNetworkAttachmentPrefix = "tf-test-composer-nta"

func allComposerServiceAgents() []string {
return []string{
Expand Down

0 comments on commit 1e56526

Please sign in to comment.