-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issue where importing random_string & random_password is not writ…
…ing all defaults into TF state Co-authored-by: Benjamin Bennett <ben.bennett@hashicorp.com>
- Loading branch information
1 parent
b8d7b4e
commit ef0bc4a
Showing
11 changed files
with
333 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# Random Password can be imported by specifying the value of the string: | ||
# Random Password can be imported by specifying the value of the password. | ||
terraform import random_password.password securepassword |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# Strings can be imported by just specifying the value of the string: | ||
# Random String can be imported by specifying the value of the string. | ||
terraform import random_string.test test |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" | ||
subcategory: "" | ||
description: |- | ||
{{ .Description | plainmarkdown | trimspace | prefixlines " " }} | ||
--- | ||
|
||
# {{.Name}} ({{.Type}}) | ||
|
||
{{ .Description | trimspace }} | ||
|
||
## Example Usage | ||
|
||
{{ tffile "examples/resources/random_password/resource.tf" }} | ||
|
||
{{ .SchemaMarkdown | trimspace }} | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
terraform import random_password.password securepassword | ||
``` | ||
|
||
### Limitations of Import | ||
|
||
Any attribute values that are specified within Terraform config will be | ||
ignored during import and all attributes that have defaults defined within | ||
the schema will have the default assigned. | ||
|
||
For instance, using the following config during import: | ||
```terraform | ||
resource "random_password" "password" { | ||
length = 16 | ||
lower = false | ||
} | ||
``` | ||
|
||
Then importing the resource using `terraform import random_password.password securepassword`, | ||
would result in the triggering of a replacement (i.e., destroy-create) during the next | ||
`terraform apply`. | ||
|
||
### Avoiding Replacement | ||
|
||
If the resource were imported using `terraform import random_password.password securepassword`, | ||
replacement could be avoided by using: | ||
|
||
1. Attribute values that match the imported ID and defaults: | ||
|
||
```terraform | ||
resource "random_password" "password" { | ||
length = 14 | ||
lower = true | ||
} | ||
``` | ||
|
||
|
||
2. Attribute values that match the imported ID and omit the attributes with defaults: | ||
|
||
```terraform | ||
resource "random_password" "password" { | ||
length = 14 | ||
} | ||
``` | ||
|
||
|
||
3. `ignore_changes` specifying the attributes to ignore: | ||
|
||
```terraform | ||
resource "random_password" "password" { | ||
length = 16 | ||
lower = false | ||
|
||
lifecycle { | ||
ignore_changes = [ | ||
length, | ||
lower, | ||
] | ||
} | ||
} | ||
``` | ||
|
||
**NOTE** `ignore_changes` is only required until the resource is recreated after import, | ||
after which it will use the configuration values specified. |
Oops, something went wrong.