Skip to content

Commit af640ef

Browse files
nboyersNoah Boyersclaude
authored
fix: ignore security group drift on existing AWS instances (#175)
Pre-existing workspaces failed to start after the coder-workspace-egress change. Terraform saw the instance's security group differ from the template and planned an in-place swap, which needs a permission the provisioner role does not have: Error: updating EC2 Instance (i-015f7199b07d72549): modifying network interface: UnauthorizedOperation: not authorized to perform ec2:ModifyNetworkInterfaceAttribute on security-group/sg-04e29c7df56b05c4f The role is create-and-describe only. subnet_id and associate_public_ip_address were already ignored because they force a replacement; vpc_security_group_ids was the one network attribute left able to drift, so add it. New instances still get the current subnet, public IP, and security group, since ignore_changes only affects updates. Existing workspaces keep what they were built with and must be recreated to pick up the fix, which they need anyway: their instances have no public IP and so no egress. The security group lookup itself works; it resolved sg-04e29c7df56b05c4f. Co-authored-by: Noah Boyers <noah@coder.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent dee5257 commit af640ef

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

deployments/ai.coder.com/demo/devcontainers/workspace.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,16 @@ resource "aws_instance" "dev" {
100100

101101
# Prevent sudden replacements due to AMI updates. subnet_id is ignored for the
102102
# same reason: re-pointing the template shouldn't force-replace (and wipe)
103-
# workspaces already running in another subnet.
103+
# workspaces already running in another subnet. vpc_security_group_ids is
104+
# ignored because swapping it on a live instance needs
105+
# ec2:ModifyNetworkInterfaceAttribute, which the provisioner role does not
106+
# have. New instances still get the current values; existing ones must be
107+
# recreated to pick up changes.
104108
lifecycle {
105109
ignore_changes = [
106110
ami,
107-
subnet_id
111+
subnet_id,
112+
vpc_security_group_ids
108113
]
109114

110115
precondition {

deployments/ai.coder.com/demo/ec2-win-vm/workspace.tf

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,23 @@ resource "aws_instance" "this" {
124124
}
125125

126126
lifecycle {
127-
# subnet_id is ignored so re-pointing the template doesn't force-replace
128-
# (and wipe) workspaces already running in another subnet.
127+
# All three network attributes are create-time only for existing instances.
128+
# subnet_id and associate_public_ip_address would force a replacement, which
129+
# wipes the workspace. vpc_security_group_ids would be an in-place update
130+
# requiring ec2:ModifyNetworkInterfaceAttribute, which the provisioner role
131+
# does not have, so a pre-existing workspace fails to start:
132+
#
133+
# UnauthorizedOperation: not authorized to perform
134+
# ec2:ModifyNetworkInterfaceAttribute on security-group/sg-...
135+
#
136+
# New instances still get the current subnet, public IP, and security group,
137+
# since ignore_changes only applies to updates. Existing workspaces keep what
138+
# they were built with and must be recreated to pick up changes.
129139
ignore_changes = [
130140
ami,
131141
associate_public_ip_address,
132-
subnet_id
142+
subnet_id,
143+
vpc_security_group_ids
133144
]
134145

135146
precondition {

0 commit comments

Comments
 (0)