Skip to content

Commit

Permalink
Add support for accelerators to google_datafusion_instance (GoogleClo…
Browse files Browse the repository at this point in the history
…udPlatform#6851)

Added support to the field for Data Fusion, updated corresponding generated and handwritten tests, and added a custom diffsuppressfunc. 

Currently suggests a manual fix to a potential diff issue, will be able to update down line based on feedback from API team.
  • Loading branch information
NickElliot authored and ericayyliu committed Jul 26, 2023
1 parent f7f3408 commit 834b723
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
24 changes: 24 additions & 0 deletions mmv1/products/datafusion/Instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,28 @@ properties:
The resource name of the Pub/Sub topic. Format: projects/{projectId}/topics/{topic_id}
required: true
input: true
- !ruby/object:Api::Type::Array
name: 'accelerators'
description: |
List of accelerators enabled for this CDF instance.
If accelerators are enabled it is possible a permadiff will be created with the Options field.
Users will need to either manually update their state file to include these diffed options, or include the field in a [lifecycle ignore changes block](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes).
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::Enum
name: 'acceleratorType'
description: |
The type of an accelator for a CDF instance.
values:
- :CDC
- :HEALTHCARE
- :CCAI_INSIGHTS
required: true
- !ruby/object:Api::Type::Enum
name: 'state'
description: |
The type of an accelator for a CDF instance.
values:
- :ENABLED
- :DISABLED
8 changes: 7 additions & 1 deletion mmv1/products/datafusion/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
instance_name: "my-instance"
custom_code: !ruby/object:Provider::Terraform::CustomCode
pre_update: templates/terraform/pre_update/datafusion_instance_update.go.erb
constants: templates/terraform/constants/data_fusion_instance_option.go.erb
properties:
region: !ruby/object:Overrides::Terraform::PropertyOverride
ignore_read: true
Expand All @@ -77,8 +78,13 @@ overrides: !ruby/object:Overrides::ResourceOverrides
name: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/shortname_to_url.go.erb'
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
zone: !ruby/object:Overrides::Terraform::PropertyOverride
options: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
diff_suppress_func: 'instanceOptionsDiffSuppress'
zone: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
accelerators.state: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
# This is for copying files over
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var instanceAcceleratorOptions = []string{
"delta.default.checkpoint.directory",
"ui.feature.cdc",
}

func instanceOptionsDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
// Suppress diffs for the options generated by adding an accelerator to a data fusion instance
for _, option := range instanceAcceleratorOptions {
if strings.Contains(k, option) && new == "" {
return true
}
}

// Let diff be determined by options (above)
if strings.Contains(k, "options.%") {
return true
}

// For other keys, don't suppress diff.
return false
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ resource "google_data_fusion_instance" "<%= ctx[:primary_resource_id] %>" {
ip_allocation = "${google_compute_global_address.private_ip_alloc.address}/${google_compute_global_address.private_ip_alloc.prefix_length}"
}

accelerators {
accelerator_type = "CDC"
state = "ENABLED"
}
<%= ctx[:vars]['prober_test_run'] %>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ resource "google_data_fusion_instance" "foobar" {
options = {
prober_test_run = "true"
}
accelerators {
accelerator_type = "CDC"
state = "DISABLED"
}
}
`, instanceName)
}
Expand All @@ -66,6 +70,11 @@ resource "google_data_fusion_instance" "foobar" {
label2 = "value2"
}
version = "6.8.0"
accelerators {
accelerator_type = "CCAI_INSIGHTS"
state = "ENABLED"
}
# Mark for testing to avoid service networking connection usage that is not cleaned up
options = {
prober_test_run = "true"
Expand Down

0 comments on commit 834b723

Please sign in to comment.