Although I have been using terraform for several years, I am just starting out using terraform cloud and update/test cycle seems overly complicated.
What I have gleaned is to update the code for an existing version is:
I have to do these 6 steps every time I make any change, and want to test the change.
if i could use “…/” for my source instead of “app.terraform.io/myorg/mymodule/myprovider”
i could iterate the code/test cycle much faster.
Or is there a better way?
granted, once I have the module the way i want it, i could publish a version for good.
If you are asking about shared modules (as opposed to the root modules you would specify directly in workspace settings) then a pattern I would recommend is:
Inside the repository where you keep your module code, create a tests subdirectory.
Inside that directory, make one or more subdirectories representing different scenarios you need to test. For example, if your module has an option to enable or disable part of its functionality, you might have one scenario for it being enabled and another for it being disabled.
Inside each test scenario directory, write a module block with source = "../../" to refer to the shared module you are trying to test
Now you can test by applying each of your test scenarios:
terraform -chdir=tests/example init
terraform -chdir=tests/example apply
terraform -chdir=tests/example destroy
If you want to test how your module responds to a change then you can apply first before you make the change to establish a baseline state, then change the module and apply again to see the plan to update the existing objects.
This pattern will keep all of your test cases contained within your module’s own repository so that you can develop and test it independently of any workspace that might be using it, and so you can test it before you publish it in the registry.