Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(terraform): validate configuration if triggered by Dependabot #623

Merged

Conversation

hknutsen
Copy link
Member

@hknutsen hknutsen commented Dec 20, 2024

Currently, if the Terraform workflow is triggered by Dependabot, both the Terraform Plan and Terraform Apply jobs are skipped, meaning the workflow does nothing 🤷 With the changes in this PR, the workflow should run until at least the Terraform Validate step to catch obvious errors.

If triggered by Dependabot, it's important that the Terraform backend is not initialized when running terraform init, since that requires authentication to Azure, which Dependabot can't do.

@hknutsen hknutsen added the enhancement New feature or request label Dec 20, 2024
@hknutsen hknutsen self-assigned this Dec 20, 2024
@hknutsen
Copy link
Member Author

hknutsen commented Dec 20, 2024

Hasn't been tested.

@hknutsen hknutsen marked this pull request as ready for review December 20, 2024 13:19
@hknutsen hknutsen requested a review from a team as a code owner December 20, 2024 13:19
@hknutsen
Copy link
Member Author

hknutsen commented Jan 2, 2025

Converting to draft until tested.

@hknutsen hknutsen marked this pull request as draft January 2, 2025 06:32
@sefornes sefornes marked this pull request as ready for review January 6, 2025 12:34
@hknutsen
Copy link
Member Author

@equinor/ops-actions-maintainers I've been unable to find a way to test this so far. I've tried to push commits as Dependabot (i.e. I've configured Git locally to commit as Dependabot), however in order to push to GitHub and trigger a workflow, you need to authenticate your account, so the commits are identified as mine anyway 🤷

I suggest we merge this PR, then either fix or revert this commit if it turns out to be broken.

@hknutsen hknutsen merged commit 9d552d9 into main Jan 16, 2025
9 checks passed
@hknutsen hknutsen deleted the feat/terraform/validate-config-if-triggered-by-dependabot branch January 16, 2025 08:56
hknutsen added a commit that referenced this pull request Jan 16, 2025
…#623)"

The Terraform workflow currently throws an error if triggered by
Dependabot and Dependabot secrets `AZURE_CLIENT_ID`,
`AZURE_SUBSCRIPTION_ID` and/or `AZURE_TENANT_ID` are not configured, as
these secrets are required by the Terraform workflow.

There are two possible solutions to this issue:

1. Set these secrets as not required in the Terraform workflow.
   The downside of this solution is that it can cause confusion regarding
   the usage of the Terraform workflow, as these secrets are still
   required for normal use, they're just not marked as required to
   prevent this error when triggered by Dependabot.

2. Add these Dependabot secrets to the relevant repository and set the
   values to empty strings. This adds an, in my opinion, unnecessary
   and confusing prerequisite for the Terraform workflow.

3. Revert the commit that broke the Terraform workflow.

Going for solution 3 keeps the Terraform workflow as simple as possible,
so that is the solution that I've gone for.

This reverts commit 9d552d9.
hknutsen added a commit that referenced this pull request Feb 25, 2025
)

Currently, if the Terraform workflow is triggered by Dependabot, both the `Terraform Plan` and `Terraform Apply` jobs are skipped, meaning the workflow does nothing. With thes changes, the workflow should run until at least the `Terraform Validate` step to catch obvious errors.

If triggered by Dependabot, it's important that the Terraform backend is _not_ initialized when running `terraform init`, since that requires authentication to Azure, which Dependabot can't do.
hknutsen added a commit that referenced this pull request Feb 25, 2025
)

Currently, if the Terraform workflow is triggered by Dependabot, both the `Terraform Plan` and `Terraform Apply` jobs are skipped, meaning the workflow does nothing. With thes changes, the workflow should run until at least the `Terraform Validate` step to catch obvious errors.

If triggered by Dependabot, it's important that the Terraform backend is _not_ initialized when running `terraform init`, since that requires authentication to Azure, which Dependabot can't do.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants