Skip to content

Commit

Permalink
Merge pull request #2 from Edge-Center/CID_25888_floating_ip
Browse files Browse the repository at this point in the history
Cid 25888 floating ip
  • Loading branch information
anaxaim authored Jan 26, 2023
2 parents 4a37c50 + 96b96dc commit ae03cfc
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 370 deletions.
14 changes: 10 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
### IDEs
.vscode
.idea
.DS_Store

### terraform
.terraform/
terraform.tfplan
terraform.tfstate
./*.tfstate

### other
dist/
modules-dev/
/pkg/
*.backup
./*.tfstate
.terraform/
*.log
.idea
*.log
5 changes: 5 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ build: fmtcheck
go build -o $(PLUGIN_PATH)/$(BINARY_NAME)_v$(VERSION)
go build -o bin/$(BINARY_NAME)

build_debug: fmtcheck
mkdir -p $(PLUGIN_PATH)
go build -o $(PLUGIN_PATH)/$(BINARY_NAME)_v$(VERSION) -gcflags '-N -l'
go build -o bin/$(BINARY_NAME) -gcflags '-N -l'

test: fmtcheck
go test -i $(TEST) || exit 1
echo $(TEST) | \
Expand Down
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Requirements
- [Terraform](https://www.terraform.io/downloads.html) 0.13.x
- [Go](https://golang.org/doc/install) 1.19 (to build the provider plugin)

Latest provider
------------
- [edge-center provider](https://registry.terraform.io/providers/Edge-Center/edgecenter/latest)

Building the provider
---------------------
```sh
Expand Down Expand Up @@ -55,6 +59,7 @@ terraform {
required_providers {
edgecenter = {
source = "local.edgecenter.ru/repo/edgecenter"
version = "{version_number}" # need to specify
}
}
}
Expand All @@ -69,4 +74,66 @@ $ cp ./examples/... .
$ terraform init
```

Debugging
------------------
There are two ways to debbugging the provider:
### vscode debugging
1. create a `launch.json` file
- In the the Run view, click `create a launch.json file`
- Choose Go: Launch Package from the debug configuration drop-down menu.
- VS Code will create a `launch.json` file in a `.vscode` folder in your workspace
2. add a new configuration to `launch.json`:
- the `address` arg must be equal to the `source` field from your `provider.tf`
```
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Terraform Provider",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}",
"env": {},
"args": [
"-debug",
"-address=local.edgecenter.ru/repo/edgecenter"
]
}
]
}
```
3. launch the debug mode: `Run > Start Debugging (F5)`
4. copy `TF_REATTACH_PROVIDERS` env from the console and export it to the terminal as follows:
```
export TF_REATTACH_PROVIDERS='{"local.edgecenter.ru/repo/edgecenter":{...'
```
5. set a breakpoint in your code and apply the terraform config: `terraform apply`
6. debugging

### using delve
1. installing the delve lib - [installation](https://github.com/go-delve/delve/tree/master/Documentation/installation)
2. building binary without optimisation or use `make build_debug`
```
go build -o bin/$(BINARY_NAME) -gcflags '-N -l'
```
3. open first terminal:
- run the binary with debug option:
```
dlv exec bin/terraform-provider-edgecenter -- -debug
```
- set a breakpoint for the create function with a resource that want to debug, e.g,
```
break resourceFloatingIPCreate
```
- `continue`
- copy `TF_REATTACH_PROVIDERS` with its value from output
5. open second terminal:
- exporting `TF_REATTACH_PROVIDERS`:
```
export TF_REATTACH_PROVIDERS='{"local.edgecenter.ru/repo/edgecenter":{...'
```
- launch ```terraform apply```
- debugging with the `continue` command in the first terminal via `delve`

Thank You
6 changes: 3 additions & 3 deletions edgecenter/resource_edgecenter_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,9 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, m interfa
i["subnet_id"] = subnetID
i["port_id"] = iface.PortID
i["order"] = orderedIOpts.Order
if len(iface.FloatingIPDetails) > 0 {
i["fip_source"] = types.ExistingFloatingIP
i["existing_fip_id"] = iface.FloatingIPDetails[0].ID
if iOpts.FloatingIP != nil {
i["fip_source"] = iOpts.FloatingIP.Source.String()
i["existing_fip_id"] = iOpts.FloatingIP.ExistingFloatingID
}
i["ip_address"] = assignment.IPAddress.String()

Expand Down
29 changes: 15 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ require (
github.com/Edge-Center/edgecentercdn-go v0.1.0
github.com/Edge-Center/edgecentercloud-go v0.1.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
github.com/mitchellh/mapstructure v1.5.0
github.com/hashicorp/terraform v1.1.9
)

require (
Expand All @@ -32,24 +33,23 @@ require (
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.2.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v0.16.1 // indirect
github.com/hashicorp/go-hclog v1.2.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.3 // indirect
github.com/hashicorp/go-plugin v1.4.6 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hc-install v0.4.0 // indirect
github.com/hashicorp/hcl/v2 v2.11.1 // indirect
github.com/hashicorp/hcl/v2 v2.15.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-json v0.14.0 // indirect
github.com/hashicorp/terraform-plugin-docs v0.13.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.5.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.2.0 // indirect
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 // indirect
github.com/hashicorp/terraform-plugin-go v0.14.1 // indirect
github.com/hashicorp/terraform-plugin-log v0.7.0 // indirect
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c // indirect
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
github.com/imdario/mergo v0.3.13 // indirect
Expand All @@ -68,23 +68,24 @@ require (
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/zclconf/go-cty v1.10.0 // indirect
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/zclconf/go-cty v1.12.1 // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1 // indirect
google.golang.org/grpc v1.36.1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/go-openapi/runtime v0.24.1 // indirect
github.com/hashicorp/terraform v1.1.9
github.com/hashicorp/terraform-exec v0.17.2 // indirect
github.com/hashicorp/terraform-exec v0.17.3 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
go.mongodb.org/mongo-driver v1.10.1 // indirect
golang.org/x/net v0.0.0-20220526153639-5463443f8c37 // indirect
Expand Down
Loading

0 comments on commit ae03cfc

Please sign in to comment.