mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
check for duplicate import blocks (#33190)
Importing to the same target address twice or importing the same ID to multiple different resources of the same type is not allowed.
This commit is contained in:
15
internal/command/testdata/validate-invalid/duplicate_import_ids/main.tf
vendored
Normal file
15
internal/command/testdata/validate-invalid/duplicate_import_ids/main.tf
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
resource "aws_instance" "web" {
|
||||
}
|
||||
|
||||
resource "aws_instance" "other_web" {
|
||||
}
|
||||
|
||||
import {
|
||||
to = aws_instance.web
|
||||
id = "test"
|
||||
}
|
||||
|
||||
import {
|
||||
to = aws_instance.other_web
|
||||
id = "test"
|
||||
}
|
||||
34
internal/command/testdata/validate-invalid/duplicate_import_ids/output.json
vendored
Normal file
34
internal/command/testdata/validate-invalid/duplicate_import_ids/output.json
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"format_version": "1.0",
|
||||
"valid": false,
|
||||
"error_count": 1,
|
||||
"warning_count": 0,
|
||||
"diagnostics": [
|
||||
{
|
||||
"severity": "error",
|
||||
"summary": "Duplicate import for ID \"test\"",
|
||||
"detail": "An import block for the ID \"test\" and a resource of type \"aws_instance\" was already declared at testdata/validate-invalid/duplicate_import_ids/main.tf:7,1-7. The same resource cannot be imported twice.",
|
||||
"range": {
|
||||
"filename": "testdata/validate-invalid/duplicate_import_ids/main.tf",
|
||||
"start": {
|
||||
"line": 12,
|
||||
"column": 1,
|
||||
"byte": 126
|
||||
},
|
||||
"end": {
|
||||
"line": 12,
|
||||
"column": 7,
|
||||
"byte": 132
|
||||
}
|
||||
},
|
||||
"snippet": {
|
||||
"context": null,
|
||||
"code": "import {",
|
||||
"start_line": 12,
|
||||
"highlight_start_offset": 0,
|
||||
"highlight_end_offset": 6,
|
||||
"values": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
12
internal/command/testdata/validate-invalid/duplicate_import_targets/main.tf
vendored
Normal file
12
internal/command/testdata/validate-invalid/duplicate_import_targets/main.tf
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
resource "aws_instance" "web" {
|
||||
}
|
||||
|
||||
import {
|
||||
to = aws_instance.web
|
||||
id = "test"
|
||||
}
|
||||
|
||||
import {
|
||||
to = aws_instance.web
|
||||
id = "test2"
|
||||
}
|
||||
34
internal/command/testdata/validate-invalid/duplicate_import_targets/output.json
vendored
Normal file
34
internal/command/testdata/validate-invalid/duplicate_import_targets/output.json
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"format_version": "1.0",
|
||||
"valid": false,
|
||||
"error_count": 1,
|
||||
"warning_count": 0,
|
||||
"diagnostics": [
|
||||
{
|
||||
"severity": "error",
|
||||
"summary": "Duplicate import configuration for \"aws_instance.web\"",
|
||||
"detail": "An import block for the resource \"aws_instance.web\" was already declared at testdata/validate-invalid/duplicate_import_targets/main.tf:4,1-7. A resource can have only one import block.",
|
||||
"range": {
|
||||
"filename": "testdata/validate-invalid/duplicate_import_targets/main.tf",
|
||||
"start": {
|
||||
"line": 9,
|
||||
"column": 1,
|
||||
"byte": 85
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"column": 7,
|
||||
"byte": 91
|
||||
}
|
||||
},
|
||||
"snippet": {
|
||||
"context": null,
|
||||
"code": "import {",
|
||||
"start_line": 9,
|
||||
"highlight_start_offset": 0,
|
||||
"highlight_end_offset": 6,
|
||||
"values": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user