Skip to content

Commit 0af5dcf

Browse files
akinrosssamiib
andauthored
[minor_change] Mux existing provider with terraform-plugin-framework base for new provider, migrate aci_annotation resource and datasource to framework provider and add aci_external_management_network_instance_profile, aci_external_management_network_subnet, aci_l3out_consumer_label, aci_l3out_redistribute_policy, aci_out_of_band_contract, aci_pim_route_map_entry, aci_pim_route_map_policy and aci_relation_to_consumed_out_of_band_contract resources and data sources (#1113)
Co-authored-by: samitab <[email protected]>
1 parent 77fc4b3 commit 0af5dcf

File tree

2,793 files changed

+190325
-29286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,793 files changed

+190325
-29286
lines changed

README.md

Lines changed: 183 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
12
# Cisco ACI Provider
23

3-
Requirements
4-
------------
4+
## Requirements
55

66
- [Terraform](https://www.terraform.io/downloads.html)
77
- v0.12 and higher (ACI Provider v1.0.0 or higher)
88
- v0.11.x or below (ACI Provider v0.7.1 or below)
99

1010
- [Go](https://golang.org/doc/install) Latest Version
1111

12-
## Building The Provider ##
12+
## Building The Provider
13+
1314
Clone this repository to: `$GOPATH/src/github.com/CiscoDevNet/terraform-provider-cisco-aci`.
1415

1516
```sh
@@ -26,9 +27,8 @@ $ make build
2627

2728
```
2829

29-
Using The Provider
30-
<!-- https://www.terraform.io/docs/plugins/basics.html#installing-a-plugin -->
31-
------------------
30+
## Using The Provider
31+
3232
If you are building the provider, follow the instructions to [install it as a plugin.](https://www.terraform.io/docs/cli/plugins/index.html) After placing it into your plugins directory, run `terraform init` to initialize it.
3333

3434
ex.
@@ -88,9 +88,181 @@ terraform apply -parallelism=1
8888

8989
Note: The value of "cert_name" argument must match the name of the certificate object attached to the APIC user (aaaUserCert) used for signature-based authentication
9090

91-
Developing The Provider
92-
-----------------------
93-
If you want to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine.
91+
## Developing The Provider
92+
93+
Currently the ACI provider is a [muxed provider](https://developer.hashicorp.com/terraform/plugin/mux) which allows us to simultaneously serve [terraform-plugin-sdk/v2](https://developer.hashicorp.com/terraform/plugin/sdkv2) and [terraform-plugin-framework](https://developer.hashicorp.com/terraform/plugin/framework) provider SDK implementations. This adds some complexity to the development process, but allows us to leverage the new capabilities that terraform-plugin-framework provides, while working on a migration strategy for existing resources.
94+
95+
### Pre-Requirements
96+
97+
1. Install latest version of [Go](http://www.golang.org)
98+
99+
### Existing resources and data-sources developed with terraform-plugin-sdk/v2
100+
101+
* Existing resources and data-sources are located in the [aci](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/aci) directory.
102+
103+
* Changes are made directly in the `provider.go`, `resource_*.go`, `data_source_*.go` and `utils` files. The [aci-go-client](https://github.com/ciscoecosystem/aci-go-client) is leveraged to construct payload constructs and handle REST communication towards the APIC.
104+
105+
* Documentation is manually maintained in the [legacy-docs](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/legacy-docs) directory and are copied automatically up on execution of `go generate` command.
106+
107+
* Examples are manually maintained in the [examples](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples) directory, where each resource has it's own directory.
108+
109+
#### Manual Development Process
110+
111+
The below steps should be followed for developing `terraform-plugin-sdk/v2` resources and data-sources:
112+
113+
1. Create issue (if not created yet) and comment that you will be working on the issue.
114+
115+
2. Fork the terraform-provider-aci repository.
116+
117+
3. Clone the forked code to your local machine.
118+
119+
4. Make changes to the files manually.
120+
* Code changes
121+
* Examples changes
122+
* Documentation changes
123+
124+
5. Run `go generate` in the root of the local repository where the `main.go` is located. Assure that the documentation is copied to the docs folder and no changes are made to files in the [internal/provider](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/internal/provider) directory.
125+
126+
5. Test the code.
127+
128+
6. Create PR for the code and request review from active maintainers.
129+
130+
7. Review process
131+
132+
### New resources and data-sources developed with terraform-plugin-framework
133+
134+
* New resources and data-sources are located in the [internal/provider](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/internal/provider) directory.
135+
136+
* The `provider.go`, `resource_*.go`, `resource_*_test.go`, `data_source_*.go`, `data_source_*_test.go` are generated with templates and should not be changed manually. Files that are automatically generated start with `// Code generated by "gen/generator.go"; DO NOT EDIT.` and should not be modified. When a file is not generated correctly, the template of that file must be adjusted.
137+
138+
* Examples used in the documentation are generated automatically and stored in the [examples/resources](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/resources) and [examples/data-sources](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/data-sources) directories.
139+
140+
* Documentation for resources and datasources are generated automatically and stored in the [docs](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/docs) directory.
141+
142+
* There are a few exceptions of static files which need to be changed manually:
143+
144+
* Files related to `rest_managed`
145+
* [provider_test.go](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/internal/provider/provider_test.go)
146+
* [provider.tf](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/provider/provider.tf)
147+
148+
#### Generator Process
149+
150+
New resources and data-sources are generated with [generator.go](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/gen/generator.go). The generator assumes that the following directories exist in the directory where the generate.go file is located:
151+
152+
- `./definitions`
153+
* contains the manually created YAML files with the ACI class definitions for overwriting the meta data retrieved from APIC
154+
155+
- `./meta`
156+
* contains the JSON files with the ACI class metadata which are retrieved from APIC
157+
158+
- `./templates`
159+
* contains the Go templates used to generate the full provider code
160+
161+
- `./testvars`
162+
* contains the generated YAML files with the test variables used in the *_test.go and example files
163+
164+
The below steps should be followed for developing `terraform-plugin-framework` resources and data-sources:
165+
166+
1. Create issue and comment that you will be working on the issue.
167+
168+
2. Fork the terraform-provider-aci repository.
169+
170+
3. Clone the forked code to your local machine.
171+
172+
4. Add minimum required class details to [classes.yaml](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/gen/definitions/classes.yaml).
173+
* `ui_location`
174+
* `sub_category`
175+
176+
5. Copy new meta file(s) or replace existing with newer version of the meta file(s) to the [meta](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/gen/meta) directory in the following format: `<classname>.json`. Assure that all relationship classes are also added to the `meta` directory. The `GEN_HOST` and `GEN_CLASSES` environment variables can be leveraged to retrieve the classes automatically before rendering the code.
177+
* `GEN_HOST` can be set to a resolvable APIC host, example: `192.158.1.38`. When not provided the devnet documentation will be retrieved.
178+
* `GEN_CLASSES` should be set to a comma-separated string of classes, example: `fvTenant` or `fvTenant,fvBD`
179+
180+
6. Run `go generate` in the root of the local repository where the `main.go` is located. The following files should be created or updated:
181+
* `resource_<resource-name>.go` and `resource_<resource-name>_test.go`
182+
* `data_source_<resource-name>.go` and `data_source_<resource-name>_test.go`
183+
* `<resource-name>.md` in the [docs/resources](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/docs/resources) and [docs/data-sources](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/docs/data-sources) directories.
184+
* `resource.tf` and `data-source.tf`
185+
* `provider.go`
186+
187+
6. Validate generated files generated on the following items:
188+
* resource name
189+
* incorrect resource names should be overwritten in [classes.yaml](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/gen/definitions/classes.yaml) by providing `resource_name: "<resource-name>"`
190+
* schema attributes ( class properties and children )
191+
* incorrect property names should be overwritten in [properties.yaml](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/gen/definitions/properties.yaml) by providing a global or class specific overwrite
192+
* all relationships classes are included
193+
* documentation contains the example and all information is correct
194+
* Run `go generate` again until the files are generated as preferred. When you are not achieving the desired outputs, reource, data-source, example and/or documentation templates should be adjusted.
195+
196+
8. Test the generated code of your resources and data-sources
197+
* Execute the tests for all your generated resources and data-sources
198+
* Set the below environment variables when running tests:
199+
```sh
200+
export ACI_VAL_REL_DN=false
201+
export TF_ACC=1
202+
export ACI_USERNAME="USER"
203+
export ACI_URL="https://IPADDRESS"
204+
export ACI_PASSWORD="PASSWORD"
205+
```
206+
* The following command can be used `go test internal/provider/* -v -run <test-name>`, where the test name can be found in the `resource_<resource-name>_test.go` and `data_source_<resource-name>_test.go` files.
207+
* Adjust generated test_values in case incorrect values are used. All test values are resolved by estimating the values. Some values are hard to resolve with and thus need to be overwritten in [properties.yaml](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/gen/definitions/properties.yaml) file under the class specific test_values.
208+
* Some tests have a dependency on a specific parent, which is unknown because the resource is not an autogenerated resource yet. This can be set in the [properties.yaml](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/gen/definitions/properties.yaml) file under the the class specific parents.
209+
* Run `go generate` again until the files are generated as preferred. When you are not achieving the desired outputs, the test templates should be adjusted.
210+
211+
9. Create PR for the code and request review from active maintainers.
212+
213+
10. Review process
214+
215+
### Troubleshooting
216+
217+
#### Go Generate Fail
218+
219+
If you encounter an error message while generating the resources using go generate, a few steps can be followed:
220+
221+
1. Make sure that you're running the latest version of Go
222+
223+
2. Update dependencies and populate the vendor directory: If you're using Go modules, you can update your dependencies and populate your vendor directory by running the following commands in your terminal:
224+
225+
```sh
226+
go mod tidy
227+
go mod vendor
228+
```
229+
230+
The go mod tidy command will clean up unused dependencies and add missing ones. The go mod vendor command will copy all dependencies into the vendor directory.
231+
232+
3. Disable vendor mode (if necessary): If the error still persists, consider disabling vendor mode by setting GOFLAGS="-mod=mod", and then run go get again:
233+
234+
```sh
235+
export GOFLAGS="-mod=mod"
236+
```
237+
238+
This will force Go to fetch the package directly, regardless of the vendor directory. After the package is downloaded, you can switch back to vendor mode if needed.
239+
240+
#### Missing packages
241+
242+
If you encounter an error indicating that the golang.org/x/text/language package is missing from your vendor directory, you can fetch it by following these steps:
243+
244+
1. Disable vendor mode: Go operates in vendor mode when the -mod=vendor flag is set. You'll need to disable vendor mode to fetch packages directly. Run the following command in your terminal:
245+
246+
```sh
247+
export GOFLAGS="-mod=mod"
248+
```
249+
250+
2. Fetch the missing package: Now that vendor mode is disabled, you can fetch the missing package by running:
251+
252+
```sh
253+
go get golang.org/x/text/language
254+
```
255+
256+
This command tells Go to fetch the golang.org/x/text/language package directly, regardless of the vendor directory
257+
258+
3. Re-enable vendor mode (if necessary): If you wish to switch back to vendor mode, you can do so by running:
259+
260+
```sh
261+
export GOFLAGS="-mod=vendor"
262+
```
263+
264+
265+
### Compiling
94266
95267
To compile the provider, run `make build`. This will build the provider with sanity checks present in scripts directory and put the provider binary in `$GOPATH/bin` directory.
96268
@@ -115,3 +287,5 @@ To compile the provider, run `make build`. This will build the provider with san
115287
```
116288
117289
<strong>NOTE:</strong> Currently only resource properties supports the reflecting manual changes made in CISCO ACI. Manual changes to relationship is not taken care by the provider.
290+
291+

aci/data_source_aci_tagannotation.go

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)