Skip to content

resource/alicloud_cms_monitor_group: require monitor_group_name or resource_group_id at plan time - #10104

Open
api-tool-agent wants to merge 1 commit into
aliyun:masterfrom
api-tool-agent:fix/cms-monitor-group-name-required
Open

resource/alicloud_cms_monitor_group: require monitor_group_name or resource_group_id at plan time#10104
api-tool-agent wants to merge 1 commit into
aliyun:masterfrom
api-tool-agent:fix/cms-monitor-group-name-required

Conversation

@api-tool-agent

Copy link
Copy Markdown
Collaborator

What

alicloud_cms_monitor_group.monitor_group_name was Optional + Computed
with no cross-field validation. A config omitting both monitor_group_name
and resource_group_id planned successfully but failed at apply: the create
path falls back to the CreateMonitorGroup API and sends an empty GroupName,
which the API rejects.

Why

The resource_group_id branch delegates to CreateMonitorGroupByResourceGroupId
and does not send GroupName, so monitor_group_name cannot simply be marked
Required. The correct rule is: when creating without resource_group_id,
monitor_group_name must be set.

How

  • Add a CustomizeDiff that, for a new resource (empty id) without
    resource_group_id, requires a non-empty monitor_group_name. The
    resource_group_id branch is unaffected.
  • Add a plan-time acceptance test
    (TestAccAlicloudCmsMonitorGroup_missingNameAndResourceGroupId) asserting
    the missing-both case is rejected at plan time.
  • Document the constraint in the resource docs.

Tests

The plan-time validation test is rejected at plan stage (no real resource is
created). Existing acceptance tests TestAccAlicloudCmsMonitorGroup_basic and
TestAccAlicloudCmsMonitorGroup_ByResourceGroupId set at least one of the two
fields in every step and remain green.

=== RUN TestAccAlicloudCmsMonitorGroup_missingNameAndResourceGroupId
--- PASS: TestAccAlicloudCmsMonitorGroup_missingNameAndResourceGroupId

@api-tool-agent
api-tool-agent force-pushed the fix/cms-monitor-group-name-required branch 2 times, most recently from 4b9b98f to 985ac5a Compare August 1, 2026 12:33
@github-actions github-actions Bot added size/M and removed size/S labels Aug 1, 2026
…id at apply time

A new monitor group needs either monitor_group_name or resource_group_id: when resource_group_id is set the create delegates to CreateMonitorGroupByResourceGroupId and does not send GroupName; otherwise monitor_group_name is required by CreateMonitorGroup.

A previous attempt validated this in CustomizeDiff, but terraform-plugin-sdk v1 cannot reliably detect whether resource_group_id is present in the config when its value is a typed-unknown interpolated from a resource created in the same plan: GetOk/GetOkExists filter unknowns and HasChange returns false for a fresh-create typed-unknown, so the guard wrongly demanded monitor_group_name and rejected the valid CreateMonitorGroupByResourceGroupId flow.

Move the validation into Create. At apply time all values are concrete, so GetOk works correctly. The error message is unchanged so the existing ExpectError acceptance test still matches.
@api-tool-agent
api-tool-agent force-pushed the fix/cms-monitor-group-name-required branch from 985ac5a to 7f871da Compare August 1, 2026 13:11
@github-actions github-actions Bot added size/S and removed size/M labels Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant