You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/terraform/v1.13.x/docs/language/stacks/component/manage.mdx
+44-17Lines changed: 44 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,20 @@ Stacks are made up of components, and each component includes a Terraform module
10
10
11
11
## Add components
12
12
13
-
The `component` block defines the pieces that make up your Stack. Add a `component` block for each top-level module you want to include in the Stack. You must specify the source module, inputs, and providers for each component. To learn more about the `component` refer to the [`component` block reference](/terraform/language/block/stack/tfcomponent/component).
13
+
The `component` block defines the pieces that make up your Stack. Add a `component` block for each top-level module you want to include in the Stack. When you define a `component` block, you specify the module that component sources its configuration from, any input variables the module requires, and provider configurations.
14
+
15
+
To learn more about the `component` refer to the [`component` block reference](/terraform/language/block/stack/tfcomponent/component).
14
16
15
17
## Remove components
16
18
17
-
Stacks take a systematic approach to removing components from your configuration. You must use a dedicated `removed` block in your component configuration to ensure Terraform can properly remove your component and the resources associated with that component.
19
+
Stacks take a systematic approach to removing components from your configuration. To remove a component from your Stack, you must do the following:
20
+
1. Delete the `component` block for the component you want to remove.
21
+
1. Add a `removed` block specifying the component you want to remove.
22
+
1. Push your configuration changes to HCP Terraform and apply the changes to your Stack.
23
+
24
+
In the `removed` block, you specify the component you want to remove, the module that component sources, and that component's provider configurations. Specifying all of a component's details ensures that Terraform can properly destroy all the resources associated with that component.
18
25
19
-
To remove a component, add a `removed` block to your component configuration specifying the component you want to remove. For example, if you want to remove the following `database` component:
26
+
For example, if you want to remove the following `database` component:
You add a `removed` block that specifies the component to remove, module that component sources, and the providers that component uses. The `removed` block also tells Terraform to destroy the resources managed by a component.
45
+
Add a `removed` block that specifies the component to remove, the module that component sources, and the providers that component uses.
39
46
40
47
<TIP>
41
48
42
49
Do not remove providers from your component configuration without first removing the components that require those providers. Terraform requires a component's providers to ensure it can successfully remove that component.
43
50
44
51
</TIP>
45
52
46
-
In the following example, Terraform removes the `database` component that sources from `./modules/database` and uses the `aws.main` provider:
53
+
The following example deletes the `database` component block and adds a `removed` block to tell Terraform to remove that component from your Stack:
47
54
48
55
```hcl
49
-
component "database" {
56
+
removed {
50
57
source = "./modules/database"
58
+
from = component.database
51
59
52
-
inputs = {
53
-
instance_class = "db.t3.micro"
60
+
providers = {
61
+
aws = provider.aws.main
54
62
}
63
+
}
64
+
```
65
+
66
+
After you apply the configuration in HCP Terraform, Terraform removes the `database` component and its resources from the associated Stack deployments. You can then delete the `removed` block from your component configuration file.
67
+
68
+
### Remove multiple components
69
+
70
+
If your `component` block uses the `for_each` meta-argument to define multiple components, use the `for_each` meta-argument in a `removed` block to let Terraform destroy multiple component instances. Using `for_each` in a `removed` block lets you remove all of the instances of a component, or a subset of those instances.
71
+
72
+
To remove all of the instances of a component, duplicate the same `for_each` expression in the `removed` block that you use in the `component` block. For example, to remove all of the instances of `env` components:
73
+
74
+
```hcl
75
+
component "env" {
76
+
for_each = ["dev", "staging"]
77
+
78
+
source = "../local-component"
55
79
56
80
providers = {
57
-
aws = provider.aws.main
81
+
#...
58
82
}
83
+
#...
59
84
}
85
+
```
60
86
87
+
Remove the `env` component block and add a `removed` block that uses the same `for_each` expression:
88
+
89
+
```hcl
61
90
removed {
62
-
source = "./modules/database"
63
-
from = component.database
91
+
for_each = ["dev", "staging"]
92
+
from = component.env[each.key]
64
93
65
94
providers = {
66
-
aws = provider.aws.main
95
+
#...
67
96
}
68
97
}
69
98
```
70
99
71
-
After you apply the configuration in HCP Terraform, Terraform removes the `database` component and its resources from the associated Stack deployments. You can then remove both the `component` block and the `removed` block from your component configuration file.
72
-
73
-
If your `component` block uses the `for_each` meta-argument to define multiple components, you can define a `removed` block with the `for_each` meta-argument to ensure Terraform destroys each component instance.
100
+
After you apply the configuration in HCP Terraform, Terraform removes all of the instances of the `env` component and its resources from the associated Stack deployments. You can then delete the `removed` block from your component configuration file.
74
101
75
-
In the following example, the `removed` block iterates through `local.deprecated_components` to remove the `staging` components and corresponding resources:
102
+
If you want to remove a subset of component instances, you must keep the `component` block that defines the instances you want to keep. In the following example, the `removed` block iterates through `local.deprecated_components` to remove the `staging` components and corresponding resources:
76
103
77
104
```hcl
78
105
locals {
@@ -101,7 +128,7 @@ removed {
101
128
}
102
129
```
103
130
104
-
In the above example, you can delete a component by removing it from the `local.components` list and adding it to the `local.removed_components` list.
131
+
After you apply the configuration in HCP Terraform, Terraform removes the `staging` component but the `dev` and `prod` components remain in your Stack. You can additionally delete more components by removing them from the `local.components` list and adding them to the `local.removed_components` list.
Copy file name to clipboardExpand all lines: content/terraform/v1.14.x (beta)/docs/language/stacks/component/manage.mdx
+44-17Lines changed: 44 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,20 @@ Stacks are made up of components, and each component includes a Terraform module
10
10
11
11
## Add components
12
12
13
-
The `component` block defines the pieces that make up your Stack. Add a `component` block for each top-level module you want to include in the Stack. You must specify the source module, inputs, and providers for each component. To learn more about the `component` refer to the [`component` block reference](/terraform/language/block/stack/tfcomponent/component).
13
+
The `component` block defines the pieces that make up your Stack. Add a `component` block for each top-level module you want to include in the Stack. When you define a `component` block, you specify the module that component sources its configuration from, any input variables the module requires, and provider configurations.
14
+
15
+
To learn more about the `component` refer to the [`component` block reference](/terraform/language/block/stack/tfcomponent/component).
14
16
15
17
## Remove components
16
18
17
-
Stacks take a systematic approach to removing components from your configuration. You must use a dedicated `removed` block in your component configuration to ensure Terraform can properly remove your component and the resources associated with that component.
19
+
Stacks take a systematic approach to removing components from your configuration. To remove a component from your Stack, you must do the following:
20
+
1. Delete the `component` block for the component you want to remove.
21
+
1. Add a `removed` block specifying the component you want to remove.
22
+
1. Push your configuration changes to HCP Terraform and apply the changes to your Stack.
23
+
24
+
In the `removed` block, you specify the component you want to remove, the module that component sources, and that component's provider configurations. Specifying all of a component's details ensures that Terraform can properly destroy all the resources associated with that component.
18
25
19
-
To remove a component, add a `removed` block to your component configuration specifying the component you want to remove. For example, if you want to remove the following `database` component:
26
+
For example, if you want to remove the following `database` component:
You add a `removed` block that specifies the component to remove, module that component sources, and the providers that component uses. The `removed` block also tells Terraform to destroy the resources managed by a component.
45
+
Add a `removed` block that specifies the component to remove, the module that component sources, and the providers that component uses.
39
46
40
47
<TIP>
41
48
42
49
Do not remove providers from your component configuration without first removing the components that require those providers. Terraform requires a component's providers to ensure it can successfully remove that component.
43
50
44
51
</TIP>
45
52
46
-
In the following example, Terraform removes the `database` component that sources from `./modules/database` and uses the `aws.main` provider:
53
+
The following example deletes the `database` component block and adds a `removed` block to tell Terraform to remove that component from your Stack:
47
54
48
55
```hcl
49
-
component "database" {
56
+
removed {
50
57
source = "./modules/database"
58
+
from = component.database
51
59
52
-
inputs = {
53
-
instance_class = "db.t3.micro"
60
+
providers = {
61
+
aws = provider.aws.main
54
62
}
63
+
}
64
+
```
65
+
66
+
After you apply the configuration in HCP Terraform, Terraform removes the `database` component and its resources from the associated Stack deployments. You can then delete the `removed` block from your component configuration file.
67
+
68
+
### Remove multiple components
69
+
70
+
If your `component` block uses the `for_each` meta-argument to define multiple components, use the `for_each` meta-argument in a `removed` block to let Terraform destroy multiple component instances. Using `for_each` in a `removed` block lets you remove all of the instances of a component, or a subset of those instances.
71
+
72
+
To remove all of the instances of a component, duplicate the same `for_each` expression in the `removed` block that you use in the `component` block. For example, to remove all of the instances of `env` components:
73
+
74
+
```hcl
75
+
component "env" {
76
+
for_each = ["dev", "staging"]
77
+
78
+
source = "../local-component"
55
79
56
80
providers = {
57
-
aws = provider.aws.main
81
+
#...
58
82
}
83
+
#...
59
84
}
85
+
```
60
86
87
+
Remove the `env` component block and add a `removed` block that uses the same `for_each` expression:
88
+
89
+
```hcl
61
90
removed {
62
-
source = "./modules/database"
63
-
from = component.database
91
+
for_each = ["dev", "staging"]
92
+
from = component.env[each.key]
64
93
65
94
providers = {
66
-
aws = provider.aws.main
95
+
#...
67
96
}
68
97
}
69
98
```
70
99
71
-
After you apply the configuration in HCP Terraform, Terraform removes the `database` component and its resources from the associated Stack deployments. You can then remove both the `component` block and the `removed` block from your component configuration file.
72
-
73
-
If your `component` block uses the `for_each` meta-argument to define multiple components, you can define a `removed` block with the `for_each` meta-argument to ensure Terraform destroys each component instance.
100
+
After you apply the configuration in HCP Terraform, Terraform removes all of the instances of the `env` component and its resources from the associated Stack deployments. You can then delete the `removed` block from your component configuration file.
74
101
75
-
In the following example, the `removed` block iterates through `local.deprecated_components` to remove the `staging` components and corresponding resources:
102
+
If you want to remove a subset of component instances, you must keep the `component` block that defines the instances you want to keep. In the following example, the `removed` block iterates through `local.deprecated_components` to remove the `staging` components and corresponding resources:
76
103
77
104
```hcl
78
105
locals {
@@ -101,7 +128,7 @@ removed {
101
128
}
102
129
```
103
130
104
-
In the above example, you can delete a component by removing it from the `local.components` list and adding it to the `local.removed_components` list.
131
+
After you apply the configuration in HCP Terraform, Terraform removes the `staging` component but the `dev` and `prod` components remain in your Stack. You can additionally delete more components by removing them from the `local.components` list and adding them to the `local.removed_components` list.
0 commit comments