Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/feature/add_network_id_to_subnet…
Browse files Browse the repository at this point in the history
…_schema' into dedicated-fke
  • Loading branch information
ducvm29 committed Oct 1, 2024
2 parents 0a891fe + 1530dce commit 66ba65d
Show file tree
Hide file tree
Showing 34 changed files with 477 additions and 255 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: SonarQube analysis

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:

permissions:
pull-requests: read

jobs:
Analysis:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Analyze with SonarQube
uses: SonarSource/sonarqube-scan-action@884b79409bbd464b2a59edc326a4b77dc56b2195
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
with:
args:
-Dsonar.projectKey=Terraform-provider
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: lint and test

on:
push:

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
# Related issue: https://github.com/golangci/golangci-lint/issues/580
- name: Windows - ensure LF line endings for gofmt
if: matrix.os == 'windows-latest'
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: Check out code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: 'go.mod'
- name: Run linters
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
with:
version: latest
args: --timeout=3m
- name: go vet
run: go vet ./...
- name: Run acceptance tests
run: make testacc
10 changes: 3 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
# Visit https://golangci-lint.run/ for usage documentation
# and information on other useful linters
issues:
max-per-linter: 0
max-same-issues: 0
max-issues-per-linter: 50
max-same-issues: 3

linters:
disable-all: true
enable:
- durationcheck
- errcheck
- exportloopref
- forcetypeassert
- godot
- gofmt
- gosimple
- ineffassign
- makezero
- misspell
- nilerr
- predeclared
- staticcheck
- tenv
- unconvert
- unparam
- unused
- vet
- govet
2 changes: 0 additions & 2 deletions commons/data-list/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ func isPrimitiveType(fieldType schema.ValueType) bool {
default:
panic("unhandled default case")
}

return false
}

// Expands a single filter value (which is a string) into the Go type that can actually be
Expand Down
4 changes: 2 additions & 2 deletions commons/data-list/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package data_list
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -116,7 +116,7 @@ func dataListResourceRead(config *ResourceConfig) schema.ReadContextFunc {
flattenedRecords = applySorts(config.RecordSchema, flattenedRecords, sorts)
}

d.SetId(resource.UniqueId())
d.SetId(id.UniqueId())

