Skip to content

Commit

Permalink
feat(LH-69475): Add tags support for ASA/IOS/FTD devices (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
weilueluo authored Sep 27, 2023
1 parent 2422531 commit 6e15ede
Show file tree
Hide file tree
Showing 47 changed files with 470 additions and 72 deletions.
17 changes: 15 additions & 2 deletions client/device/asa/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/retry"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/devicetype"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/featureflag"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/user"
Expand All @@ -20,6 +21,7 @@ type CreateInput struct {
ConnectorUid string
ConnectorType string
SocketAddress string
Tags tags.Type

Username string
Password string
Expand All @@ -36,6 +38,7 @@ type CreateOutput struct {
SocketAddress string `json:"ipv4"`
ConnectorType string `json:"larType"`
ConnectorUid string `json:"larUid"`
Tags tags.Type `json:"tags"`
}

type Metadata struct {
Expand All @@ -51,7 +54,7 @@ func (r *CreateError) Error() string {
return r.Err.Error()
}

func NewCreateRequestInput(name, connectorUid, connectorType, socketAddress, username, password string, ignoreCertificate bool) *CreateInput {
func NewCreateRequestInput(name, connectorUid, connectorType, socketAddress, username, password string, ignoreCertificate bool, tags tags.Type) *CreateInput {
return &CreateInput{
Name: name,
ConnectorUid: connectorUid,
Expand All @@ -60,6 +63,7 @@ func NewCreateRequestInput(name, connectorUid, connectorType, socketAddress, use
Username: username,
Password: password,
IgnoreCertificate: ignoreCertificate,
Tags: tags,
}
}

Expand All @@ -83,7 +87,15 @@ func Create(ctx context.Context, client http.Client, createInp CreateInput) (*Cr
}
// 1.3 create the device
deviceCreateOutp, err := device.Create(ctx, client, *device.NewCreateRequestInput(
createInp.Name, "ASA", createInp.ConnectorUid, createInp.ConnectorType, createInp.SocketAddress, false, createInp.IgnoreCertificate, metadata,
createInp.Name,
"ASA",
createInp.ConnectorUid,
createInp.ConnectorType,
createInp.SocketAddress,
false,
createInp.IgnoreCertificate,
metadata,
createInp.Tags,
))
var createdResourceId *string = nil
if deviceCreateOutp != nil {
Expand Down Expand Up @@ -207,6 +219,7 @@ func Create(ctx context.Context, client http.Client, createInp CreateInput) (*Cr
SocketAddress: deviceCreateOutp.SocketAddress,
ConnectorUid: deviceCreateOutp.ConnectorUid,
ConnectorType: deviceCreateOutp.ConnectorType,
Tags: deviceCreateOutp.Tags,
}
return &createOutp, nil
}
4 changes: 4 additions & 0 deletions client/device/asa/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/connector"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/asa/asaconfig"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/featureflag"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/statemachine/state"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/user/auth"
Expand All @@ -29,6 +30,7 @@ func TestAsaCreate(t *testing.T) {
WithName("my-asa").
OnboardedUsingCloudConnector("88888888-8888-8888-8888-888888888888").
WithLocation("10.10.0.1", 443).
WithTags(tags.New("tag1", "tag2")).
Build()

asaDeviceUsingSdc := device.NewReadOutputBuilder().
Expand Down Expand Up @@ -132,6 +134,7 @@ func TestAsaCreate(t *testing.T) {
SocketAddress: asaDevice.SocketAddress,
ConnectorType: asaDevice.ConnectorType,
ConnectorUid: asaDevice.ConnectorUid,
Tags: asaDevice.Tags,
}
assert.Equal(t, expectedCreatedOutput, *output)

Expand Down Expand Up @@ -257,6 +260,7 @@ func TestAsaCreate(t *testing.T) {
SocketAddress: asaDevice.SocketAddress,
ConnectorType: asaDevice.ConnectorType,
ConnectorUid: asaDevice.ConnectorUid,
Tags: asaDevice.Tags,
}
assert.Equal(t, expectedCreatedOutput, *output)

Expand Down
2 changes: 2 additions & 0 deletions client/device/asa/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package asa

import (
"context"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/devicetype"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device"
Expand All @@ -21,6 +22,7 @@ type ReadOutput struct {
SocketAddress string `json:"ipv4"`
Port string `json:"port"`
Host string `json:"host"`
Tags tags.Type `json:"tags"`

IgnoreCertificate bool `json:"ignoreCertificate"`
ConnectivityState int `json:"connectivityState,omitempty"`
Expand Down
15 changes: 9 additions & 6 deletions client/device/asa/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/connector"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/asa/asaconfig"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"strings"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/retry"
Expand All @@ -16,21 +17,23 @@ import (
)

type UpdateInput struct {
Uid string `json:"-"`
Name string `json:"name"`
Location string
Username string
Password string
Uid string `json:"-"`
Name string `json:"name"`
Location string `json:"-"`
Username string `json:"-"`
Password string `json:"-"`
Tags tags.Type `json:"tags"`
}

type UpdateOutput = device.UpdateOutput

func NewUpdateInput(uid string, name string, username string, password string) *UpdateInput {
func NewUpdateInput(uid string, name string, username string, password string, tags tags.Type) *UpdateInput {
return &UpdateInput{
Uid: uid,
Name: name,
Username: username,
Password: password,
Tags: tags,
}
}

Expand Down
9 changes: 8 additions & 1 deletion client/device/cloudftd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ package cloudftd
import (
"context"
"fmt"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudfmc"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudfmc/fmcplatform"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/cdo"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/retry"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/devicetype"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/ftd/license"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/ftd/tier"
Expand All @@ -25,12 +25,14 @@ type CreateInput struct {
PerformanceTier *tier.Type // ignored if it is physical device
Virtual bool
Licenses *[]license.Type
Tags tags.Type
}

type CreateOutput struct {
Uid string `json:"uid"`
Name string `json:"name"`
Metadata *Metadata `json:"metadata"`
Tags tags.Type `json:"tags"`
}

func NewCreateInput(
Expand All @@ -39,13 +41,15 @@ func NewCreateInput(
performanceTier *tier.Type,
virtual bool,
licenses *[]license.Type,
tags tags.Type,
) CreateInput {
return CreateInput{
Name: name,
AccessPolicyName: accessPolicyName,
PerformanceTier: performanceTier,
Virtual: virtual,
Licenses: licenses,
Tags: tags,
}
}

Expand All @@ -57,6 +61,7 @@ type createRequestBody struct {
State string `json:"state"` // TODO: use queueTriggerState?
Type string `json:"type"`
Model bool `json:"model"`
Tags tags.Type `json:"tags"`
}

func Create(ctx context.Context, client http.Client, createInp CreateInput) (*CreateOutput, error) {
Expand Down Expand Up @@ -120,6 +125,7 @@ func Create(ctx context.Context, client http.Client, createInp CreateInput) (*Cr
State: "NEW",
Type: "devices",
Model: false,
Tags: createInp.Tags,
}
createReq := client.NewPost(ctx, createUrl, createBody)
var createOup CreateOutput
Expand Down Expand Up @@ -158,5 +164,6 @@ func Create(ctx context.Context, client http.Client, createInp CreateInput) (*Cr
Uid: createOup.Uid,
Name: createOup.Name,
Metadata: &metadata,
Tags: createOup.Tags,
}, nil
}
7 changes: 7 additions & 0 deletions client/device/cloudftd/create_outputbuilder.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cloudftd

import "github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"

type CreateOutputBuilder struct {
createOutput *CreateOutput
}
Expand All @@ -25,6 +27,11 @@ func (b *CreateOutputBuilder) Metadata(metadata Metadata) *CreateOutputBuilder {
return b
}

func (b *CreateOutputBuilder) Tags(tags tags.Type) *CreateOutputBuilder {
b.createOutput.Tags = tags
return b
}

func (b *CreateOutputBuilder) Build() CreateOutput {
return *b.createOutput
}
72 changes: 64 additions & 8 deletions client/device/cloudftd/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ func TestCreateCloudFtd(t *testing.T) {
}{
{
testName: "successfully create Cloud FTD",
input: cloudftd.NewCreateInput(ftdName, ftdAccessPolicyName, &ftdPerformanceTier, ftdVirtual, ftdLicenseCaps),
input: cloudftd.NewCreateInput(
ftdName,
ftdAccessPolicyName,
&ftdPerformanceTier,
ftdVirtual,
ftdLicenseCaps,
ftdTags,
),
setupFunc: func() {
readFmcIsSuccessful(true)
readFmcDomainInfoIsSuccessful(true)
Expand All @@ -42,7 +49,14 @@ func TestCreateCloudFtd(t *testing.T) {
},
{
testName: "error when failed to read FMC",
input: cloudftd.NewCreateInput(ftdName, ftdAccessPolicyName, &ftdPerformanceTier, ftdVirtual, ftdLicenseCaps),
input: cloudftd.NewCreateInput(
ftdName,
ftdAccessPolicyName,
&ftdPerformanceTier,
ftdVirtual,
ftdLicenseCaps,
ftdTags,
),
setupFunc: func() {
readFmcIsSuccessful(false)
},
Expand All @@ -53,7 +67,14 @@ func TestCreateCloudFtd(t *testing.T) {
},
{
testName: "error when failed to read FMC domain info",
input: cloudftd.NewCreateInput(ftdName, ftdAccessPolicyName, &ftdPerformanceTier, ftdVirtual, ftdLicenseCaps),
input: cloudftd.NewCreateInput(
ftdName,
ftdAccessPolicyName,
&ftdPerformanceTier,
ftdVirtual,
ftdLicenseCaps,
ftdTags,
),
setupFunc: func() {
readFmcIsSuccessful(true)
readFmcDomainInfoIsSuccessful(false)
Expand All @@ -70,7 +91,14 @@ func TestCreateCloudFtd(t *testing.T) {
},
{
testName: "error when failed to read FMC Access Policy",
input: cloudftd.NewCreateInput(ftdName, ftdAccessPolicyName, &ftdPerformanceTier, ftdVirtual, ftdLicenseCaps),
input: cloudftd.NewCreateInput(
ftdName,
ftdAccessPolicyName,
&ftdPerformanceTier,
ftdVirtual,
ftdLicenseCaps,
ftdTags,
),
setupFunc: func() {
readFmcIsSuccessful(true)
readFmcDomainInfoIsSuccessful(true)
Expand All @@ -87,7 +115,14 @@ func TestCreateCloudFtd(t *testing.T) {
},
{
testName: "error when failed to create FTD",
input: cloudftd.NewCreateInput(ftdName, ftdAccessPolicyName, &ftdPerformanceTier, ftdVirtual, ftdLicenseCaps),
input: cloudftd.NewCreateInput(
ftdName,
ftdAccessPolicyName,
&ftdPerformanceTier,
ftdVirtual,
ftdLicenseCaps,
ftdTags,
),
setupFunc: func() {
readFmcIsSuccessful(true)
readFmcDomainInfoIsSuccessful(true)
Expand All @@ -104,7 +139,14 @@ func TestCreateCloudFtd(t *testing.T) {
},
{
testName: "error when failed to read FTD specific device",
input: cloudftd.NewCreateInput(ftdName, ftdAccessPolicyName, &ftdPerformanceTier, ftdVirtual, ftdLicenseCaps),
input: cloudftd.NewCreateInput(
ftdName,
ftdAccessPolicyName,
&ftdPerformanceTier,
ftdVirtual,
ftdLicenseCaps,
ftdTags,
),
setupFunc: func() {
readFmcIsSuccessful(true)
readFmcDomainInfoIsSuccessful(true)
Expand All @@ -121,7 +163,14 @@ func TestCreateCloudFtd(t *testing.T) {
},
{
testName: "error when failed to read trigger FTD onboarding",
input: cloudftd.NewCreateInput(ftdName, ftdAccessPolicyName, &ftdPerformanceTier, ftdVirtual, ftdLicenseCaps),
input: cloudftd.NewCreateInput(
ftdName,
ftdAccessPolicyName,
&ftdPerformanceTier,
ftdVirtual,
ftdLicenseCaps,
ftdTags,
),
setupFunc: func() {
readFmcIsSuccessful(true)
readFmcDomainInfoIsSuccessful(true)
Expand All @@ -138,7 +187,14 @@ func TestCreateCloudFtd(t *testing.T) {
},
{
testName: "error when failed to read retrieve FTD configure manager command",
input: cloudftd.NewCreateInput(ftdName, ftdAccessPolicyName, &ftdPerformanceTier, ftdVirtual, ftdLicenseCaps),
input: cloudftd.NewCreateInput(
ftdName,
ftdAccessPolicyName,
&ftdPerformanceTier,
ftdVirtual,
ftdLicenseCaps,
ftdTags,
),
setupFunc: func() {
readFmcIsSuccessful(true)
readFmcDomainInfoIsSuccessful(true)
Expand Down
2 changes: 2 additions & 0 deletions client/device/cloudftd/fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/statemachine"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/cloudfmc/accesspolicies"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/cloudfmc/fmcdomain"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/ftd/license"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/ftd/tier"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/statemachine/state"
Expand Down Expand Up @@ -62,6 +63,7 @@ const (
var (
ftdLicenseCaps = &[]license.Type{license.Base, license.Carrier}
ftdPerformanceTier = tier.FTDv5
ftdTags = tags.New("tags1", "tags2", "tags3")
)

var (
Expand Down
Loading

0 comments on commit 6e15ede

Please sign in to comment.