Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Terraform
Commits
0eea4e7c
Commit
0eea4e7c
authored
5 years ago
by
CJ Horton
Browse files
Options
Download
Email Patches
Plain Diff
prevent targeting for unsupported API versions
parent
650a272a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
backend/remote/backend_apply.go
+21
-0
backend/remote/backend_apply.go
backend/remote/backend_plan.go
+21
-0
backend/remote/backend_plan.go
backend/remote/testing.go
+6
-0
backend/remote/testing.go
with
48 additions
and
0 deletions
+48
-0
backend/remote/backend_apply.go
+
21
-
0
View file @
0eea4e7c
...
...
@@ -8,6 +8,7 @@ import (
"log"
tfe
"github.com/hashicorp/go-tfe"
version
"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform/backend"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform/tfdiags"
...
...
@@ -94,6 +95,26 @@ func (b *Remote) opApply(stopCtx, cancelCtx context.Context, op *backend.Operati
))
}
if
len
(
op
.
Targets
)
!=
0
{
// For API versions prior to 2.3, RemoteAPIVersion will return an empty string,
// so if there's an error when parsing the RemoteAPIVersion, it's handled as
// equivalent to an API version < 2.3.
currentAPIVersion
,
parseErr
:=
version
.
NewVersion
(
b
.
client
.
RemoteAPIVersion
())
desiredAPIVersion
,
_
:=
version
.
NewVersion
(
"2.3"
)
if
parseErr
!=
nil
||
currentAPIVersion
.
LessThan
(
desiredAPIVersion
)
{
diags
=
diags
.
Append
(
tfdiags
.
Sourceless
(
tfdiags
.
Error
,
"Resource targeting is not supported"
,
fmt
.
Sprintf
(
`The host %s does not support the -target option for `
+
`remote plans.`
,
b
.
hostname
,
),
))
}
}
// Return if there are any errors.
if
diags
.
HasErrors
()
{
return
nil
,
diags
.
Err
()
...
...
This diff is collapsed.
Click to expand it.
backend/remote/backend_plan.go
+
21
-
0
View file @
0eea4e7c
...
...
@@ -15,6 +15,7 @@ import (
"time"
tfe
"github.com/hashicorp/go-tfe"
version
"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform/backend"
"github.com/hashicorp/terraform/tfdiags"
)
...
...
@@ -98,6 +99,26 @@ func (b *Remote) opPlan(stopCtx, cancelCtx context.Context, op *backend.Operatio
))
}
if
len
(
op
.
Targets
)
!=
0
{
// For API versions prior to 2.3, RemoteAPIVersion will return an empty string,
// so if there's an error when parsing the RemoteAPIVersion, it's handled as
// equivalent to an API version < 2.3.
currentAPIVersion
,
parseErr
:=
version
.
NewVersion
(
b
.
client
.
RemoteAPIVersion
())
desiredAPIVersion
,
_
:=
version
.
NewVersion
(
"2.3"
)
if
parseErr
!=
nil
||
currentAPIVersion
.
LessThan
(
desiredAPIVersion
)
{
diags
=
diags
.
Append
(
tfdiags
.
Sourceless
(
tfdiags
.
Error
,
"Resource targeting is not supported"
,
fmt
.
Sprintf
(
`The host %s does not support the -target option for `
+
`remote plans.`
,
b
.
hostname
,
),
))
}
}
// Return if there are any errors.
if
diags
.
HasErrors
()
{
return
nil
,
diags
.
Err
()
...
...
This diff is collapsed.
Click to expand it.
backend/remote/testing.go
+
6
-
0
View file @
0eea4e7c
...
...
@@ -207,6 +207,12 @@ func testServer(t *testing.T) *httptest.Server {
}`
,
path
.
Base
(
r
.
URL
.
Path
)))
})
// Respond to pings to get the API version header.
mux
.
HandleFunc
(
"/api/v2/ping"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
Header
()
.
Set
(
"TFP-API-Version"
,
"2.3"
)
})
// Respond to the initial query to read the hashicorp org entitlements.
mux
.
HandleFunc
(
"/api/v2/organizations/hashicorp/entitlement-set"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/vnd.api+json"
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help