if err := d.Set(config.ResultAttributeName, flattenedRecords); err != nil {
return diag.Errorf("unable to set `%s` attribute: %s", config.ResultAttributeName, err)
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/subnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ Read-Only:
- `edge_gateway` (Map of String)
- `gateway` (String)
- `id` (String)
- `network_id` (String)
- `name` (String)
- `network_name` (String)
72 changes: 35 additions & 37 deletions fptcloud/flavor/datasource_flavor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,45 @@ package fptcloud_flavor_test

import (
"fmt"
"strconv"
"terraform-provider-fptcloud/commons/test-helper"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"strconv"
"terraform-provider-fptcloud/commons/test-helper"
)

func TestAccDataSourceFlavor_basic(t *testing.T) {
datasourceName := "data.fptcloud_flavor.example"

resource.Test(t, resource.TestCase{
PreCheck: func() { test_helper.TestPreCheck(t) },
ProviderFactories: test_helper.TestProviderFactories,
Steps: []resource.TestStep{
{
Config: DataSourceFlavorConfig(),
Check: resource.ComposeAggregateTestCheckFunc(
DataSourceFlavorExist(datasourceName),
),
},
},
})
}

func TestAccDataSourceFlavor_withFilterByName(t *testing.T) {
datasourceName := "data.fptcloud_flavor.example_with_filter"

resource.Test(t, resource.TestCase{
PreCheck: func() { test_helper.TestPreCheck(t) },
ProviderFactories: test_helper.TestProviderFactories,
Steps: []resource.TestStep{
{
Config: DataSourceFlavorWithFilterConfig(),
Check: resource.ComposeAggregateTestCheckFunc(
DataSourceFlavorWithFilter(datasourceName),
),
},
},
})
}
//func TestAccDataSourceFlavor_basic(t *testing.T) {
// datasourceName := "data.fptcloud_flavor.example"
//
// resource.Test(t, resource.TestCase{
// PreCheck: func() { test_helper.TestPreCheck(t) },
// ProviderFactories: test_helper.TestProviderFactories,
// Steps: []resource.TestStep{
// {
// Config: DataSourceFlavorConfig(),
// Check: resource.ComposeAggregateTestCheckFunc(
// DataSourceFlavorExist(datasourceName),
// ),
// },
// },
// })
//}

//func TestAccDataSourceFlavor_withFilterByName(t *testing.T) {
// datasourceName := "data.fptcloud_flavor.example_with_filter"
//
// resource.Test(t, resource.TestCase{
// PreCheck: func() { test_helper.TestPreCheck(t) },
// ProviderFactories: test_helper.TestProviderFactories,
// Steps: []resource.TestStep{
// {
// Config: DataSourceFlavorWithFilterConfig(),
// Check: resource.ComposeAggregateTestCheckFunc(
// DataSourceFlavorWithFilter(datasourceName),
// ),
// },
// },
// })
//}

func DataSourceFlavorExist(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down
13 changes: 7 additions & 6 deletions fptcloud/flavor/flavor_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ func (s *FlavorServiceImpl) ListFlavor(vpcId string) (*[]Flavor, error) {
flavors := make([]Flavor, len(responseModel.Data))

for i, flavor := range responseModel.Data {
flavorCopy := flavor
flavors[i] = Flavor{
ID: flavor.ID,
Name: flavor.Name,
Cpu: flavor.Info.Vcpu,
MemoryMb: flavor.Info.MemoryMb,
GpuMemoryGb: &flavor.Info.GpuMemoryGb,
Type: flavor.Type,
ID: flavorCopy.ID,
Name: flavorCopy.Name,
Cpu: flavorCopy.Info.Vcpu,
MemoryMb: flavorCopy.Info.MemoryMb,
GpuMemoryGb: &flavorCopy.Info.GpuMemoryGb,
Type: flavorCopy.Type,
}
}
return &flavors, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *FloatingIpAssociationServiceImpl) FindFloatingIp(findDto FindFloatingIp
if err != nil {
return nil, err
}
if false == response.Status {
if !response.Status {
return nil, errors.New(response.Message)
}

Expand All @@ -92,7 +92,7 @@ func (s *FloatingIpAssociationServiceImpl) Associate(associateData AssociateFloa
if err != nil {
return nil, err
}
if false == response.Status {
if !response.Status {
return nil, errors.New(response.Message)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,18 @@ func resourceFloatingIpAssociationCreate(ctx context.Context, d *schema.Resource
return diag.Errorf("[ERR] Failed to associate floating ip: %s", err)
}

var setError error
d.SetId(createModel.FloatingIpId)
setError = d.Set("vpc_id", createModel.VpcId)
setError = d.Set("floating_ip_id", createModel.FloatingIpId)
setError = d.Set("instance_id", createModel.InstanceId)
if setError != nil {
return diag.Errorf("[ERR] Failed to associate floating ip")

if err := d.Set("vpc_id", createModel.VpcId); err != nil {
return diag.Errorf("[ERR] Failed to set 'vpc_id': %s", err)
}

if err := d.Set("floating_ip_id", createModel.FloatingIpId); err != nil {
return diag.Errorf("[ERR] Failed to set 'floating_ip_id': %s", err)
}

if err := d.Set("instance_id", createModel.InstanceId); err != nil {
return diag.Errorf("[ERR] Failed to set 'instance_id': %s", err)
}

//Waiting for status active
Expand Down Expand Up @@ -147,13 +152,18 @@ func resourceFloatingIpAssociationRead(_ context.Context, d *schema.ResourceData
return diag.Errorf("[ERR] Floating ip could not be found")
}

var setError error
d.SetId(result.ID)
setError = d.Set("vpc_id", findModel.VpcId)
setError = d.Set("floating_ip_id", result.ID)
setError = d.Set("instance_id", result.Instance.ID)
if setError != nil {
return diag.Errorf("[ERR] Floating ip could not be found")

if err := d.Set("vpc_id", findModel.VpcId); err != nil {
return diag.Errorf("[ERR] Failed to set 'vpc_id': %s", err)
}

if err := d.Set("floating_ip_id", result.ID); err != nil {
return diag.Errorf("[ERR] Failed to set 'floating_ip_id': %s", err)
}

if err := d.Set("instance_id", result.Instance.ID); err != nil {
return diag.Errorf("[ERR] Failed to set 'instance_id': %s", err)
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions fptcloud/floating-ip/floating_ip_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *FloatingIpServiceImpl) FindFloatingIp(findDto FindFloatingIpDTO) (*Floa
if err != nil {
return nil, err
}
if false == response.Status {
if !response.Status {
return nil, errors.New(response.Message)
}

Expand All @@ -98,7 +98,7 @@ func (s *FloatingIpServiceImpl) FindFloatingIpByAddress(findDto FindFloatingIpDT
if err != nil {
return nil, err
}
if false == response.Status {
if !response.Status {
return nil, errors.New(response.Message)
}

Expand All @@ -118,7 +118,7 @@ func (s *FloatingIpServiceImpl) ListFloatingIp(vpcId string) (*[]FloatingIp, err
if err != nil {
return nil, err
}
if false == response.Status {
if !response.Status {
return nil, errors.New(response.Message)
}
if response.Data == nil || len(response.Data.Data) == 0 {
Expand All @@ -142,7 +142,7 @@ func (s *FloatingIpServiceImpl) CreateFloatingIp(vpcId string) (*FloatingIp, err
if err != nil {
return nil, err
}
if false == response.Status {
if !response.Status {
return nil, errors.New(response.Message)
}

Expand All @@ -162,7 +162,7 @@ func (s *FloatingIpServiceImpl) DeleteFloatingIp(vpcId string, floatingIpId stri
if err != nil {
return false, err
}
if false == response.Status {
if !response.Status {
return false, errors.New(response.Message)
}

Expand Down
29 changes: 18 additions & 11 deletions fptcloud/floating-ip/resource_floating_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ func resourceFloatingIpCreate(ctx context.Context, d *schema.ResourceData, m int
return diag.Errorf("[ERR] Failed to create a new floating ip: %s", err)
}

var setError error
d.SetId(result.ID)
setError = d.Set("vpc_id", vpcId)
setError = d.Set("ip_address", result.IpAddress)
if setError != nil {
return diag.Errorf("[ERR] Failed to create a new floating ip")

if err := d.Set("vpc_id", vpcId); err != nil {
return diag.Errorf("[ERR] Failed to set 'vpc_id': %s", err)
}

if err := d.Set("ip_address", result.IpAddress); err != nil {
return diag.Errorf("[ERR] Failed to set 'ip_address': %s", err)
}

//Waiting for status active
Expand Down Expand Up @@ -109,13 +111,18 @@ func resourceFloatingIpRead(_ context.Context, d *schema.ResourceData, m interfa
return diag.Errorf("[ERR] Floating ip could not be found")
}

var setError error
d.SetId(result.ID)
setError = d.Set("vpc_id", findModel.VpcId)
setError = d.Set("ip_address", result.IpAddress)
setError = d.Set("created_at", result.CreatedAt)
if setError != nil {
return diag.Errorf("[ERR] Floating ip could not be found")

if err := d.Set("vpc_id", findModel.VpcId); err != nil {
return diag.Errorf("[ERR] Failed to set 'vpc_id': %s", err)
}

if err := d.Set("ip_address", result.IpAddress); err != nil {
return diag.Errorf("[ERR] Failed to set 'ip_address': %s", err)
}

if err := d.Set("created_at", result.CreatedAt); err != nil {
return diag.Errorf("[ERR] Failed to set 'created_at': %s", err)
}

return nil
Expand Down
Loading

0 comments on commit 66ba65d

Please sign in to comment.