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: docs/guides/migration.md
+63-57Lines changed: 63 additions & 57 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,13 @@ description: |-
7
7
8
8
## Introduction
9
9
10
-
Since its first release in September 2020, the Terraform ACI provider has significantly progressed, adding new resources and data sources to streamline the management of Cisco ACI environments. Over the years, we've transitioned from SDKv1 to [SDKv2](https://developer.hashicorp.com/terraform/plugin/sdkv2), and now to the latest [Terraform Plugin Framework](https://developer.hashicorp.com/terraform/plugin/framework). This new Plugin Framework is the recommended way for developing Terraform plugins and offers several advantages over SDKv2.
10
+
Since its first release in July 2019, the Terraform ACI provider has significantly progressed, adding new resources and data sources to streamline the management of Cisco ACI environments. Over the years, we've transitioned from SDKv1 to [SDKv2](https://developer.hashicorp.com/terraform/plugin/sdkv2), and now to the latest [Terraform Plugin Framework](https://developer.hashicorp.com/terraform/plugin/framework). This new Plugin Framework is the recommended way for developing Terraform plugins and offers several advantages over SDKv2.
11
11
12
-
In order to fully leverage the new features of the Terraform Plugin Framework, we undertook a complete rewrite of the Terraform ACI provider's resources and data sources. Although this was a significant effort, it presented an opportunity to review and enhance the existing ACI provider. This guide provides detailed steps for migrating from previous versions, outlines key optimization steps to enhance performance, and aims to facilitate a smoother transition for users adapting to these updates. Additionally, it outlines the new features introduced by the Terraform Plugin Framework, along with the modifications we implemented in the ACI provider and the rationale behind these changes.
12
+
In order to fully leverage the new features of the Terraform Plugin Framework, we decided to undertake a complete rewrite of the Terraform ACI provider's resources and data sources. Although this is a significant effort, it presented an opportunity to review and enhance the existing ACI provider and how the provider is developed.
13
+
14
+
This complete rewrite will stretch a series of releases starting with [v2.16.0](https://github.com/CiscoDevNet/terraform-provider-aci/releases/tag/v2.16.0) where all new resources and data sources will be implemented using the new Terraform Plugin Framework and pre-existing resources and data sources will be slowly migrated into the Terraform Plugin Framework. Migrated resources and data sources contain a note that specifies it has been migrated at the top of their documentation. Once all pre-existing resources are migrated to the Terraform Provider Framework, a major release of the provider will be created to remove legacy attributes.
15
+
16
+
This guide provides detailed steps for migrating from previous versions, outlines key optimization steps to enhance performance, and aims to facilitate a smoother transition for users adapting to these updates. Additionally, it outlines how the migrated resources use the new features introduced by the Terraform Plugin Framework, along with the modifications we implemented in the ACI provider and the rationale behind these changes.
13
17
14
18
## Upgrading the ACI Terraform Provider
15
19
@@ -20,57 +24,59 @@ Upgrading the ACI Terraform provider to a new version requires careful planning
20
24
Before making any changes, it's crucial to back up your current Terraform state. This precaution ensures that you can revert your environment to its previous state if any issues arise during the upgrade process.
21
25
22
26
1.**Local Backend:** Open a terminal and navigate to the directory where your ACI Terraform configuration files with the state are located. Copy the current state file (terraform.tfstate) to a backup location.
2. **Remote Backend:** If you are using a remote backend (e.g., S3, Azure Blob Storage), ensure you have a backup of the state file from the remote location.
30
34
31
35
### Step 2: Update the Provider Version
32
36
33
-
1.**Open the Terraform Configuration File:** Open the `main.tf` or the relevant Terraform configuration file where the ACI provider is defined.
37
+
The version meta-argument specifies the version constraint fora provider. The version constraint can be specifiedinthe [provider configuration](https://developer.hashicorp.com/terraform/language/providers/configuration) or inthe [required_providers block](https://developer.hashicorp.com/terraform/language/providers/requirements). The [version](https://developer.hashicorp.com/terraform/language/providers/configuration#version-deprecated) argument in the provider configuration is deprecated, and will be removed in future Terraform versions.
34
38
35
-
2.**Update the Provider Version:**We recommend setting [version constraints](https://developer.hashicorp.com/terraform/language/expressions/version-constraints) for the provider. Modify the provider block to specify the new version constraint for the ACI provider.
39
+
1. **Open the Terraform Configuration File:**Open the `main.tf` or the relevant Terraform configuration file where the ACI provider version constraint is defined.
36
40
37
-
***Version constraint format***
38
-
```hcl
39
-
terraform {
40
-
required_providers {
41
-
aci = {
42
-
source = "ciscodevnet/aci"
43
-
version = "x.y.z" # Replace with the new version number
44
-
}
45
-
}
46
-
}
47
-
```
41
+
2. **Update the Provider Version:** Terraform recommends setting [version constraints](https://developer.hashicorp.com/terraform/language/expressions/version-constraints) for providers. Modify the terraform.required_providers or provider block to specify the new version constraint for the ACI provider.
48
42
49
-
***Deprecated Terraform version constraint format***
50
-
```hcl
51
-
provider "aci" {
52
-
version = "x.y.z" # Replace with the new version number
53
-
# Other provider configuration options
54
-
}
55
-
```
43
+
***Version constraint format***
44
+
```hcl
45
+
terraform {
46
+
required_providers {
47
+
aci = {
48
+
source = "ciscodevnet/aci"
49
+
version = "~> x.y.z"# Replace with the new version number
50
+
}
51
+
}
52
+
}
53
+
```
54
+
55
+
***Deprecated Terraform version constraint format***
56
+
```hcl
57
+
provider "aci" {
58
+
version = "~> x.y.z"# Replace with the new version number
59
+
# Other provider configuration options
60
+
}
61
+
```
56
62
57
-
3.**Initialize the Configuration:** Run `terraform init` to reinitialize your configuration with the updated provider version.
63
+
3. **Initialize the Configuration:** Run `terraform init -upgrade` to reinitialize your configuration with the updated provider version.
58
64
59
-
```bash
60
-
terraform init
61
-
```
65
+
```bash
66
+
terraform init -upgrade
67
+
```
62
68
63
69
### Step 3: Review the Changes
64
70
65
71
1. **Plan the Changes:** Run `terraform plan` without modifying the configuration to preview the changes that will be applied with the new provider version.
66
72
67
-
```bash
68
-
terraform plan
69
-
```
73
+
```bash
74
+
terraform plan
75
+
```
70
76
71
77
2. **Review the Plan:** Carefully review the output of the `terraform plan`command to ensure that there are no changes.
72
78
73
-
~> Warnings are expected to be displayed in the plan output for legacy attributes, this topic will be addressed in ***Step 4: Migrate deprecated configuration***.
79
+
~> Warnings are expected to be displayed in the plan output forlegacy attributes, this topic will be addressedin[Step 4: Migrate deprecated configuration](#step-4-migrate-deprecated-configuration).
74
80
75
81
```bash
76
82
No changes. Your infrastructure matches the configuration.
@@ -119,20 +125,20 @@ The state file does not reflect the changes yet, because a refresh has not taken
119
125
***Old Configuration***
120
126
```hcl
121
127
resource "aci_bridge_domain""terraform_bd" {
122
-
tenant_dn = aci_tenant.terraform_tenant.id
123
-
name = "terraform_bd"
124
-
ll_addr = "::"
125
-
unk_mcast_act = "flood"
128
+
tenant_dn = aci_tenant.terraform_tenant.id
129
+
name = "terraform_bd"
130
+
ll_addr = "::"
131
+
unk_mcast_act = "flood"
126
132
}
127
133
```
128
134
129
135
***New Configuration***
130
136
```hcl
131
137
resource "aci_bridge_domain""terraform_bd" {
132
-
parent_dn = aci_tenant.terraform_tenant.id
133
-
name = "terraform_bd"
134
-
link_local_ipv6_address = "::"
135
-
l3_unknown_multicast_flooding = "flood"
138
+
parent_dn = aci_tenant.terraform_tenant.id
139
+
name = "terraform_bd"
140
+
link_local_ipv6_address = "::"
141
+
l3_unknown_multicast_flooding = "flood"
136
142
}
137
143
```
138
144
@@ -148,26 +154,26 @@ The state file does not reflect the changes yet, because a refresh has not taken
148
154
149
155
1. **Remove Backup (Optional):** If everything is working correctly, you can remove the backup state file.
150
156
151
-
```bash
152
-
rm terraform.tfstate.backup
153
-
```
157
+
```bash
158
+
rm terraform.tfstate.backup
159
+
```
154
160
155
161
By following these steps, you can safely upgrade the ACI Terraform provider to a new version while ensuring that you have a backup of your current state incase anything goes wrong.
156
162
157
163
## Optimization
158
164
159
-
1. **Add relationships to parent resource:** Reduces the amount of resources in the configuration by including children inside their parent resources. This will decrease the execution time by decreasing the size of the terraform graph and reducing the amount of REST API calls made towards APIC.
165
+
1. **Add relationships to parent resource:** Reduces the amount of resources in the configuration by including children inside their parent resources. This will decrease the execution time by decreasing the size of the terraform graph and reducing the amount of REST API calls made towards APIC. See section [Changed Child Objects in Payloads](#changed-child-objects-in-payloads) for more details.
@@ -284,7 +290,7 @@ In non-migrated resources, child objects (including relationship objects) were m
284
290
285
291
## Changed Annotation Behavior
286
292
287
-
The annotation attribute can be set for each MO that exposes the attribute, including children inside a resource. By default, the annotation is set to `orchestrator:terraform`, but this default can be overwritten at the provider level.
293
+
The annotation attribute can be set for each MO that exposes the attribute, including children inside a resource. By default, the annotation is set to `orchestrator:terraform`, but this default can be overwritten at different levels (provider, resource, child attribute).
288
294
289
295
```hcl
290
296
provider "aci" {
@@ -311,11 +317,11 @@ For non-migrated resources, the ID of the resource appears as "known after apply
311
317
312
318
## Error for Existing MO on Create
313
319
314
-
Migrated resources support the (`allow_existing_on_create`) provider-level option to check during the plan if an object already exists. By default, existing MOs will be automatically managed on apply, as (`allow_existing_on_create`) is set to `true` by default. This option can be set to `false`, providing a mechanism to prevent the management of the same MO by separate configurations. The drawback of this mechanism is that it requires an additional API call per resource during the plan to verify that the object does not already exist.
320
+
Migrated resources support the [allow_existing_on_create](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs#schema) provider-level option to check during the plan if an object already exists. By default, existing MOs will be automatically managed on apply, as `allow_existing_on_create` is set to `true` by default. This option can be set to `false`, providing a mechanism to prevent the management of the same MO by separate configurations. The drawback of this mechanism is that it requires an additional API call per resource during the plan to verify that the object does not already exist.
315
321
316
322
## Allowing Empty Input for Attributes
317
323
318
-
Migrated resources in the Terraform ACI provider support null, unknown, and known states. Terraform supports three states for any value: null (missing), unknown ("known after apply"), and known. Previous SDKs did not support null and unknown states, which prevented differentiating between an empty value and a non-provided value. Because of this limitation, updating a string value to an empty stringwas not possible before the Plugin Framework.
324
+
The attributes of migrated resources in the Terraform ACI provider now support null, unknown, and known states which can be used to reset values to empty or to enforce that children objects are not present. Terraform supports three states for any value: null (missing), unknown ("known after apply"), and known. Previous SDKs did not support null and unknown states, which prevented differentiating between an empty value and a non-provided value. Because of this limitation, updating a string value to an empty string, updating a map to an empty map or a list of maps to an empty list was not possible before the Plugin Framework but is now supported in the migrated resources.
0 commit comments