mirror of
https://github.com/hashicorp/terraform.git
synced 2026-05-12 17:09:33 -04:00
test: Add failing tests that show expected behaviour when a pre-release of a provider is used
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
parent
d695528f5f
commit
ddf50df609
8 changed files with 164 additions and 0 deletions
|
|
@ -202,6 +202,47 @@ func TestInit_two_step_provider_download(t *testing.T) {
|
|||
- Using previously-installed hashicorp/random v1.0.0`,
|
||||
},
|
||||
},
|
||||
// Same tests with providers shared between config and state,
|
||||
// but now the version constraint in config specifies a pre-release
|
||||
"pre-release required by only the state file": {
|
||||
workDirPath: "init-provider-download-prerelease/state-file-only",
|
||||
expectedDownloadMsgs: []string{
|
||||
views.MessageRegistry[views.OutputInitSuccessCLIMessage].JSONValue,
|
||||
`Initializing provider plugins found in the configuration...
|
||||
Initializing the backend...`, // No providers found in the configuration so next output is backend-related
|
||||
`Initializing provider plugins found in the state...
|
||||
- Finding latest version of hashicorp/random...
|
||||
- Installing hashicorp/random v9.9.9...`, // The latest version is expected, as state has no version constraints
|
||||
},
|
||||
},
|
||||
"pre-release not re-downloaded if present in both config and state": {
|
||||
workDirPath: "init-provider-download-prerelease/config-and-state-same-providers",
|
||||
expectedDownloadMsgs: []string{
|
||||
// Config
|
||||
`Initializing provider plugins found in the configuration...
|
||||
- Finding hashicorp/random versions matching "1.2.3-beta"...
|
||||
- Installing hashicorp/random v1.2.3-beta...
|
||||
- Installed hashicorp/random v1.2.3-beta`,
|
||||
// State
|
||||
`Initializing provider plugins found in the state...
|
||||
- Reusing previous version of hashicorp/random
|
||||
- Using previously-installed hashicorp/random v1.2.3-beta`,
|
||||
},
|
||||
},
|
||||
"reuses pre-release provider already represented in a dependency lock file": {
|
||||
workDirPath: "init-provider-download-prerelease/config-state-file-and-lockfile",
|
||||
expectedDownloadMsgs: []string{
|
||||
// Config
|
||||
`Initializing provider plugins found in the configuration...
|
||||
- Reusing previous version of hashicorp/random from the dependency lock file
|
||||
- Installing hashicorp/random v1.2.3-beta...
|
||||
- Installed hashicorp/random v1.2.3-beta`,
|
||||
// State
|
||||
`Initializing provider plugins found in the state...
|
||||
- Reusing previous version of hashicorp/random
|
||||
- Using previously-installed hashicorp/random v1.2.3-beta`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for tn, tc := range cases {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
random = {
|
||||
source = "hashicorp/random"
|
||||
version = "1.2.3-beta"
|
||||
}
|
||||
}
|
||||
|
||||
backend "local" {
|
||||
path = "./state-using-random-provider.tfstate"
|
||||
}
|
||||
}
|
||||
|
||||
resource "random_pet" "maurice" {}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"version": 4,
|
||||
"terraform_version": "1.14.0",
|
||||
"serial": 1,
|
||||
"lineage": "foobar",
|
||||
"resources": [
|
||||
{
|
||||
"mode": "managed",
|
||||
"type": "random_pet",
|
||||
"name": "maurice",
|
||||
"provider": "provider[\"registry.terraform.io/hashicorp/random\"]",
|
||||
"instances": [
|
||||
{
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"id": "sassy-ferret",
|
||||
"keepers": null,
|
||||
"length": 2,
|
||||
"prefix": null,
|
||||
"separator": "-"
|
||||
},
|
||||
"sensitive_attributes": [],
|
||||
"identity_schema_version": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# This file is maintained automatically by "terraform init".
|
||||
# Manual edits may be lost in future updates.
|
||||
|
||||
provider "registry.terraform.io/hashicorp/random" {
|
||||
version = "1.2.3-beta"
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
random = {
|
||||
source = "hashicorp/random"
|
||||
version = "1.2.3-beta"
|
||||
}
|
||||
}
|
||||
|
||||
backend "local" {
|
||||
path = "./state-using-random-provider.tfstate"
|
||||
}
|
||||
}
|
||||
|
||||
resource "random_pet" "maurice" {}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"version": 4,
|
||||
"terraform_version": "1.14.0",
|
||||
"serial": 1,
|
||||
"lineage": "foobar",
|
||||
"resources": [
|
||||
{
|
||||
"mode": "managed",
|
||||
"type": "random_pet",
|
||||
"name": "maurice",
|
||||
"provider": "provider[\"registry.terraform.io/hashicorp/random\"]",
|
||||
"instances": [
|
||||
{
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"id": "sassy-ferret",
|
||||
"keepers": null,
|
||||
"length": 2,
|
||||
"prefix": null,
|
||||
"separator": "-"
|
||||
},
|
||||
"sensitive_attributes": [],
|
||||
"identity_schema_version": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
5
internal/command/testdata/init-provider-download-prerelease/state-file-only/main.tf
vendored
Normal file
5
internal/command/testdata/init-provider-download-prerelease/state-file-only/main.tf
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
terraform {
|
||||
backend "local" {
|
||||
path = "./state-using-random-provider.tfstate"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"version": 4,
|
||||
"terraform_version": "1.14.0",
|
||||
"serial": 1,
|
||||
"lineage": "foobar",
|
||||
"resources": [
|
||||
{
|
||||
"mode": "managed",
|
||||
"type": "random_pet",
|
||||
"name": "maurice",
|
||||
"provider": "provider[\"registry.terraform.io/hashicorp/random\"]",
|
||||
"instances": [
|
||||
{
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"id": "sassy-ferret",
|
||||
"keepers": null,
|
||||
"length": 2,
|
||||
"prefix": null,
|
||||
"separator": "-"
|
||||
},
|
||||
"sensitive_attributes": [],
|
||||
"identity_schema_version": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in a new issue