After working on this all night, I found a solutions that works.
Here's a solutions that DOESN'T WORK:
/etc/cloud/cloud.cfg:
file.comment:
- regex: ^ - set_hostname
/etc/cloud/cloud.cfg:
file.comment:
- regex: ^ - update_hostname
The reason that doesn't work is that the /etc/cloud/cloud.cfg
bit is used as the ID for the state, and no two IDs can ever be the same in a SLS file since IDs are global. However, there's an alternative way to write states:
comment_set_hostname:
file.comment:
- name: /etc/cloud/cloud.cfg
- regex: ^ - set_hostname
comment_update_hostname:
file.comment:
- name: /etc/cloud/cloud.cfg
- regex: ^ - update_hostname
This version sets the file manually inside the state rather than including it as the ID of the state. In doing so, I can solve my problem.