Fix Terraform remote backend detection to support all backend types#6682
Open
Fix Terraform remote backend detection to support all backend types#6682
Conversation
- Updated isRemoteBackendConfig() to recognize all remote backend types - Added support for Terraform Cloud (both legacy 'remote' and new 'cloud' syntax) - Added support for AWS S3, GCS, Consul, COS, HTTP, Kubernetes, OSS, and PostgreSQL backends - Created comprehensive unit tests for all backend types - This fixes the deprecated -state flag warning when using Terraform Cloud and other remote backends Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
…h nosec directive Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix deprecated -state flag warning for Terraform Cloud backend
Fix Terraform remote backend detection to support all backend types
Feb 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the Terraform provider incorrectly applied the deprecated -state flag when using remote backends other than Azure RM. The issue occurred because the isRemoteBackendConfig() function only checked for backend "azurerm", causing warnings when using Terraform Cloud, AWS S3, Google Cloud Storage, or other remote backends.
Changes:
- Extended remote backend detection to recognize 10 additional backend types including Terraform Cloud (
cloud {}andbackend "remote"), AWS S3, GCS, and other cloud providers - Added comprehensive test coverage for backend detection with 7 test cases covering common scenarios (azurerm, remote, cloud, s3, gcs, local, and no backend)
- Created test fixture files for each backend type to verify correct detection behavior
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| cli/azd/pkg/infra/provisioning/terraform/terraform_provider.go | Extended isRemoteBackendConfig() to check for multiple remote backend types instead of only azurerm |
| cli/azd/pkg/infra/provisioning/terraform/terraform_provider_test.go | Added TestIsRemoteBackendConfig with table-driven tests for various backend configurations |
| cli/azd/pkg/infra/provisioning/terraform/testdata/backend_tests/*.tf | Created test fixtures for azurerm, remote, cloud, s3, gcs, local, and no-backend scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
@copilot apply changes based on the comments in this thread |
…ensive tests
- Improved cloud block detection to require both 'terraform {' and 'cloud {' to reduce false positives
- Added detailed documentation about the string matching approach and its limitations
- Removed deprecated backends (etcd, swift, artifactory, manta) from detection list
- Added comprehensive test coverage for consul, http, and kubernetes backends
- Updated comments to explain why certain backends are included/excluded
Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
Member
|
/azp run azure-dev - cli |
|
Azure Pipelines successfully started running 1 pipeline(s). |
weikanglim
reviewed
Feb 4, 2026
- Added early check for 'backend' keyword before scanning specific backend types
- This improves performance by skipping detailed checks for files without backend config
- Maintains check for Terraform Cloud 'cloud {}' syntax which doesn't use 'backend' keyword
- All tests continue to pass
Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Plan to Fix Terraform Remote Backend Detection
isRemoteBackendConfig()isRemoteBackendConfig()to recognize all remote backend types-stateflag warningChanges from Review Feedback
Initial Review (Addressed):
cloud {detection (Comment 2752395659)Latest Optimization (Comment 2765449116):
backendkeyword before scanning specific backend typescloud {}syntax separately since it doesn't use thebackendkeywordSecurity Summary
No security vulnerabilities introduced. CodeQL analysis: 0 alerts.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.