newgrp not working in startup script

This might just be a Linux 101 issue but still can't work out why. We have a custom built AMI with Docker installed and want to grant the Coder user access to use Docker. Since the Coder user doesn't exist on the AMI yet I added the commands to the startup_script in resource "coder_agent" The script runs
newgrp docker
newgrp docker
and it doesn't appear to work. We run the same command in the terminal and it works. So maybe something strange is happening with the session?
resource "coder_agent" "dev" {
count = data.coder_workspace.me.start_count
arch = "amd64"
auth = "aws-instance-identity"
os = "linux"
startup_script_behavior = "blocking"
startup_script = <<-EOT
set -e

# Add any commands that should be executed at workspace startup (e.g install requirements, start a program, etc) here
# docker group already exists
sudo usermod -aG docker coder
newgrp docker
resource "coder_agent" "dev" {
count = data.coder_workspace.me.start_count
arch = "amd64"
auth = "aws-instance-identity"
os = "linux"
startup_script_behavior = "blocking"
startup_script = <<-EOT
set -e

# Add any commands that should be executed at workspace startup (e.g install requirements, start a program, etc) here
# docker group already exists
sudo usermod -aG docker coder
newgrp docker
6 Replies
Codercord
Codercord3mo ago
<#1339381453821317161>
Category
Help needed
Product
code-server
Platform
Windows
Logs
Please post any relevant logs/error messages.
Chris2pi
Chris2piOP3mo ago
*linux OS
Phorcys
Phorcys3mo ago
@Chris2pi newgrp can only be used in an interactive session because it starts a new shell so, it seems you can't use it in this context you should create the coder user within the AMI and add that group to it
Chris2pi
Chris2piOP3mo ago
Thanks for that. Ok just linux 101, yes we did make the coder user in the AMI and it seems to be working.
Phorcys
Phorcys3mo ago
sounds good
Codercord
Codercord3mo ago
@Phorcys closed the thread.

Did you find this page helpful?