diff --git a/CHANGELOG.md b/CHANGELOG.md index bdc0bd6f..c65f95dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 0.1.3 (unreleased) -- Add `catalystcenter_device_role` resource +- Add `catalystcenter_device` resource +- BREAKING CHANGE: Rename `catalystcenter_device` resource and data source to `catalystcenter_pnp_device` +- BREAKING CHANGE: Rename `catalystcenter_device_claim_site` resource and data source to `catalystcenter_pnp_device_claim_site` ## 0.1.2 diff --git a/docs/data-sources/device.md b/docs/data-sources/pnp_device.md similarity index 65% rename from docs/data-sources/device.md rename to docs/data-sources/pnp_device.md index d4ab3e51..974d411a 100644 --- a/docs/data-sources/device.md +++ b/docs/data-sources/pnp_device.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "catalystcenter_device Data Source - terraform-provider-catalystcenter" +page_title: "catalystcenter_pnp_device Data Source - terraform-provider-catalystcenter" subcategory: "Plug and Play" description: |- - This data source can read the Device. + This data source can read the PnP Device. --- -# catalystcenter_device (Data Source) +# catalystcenter_pnp_device (Data Source) -This data source can read the Device. +This data source can read the PnP Device. ## Example Usage ```terraform -data "catalystcenter_device" "example" { +data "catalystcenter_pnp_device" "example" { id = "76d24097-41c4-4558-a4d0-a8c07ac08470" } ``` diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index 3fd46e65..7c8d0237 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -9,7 +9,9 @@ description: |- ## 0.1.3 (unreleased) -- Add `catalystcenter_device_role` resource +- Add `catalystcenter_device` resource +- BREAKING CHANGE: Rename `catalystcenter_device` resource and data source to `catalystcenter_pnp_device` +- BREAKING CHANGE: Rename `catalystcenter_device_claim_site` resource and data source to `catalystcenter_pnp_device_claim_site` ## 0.1.2 diff --git a/docs/resources/device.md b/docs/resources/pnp_device.md similarity index 65% rename from docs/resources/device.md rename to docs/resources/pnp_device.md index c83207c1..c20980bd 100644 --- a/docs/resources/device.md +++ b/docs/resources/pnp_device.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "catalystcenter_device Resource - terraform-provider-catalystcenter" +page_title: "catalystcenter_pnp_device Resource - terraform-provider-catalystcenter" subcategory: "Plug and Play" description: |- - This resource can manage a Device. + This resource can manage a PnP Device. --- -# catalystcenter_device (Resource) +# catalystcenter_pnp_device (Resource) -This resource can manage a Device. +This resource can manage a PnP Device. ## Example Usage ```terraform -resource "catalystcenter_device" "example" { +resource "catalystcenter_pnp_device" "example" { serial_number = "FOC12345678" stack = false pid = "C9300-24P" @@ -43,5 +43,5 @@ resource "catalystcenter_device" "example" { Import is supported using the following syntax: ```shell -terraform import catalystcenter_device.example "4b0b7a80-44c0-4bf2-bab5-fc24b4e0a17e" +terraform import catalystcenter_pnp_device.example "4b0b7a80-44c0-4bf2-bab5-fc24b4e0a17e" ``` diff --git a/docs/resources/device_claim_site.md b/docs/resources/pnp_device_claim_site.md similarity index 86% rename from docs/resources/device_claim_site.md rename to docs/resources/pnp_device_claim_site.md index 745f1c2b..8f8894e2 100644 --- a/docs/resources/device_claim_site.md +++ b/docs/resources/pnp_device_claim_site.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "catalystcenter_device_claim_site Resource - terraform-provider-catalystcenter" +page_title: "catalystcenter_pnp_device_claim_site Resource - terraform-provider-catalystcenter" subcategory: "Plug and Play" description: |- - This resource can manage a Device Claim Site. + This resource can manage a PnP Device Claim Site. --- -# catalystcenter_device_claim_site (Resource) +# catalystcenter_pnp_device_claim_site (Resource) -This resource can manage a Device Claim Site. +This resource can manage a PnP Device Claim Site. ## Example Usage ```terraform -resource "catalystcenter_device_claim_site" "example" { +resource "catalystcenter_pnp_device_claim_site" "example" { device_id = "12345678-1234-1234-1234-123456789012" site_id = "12345678-1234-1234-1234-123456789012" type = "Default" diff --git a/examples/data-sources/catalystcenter_device/data-source.tf b/examples/data-sources/catalystcenter_pnp_device/data-source.tf similarity index 51% rename from examples/data-sources/catalystcenter_device/data-source.tf rename to examples/data-sources/catalystcenter_pnp_device/data-source.tf index 12983487..bcd4033e 100644 --- a/examples/data-sources/catalystcenter_device/data-source.tf +++ b/examples/data-sources/catalystcenter_pnp_device/data-source.tf @@ -1,3 +1,3 @@ -data "catalystcenter_device" "example" { +data "catalystcenter_pnp_device" "example" { id = "76d24097-41c4-4558-a4d0-a8c07ac08470" } diff --git a/examples/resources/catalystcenter_device/import.sh b/examples/resources/catalystcenter_device/import.sh deleted file mode 100644 index 502b9e27..00000000 --- a/examples/resources/catalystcenter_device/import.sh +++ /dev/null @@ -1 +0,0 @@ -terraform import catalystcenter_device.example "4b0b7a80-44c0-4bf2-bab5-fc24b4e0a17e" diff --git a/examples/resources/catalystcenter_pnp_device/import.sh b/examples/resources/catalystcenter_pnp_device/import.sh new file mode 100644 index 00000000..dc45bdbd --- /dev/null +++ b/examples/resources/catalystcenter_pnp_device/import.sh @@ -0,0 +1 @@ +terraform import catalystcenter_pnp_device.example "4b0b7a80-44c0-4bf2-bab5-fc24b4e0a17e" diff --git a/examples/resources/catalystcenter_device/resource.tf b/examples/resources/catalystcenter_pnp_device/resource.tf similarity index 70% rename from examples/resources/catalystcenter_device/resource.tf rename to examples/resources/catalystcenter_pnp_device/resource.tf index 863bf0cd..f34ec5e1 100644 --- a/examples/resources/catalystcenter_device/resource.tf +++ b/examples/resources/catalystcenter_pnp_device/resource.tf @@ -1,4 +1,4 @@ -resource "catalystcenter_device" "example" { +resource "catalystcenter_pnp_device" "example" { serial_number = "FOC12345678" stack = false pid = "C9300-24P" diff --git a/examples/resources/catalystcenter_device_claim_site/resource.tf b/examples/resources/catalystcenter_pnp_device_claim_site/resource.tf similarity index 82% rename from examples/resources/catalystcenter_device_claim_site/resource.tf rename to examples/resources/catalystcenter_pnp_device_claim_site/resource.tf index 4f1161bb..0edef08f 100644 --- a/examples/resources/catalystcenter_device_claim_site/resource.tf +++ b/examples/resources/catalystcenter_pnp_device_claim_site/resource.tf @@ -1,4 +1,4 @@ -resource "catalystcenter_device_claim_site" "example" { +resource "catalystcenter_pnp_device_claim_site" "example" { device_id = "12345678-1234-1234-1234-123456789012" site_id = "12345678-1234-1234-1234-123456789012" type = "Default" diff --git a/gen/definitions/device.yaml b/gen/definitions/pnp_device.yaml similarity index 97% rename from gen/definitions/device.yaml rename to gen/definitions/pnp_device.yaml index bbfca043..0fcd205d 100644 --- a/gen/definitions/device.yaml +++ b/gen/definitions/pnp_device.yaml @@ -1,5 +1,5 @@ --- -name: Device +name: PnP Device rest_endpoint: /dna/intent/api/v1/onboarding/pnp-device id_path: id doc_category: Plug and Play diff --git a/gen/definitions/device_claim_site.yaml b/gen/definitions/pnp_device_claim_site.yaml similarity index 99% rename from gen/definitions/device_claim_site.yaml rename to gen/definitions/pnp_device_claim_site.yaml index cb1b2d52..eb0abfea 100644 --- a/gen/definitions/device_claim_site.yaml +++ b/gen/definitions/pnp_device_claim_site.yaml @@ -1,5 +1,5 @@ --- -name: Device Claim Site +name: PnP Device Claim Site rest_endpoint: /dna/intent/api/v1/onboarding/pnp-device/site-claim no_data_source: true no_read: true diff --git a/internal/provider/data_source_catalystcenter_device.go b/internal/provider/data_source_catalystcenter_pnp_device.go similarity index 80% rename from internal/provider/data_source_catalystcenter_device.go rename to internal/provider/data_source_catalystcenter_pnp_device.go index 01c5ec95..338e5af4 100644 --- a/internal/provider/data_source_catalystcenter_device.go +++ b/internal/provider/data_source_catalystcenter_pnp_device.go @@ -40,26 +40,26 @@ import ( // Ensure the implementation satisfies the expected interfaces. var ( - _ datasource.DataSource = &DeviceDataSource{} - _ datasource.DataSourceWithConfigure = &DeviceDataSource{} + _ datasource.DataSource = &PnPDeviceDataSource{} + _ datasource.DataSourceWithConfigure = &PnPDeviceDataSource{} ) -func NewDeviceDataSource() datasource.DataSource { - return &DeviceDataSource{} +func NewPnPDeviceDataSource() datasource.DataSource { + return &PnPDeviceDataSource{} } -type DeviceDataSource struct { +type PnPDeviceDataSource struct { client *cc.Client } -func (d *DeviceDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_device" +func (d *PnPDeviceDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_pnp_device" } -func (d *DeviceDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *PnPDeviceDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { resp.Schema = schema.Schema{ // This description is used by the documentation generator and the language server. - MarkdownDescription: "This data source can read the Device.", + MarkdownDescription: "This data source can read the PnP Device.", Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -87,7 +87,7 @@ func (d *DeviceDataSource) Schema(ctx context.Context, req datasource.SchemaRequ }, } } -func (d *DeviceDataSource) ConfigValidators(ctx context.Context) []datasource.ConfigValidator { +func (d *PnPDeviceDataSource) ConfigValidators(ctx context.Context) []datasource.ConfigValidator { return []datasource.ConfigValidator{ datasourcevalidator.ExactlyOneOf( path.MatchRoot("id"), @@ -96,7 +96,7 @@ func (d *DeviceDataSource) ConfigValidators(ctx context.Context) []datasource.Co } } -func (d *DeviceDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { +func (d *PnPDeviceDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { if req.ProviderData == nil { return } @@ -107,8 +107,8 @@ func (d *DeviceDataSource) Configure(_ context.Context, req datasource.Configure //template:end model //template:begin read -func (d *DeviceDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - var config Device +func (d *PnPDeviceDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PnPDevice // Read config diags := req.Config.Get(ctx, &config) diff --git a/internal/provider/data_source_catalystcenter_device_test.go b/internal/provider/data_source_catalystcenter_pnp_device_test.go similarity index 78% rename from internal/provider/data_source_catalystcenter_device_test.go rename to internal/provider/data_source_catalystcenter_pnp_device_test.go index da028c57..0d6d7715 100644 --- a/internal/provider/data_source_catalystcenter_device_test.go +++ b/internal/provider/data_source_catalystcenter_pnp_device_test.go @@ -29,18 +29,18 @@ import ( //template:end imports //template:begin testAccDataSource -func TestAccDataSourceCcDevice(t *testing.T) { +func TestAccDataSourceCcPnPDevice(t *testing.T) { var checks []resource.TestCheckFunc - checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_device.test", "serial_number", "FOC12345678")) - checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_device.test", "stack", "false")) - checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_device.test", "pid", "C9300-24P")) - checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_device.test", "hostname", "switch1")) + checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_pnp_device.test", "serial_number", "FOC12345678")) + checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_pnp_device.test", "stack", "false")) + checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_pnp_device.test", "pid", "C9300-24P")) + checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_pnp_device.test", "hostname", "switch1")) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccDataSourceCcDeviceConfig(), + Config: testAccDataSourceCcPnPDeviceConfig(), Check: resource.ComposeTestCheckFunc(checks...), }, }, @@ -53,8 +53,8 @@ func TestAccDataSourceCcDevice(t *testing.T) { //template:end testPrerequisites //template:begin testAccDataSourceConfig -func testAccDataSourceCcDeviceConfig() string { - config := `resource "catalystcenter_device" "test" {` + "\n" +func testAccDataSourceCcPnPDeviceConfig() string { + config := `resource "catalystcenter_pnp_device" "test" {` + "\n" config += ` serial_number = "FOC12345678"` + "\n" config += ` stack = false` + "\n" config += ` pid = "C9300-24P"` + "\n" @@ -62,8 +62,8 @@ func testAccDataSourceCcDeviceConfig() string { config += `}` + "\n" config += ` - data "catalystcenter_device" "test" { - id = catalystcenter_device.test.id + data "catalystcenter_pnp_device" "test" { + id = catalystcenter_pnp_device.test.id } ` return config diff --git a/internal/provider/model_catalystcenter_device.go b/internal/provider/model_catalystcenter_pnp_device.go similarity index 91% rename from internal/provider/model_catalystcenter_device.go rename to internal/provider/model_catalystcenter_pnp_device.go index b1d4ec04..d0737a5c 100644 --- a/internal/provider/model_catalystcenter_device.go +++ b/internal/provider/model_catalystcenter_pnp_device.go @@ -31,7 +31,7 @@ import ( //template:end imports //template:begin types -type Device struct { +type PnPDevice struct { Id types.String `tfsdk:"id"` SerialNumber types.String `tfsdk:"serial_number"` Stack types.Bool `tfsdk:"stack"` @@ -42,14 +42,14 @@ type Device struct { //template:end types //template:begin getPath -func (data Device) getPath() string { +func (data PnPDevice) getPath() string { return "/dna/intent/api/v1/onboarding/pnp-device" } //template:end getPath //template:begin toBody -func (data Device) toBody(ctx context.Context, state Device) string { +func (data PnPDevice) toBody(ctx context.Context, state PnPDevice) string { body := "" if !data.SerialNumber.IsNull() { body, _ = sjson.Set(body, "deviceInfo.serialNumber", data.SerialNumber.ValueString()) @@ -69,7 +69,7 @@ func (data Device) toBody(ctx context.Context, state Device) string { //template:end toBody //template:begin fromBody -func (data *Device) fromBody(ctx context.Context, res gjson.Result) { +func (data *PnPDevice) fromBody(ctx context.Context, res gjson.Result) { if value := res.Get("deviceInfo.serialNumber"); value.Exists() { data.SerialNumber = types.StringValue(value.String()) } else { @@ -95,7 +95,7 @@ func (data *Device) fromBody(ctx context.Context, res gjson.Result) { //template:end fromBody //template:begin updateFromBody -func (data *Device) updateFromBody(ctx context.Context, res gjson.Result) { +func (data *PnPDevice) updateFromBody(ctx context.Context, res gjson.Result) { if value := res.Get("deviceInfo.serialNumber"); value.Exists() && !data.SerialNumber.IsNull() { data.SerialNumber = types.StringValue(value.String()) } else { diff --git a/internal/provider/model_catalystcenter_device_claim_site.go b/internal/provider/model_catalystcenter_pnp_device_claim_site.go similarity index 84% rename from internal/provider/model_catalystcenter_device_claim_site.go rename to internal/provider/model_catalystcenter_pnp_device_claim_site.go index 1accd85d..10b779f6 100644 --- a/internal/provider/model_catalystcenter_device_claim_site.go +++ b/internal/provider/model_catalystcenter_pnp_device_claim_site.go @@ -31,25 +31,25 @@ import ( //template:end imports //template:begin types -type DeviceClaimSite struct { - Id types.String `tfsdk:"id"` - DeviceId types.String `tfsdk:"device_id"` - SiteId types.String `tfsdk:"site_id"` - Type types.String `tfsdk:"type"` - ImageId types.String `tfsdk:"image_id"` - ImageSkip types.Bool `tfsdk:"image_skip"` - ConfigId types.String `tfsdk:"config_id"` - ConfigParameters []DeviceClaimSiteConfigParameters `tfsdk:"config_parameters"` - RfProfile types.String `tfsdk:"rf_profile"` - StaticIp types.String `tfsdk:"static_ip"` - SubnetMask types.String `tfsdk:"subnet_mask"` - Gateway types.String `tfsdk:"gateway"` - VlanId types.String `tfsdk:"vlan_id"` - IpInterfaceName types.String `tfsdk:"ip_interface_name"` - SensorProfile types.String `tfsdk:"sensor_profile"` +type PnPDeviceClaimSite struct { + Id types.String `tfsdk:"id"` + DeviceId types.String `tfsdk:"device_id"` + SiteId types.String `tfsdk:"site_id"` + Type types.String `tfsdk:"type"` + ImageId types.String `tfsdk:"image_id"` + ImageSkip types.Bool `tfsdk:"image_skip"` + ConfigId types.String `tfsdk:"config_id"` + ConfigParameters []PnPDeviceClaimSiteConfigParameters `tfsdk:"config_parameters"` + RfProfile types.String `tfsdk:"rf_profile"` + StaticIp types.String `tfsdk:"static_ip"` + SubnetMask types.String `tfsdk:"subnet_mask"` + Gateway types.String `tfsdk:"gateway"` + VlanId types.String `tfsdk:"vlan_id"` + IpInterfaceName types.String `tfsdk:"ip_interface_name"` + SensorProfile types.String `tfsdk:"sensor_profile"` } -type DeviceClaimSiteConfigParameters struct { +type PnPDeviceClaimSiteConfigParameters struct { Name types.String `tfsdk:"name"` Value types.String `tfsdk:"value"` } @@ -57,14 +57,14 @@ type DeviceClaimSiteConfigParameters struct { //template:end types //template:begin getPath -func (data DeviceClaimSite) getPath() string { +func (data PnPDeviceClaimSite) getPath() string { return "/dna/intent/api/v1/onboarding/pnp-device/site-claim" } //template:end getPath //template:begin toBody -func (data DeviceClaimSite) toBody(ctx context.Context, state DeviceClaimSite) string { +func (data PnPDeviceClaimSite) toBody(ctx context.Context, state PnPDeviceClaimSite) string { body := "" if !data.DeviceId.IsNull() { body, _ = sjson.Set(body, "deviceId", data.DeviceId.ValueString()) @@ -124,7 +124,7 @@ func (data DeviceClaimSite) toBody(ctx context.Context, state DeviceClaimSite) s //template:end toBody //template:begin fromBody -func (data *DeviceClaimSite) fromBody(ctx context.Context, res gjson.Result) { +func (data *PnPDeviceClaimSite) fromBody(ctx context.Context, res gjson.Result) { if value := res.Get("deviceId"); value.Exists() { data.DeviceId = types.StringValue(value.String()) } else { @@ -156,9 +156,9 @@ func (data *DeviceClaimSite) fromBody(ctx context.Context, res gjson.Result) { data.ConfigId = types.StringNull() } if value := res.Get("configInfo.configParameters"); value.Exists() { - data.ConfigParameters = make([]DeviceClaimSiteConfigParameters, 0) + data.ConfigParameters = make([]PnPDeviceClaimSiteConfigParameters, 0) value.ForEach(func(k, v gjson.Result) bool { - item := DeviceClaimSiteConfigParameters{} + item := PnPDeviceClaimSiteConfigParameters{} if cValue := v.Get("key"); cValue.Exists() { item.Name = types.StringValue(cValue.String()) } else { @@ -213,7 +213,7 @@ func (data *DeviceClaimSite) fromBody(ctx context.Context, res gjson.Result) { //template:end fromBody //template:begin updateFromBody -func (data *DeviceClaimSite) updateFromBody(ctx context.Context, res gjson.Result) { +func (data *PnPDeviceClaimSite) updateFromBody(ctx context.Context, res gjson.Result) { if value := res.Get("deviceId"); value.Exists() && !data.DeviceId.IsNull() { data.DeviceId = types.StringValue(value.String()) } else { diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 75fe6810..019a560a 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -249,14 +249,14 @@ func (p *CcProvider) Resources(ctx context.Context) []func() resource.Resource { NewCredentialsSNMPv2ReadResource, NewCredentialsSNMPv2WriteResource, NewCredentialsSNMPv3Resource, - NewDeviceResource, - NewDeviceClaimSiteResource, NewDeviceRoleResource, NewFloorResource, NewIPPoolResource, NewIPPoolReservationResource, NewNetworkResource, NewNetworkProfileResource, + NewPnPDeviceResource, + NewPnPDeviceClaimSiteResource, NewProjectResource, NewSPProfileResource, NewTemplateResource, @@ -274,12 +274,12 @@ func (p *CcProvider) DataSources(ctx context.Context) []func() datasource.DataSo NewCredentialsSNMPv2ReadDataSource, NewCredentialsSNMPv2WriteDataSource, NewCredentialsSNMPv3DataSource, - NewDeviceDataSource, NewFloorDataSource, NewIPPoolDataSource, NewIPPoolReservationDataSource, NewNetworkDataSource, NewNetworkProfileDataSource, + NewPnPDeviceDataSource, NewProjectDataSource, NewSPProfileDataSource, NewTemplateDataSource, diff --git a/internal/provider/resource_catalystcenter_device.go b/internal/provider/resource_catalystcenter_pnp_device.go similarity index 80% rename from internal/provider/resource_catalystcenter_device.go rename to internal/provider/resource_catalystcenter_pnp_device.go index eab69240..7c5e6f30 100644 --- a/internal/provider/resource_catalystcenter_device.go +++ b/internal/provider/resource_catalystcenter_pnp_device.go @@ -41,25 +41,25 @@ import ( //template:begin model // Ensure provider defined types fully satisfy framework interfaces -var _ resource.Resource = &DeviceResource{} -var _ resource.ResourceWithImportState = &DeviceResource{} +var _ resource.Resource = &PnPDeviceResource{} +var _ resource.ResourceWithImportState = &PnPDeviceResource{} -func NewDeviceResource() resource.Resource { - return &DeviceResource{} +func NewPnPDeviceResource() resource.Resource { + return &PnPDeviceResource{} } -type DeviceResource struct { +type PnPDeviceResource struct { client *cc.Client } -func (r *DeviceResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_device" +func (r *PnPDeviceResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_pnp_device" } -func (r *DeviceResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *PnPDeviceResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ // This description is used by the documentation generator and the language server. - MarkdownDescription: helpers.NewAttributeDescription("This resource can manage a Device.").String, + MarkdownDescription: helpers.NewAttributeDescription("This resource can manage a PnP Device.").String, Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -89,7 +89,7 @@ func (r *DeviceResource) Schema(ctx context.Context, req resource.SchemaRequest, } } -func (r *DeviceResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { +func (r *PnPDeviceResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { if req.ProviderData == nil { return } @@ -100,8 +100,8 @@ func (r *DeviceResource) Configure(_ context.Context, req resource.ConfigureRequ //template:end model //template:begin create -func (r *DeviceResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var plan Device +func (r *PnPDeviceResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PnPDevice // Read plan diags := req.Plan.Get(ctx, &plan) @@ -113,7 +113,7 @@ func (r *DeviceResource) Create(ctx context.Context, req resource.CreateRequest, tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Id.ValueString())) // Create object - body := plan.toBody(ctx, Device{}) + body := plan.toBody(ctx, PnPDevice{}) params := "" res, err := r.client.Post(plan.getPath()+params, body) @@ -132,8 +132,8 @@ func (r *DeviceResource) Create(ctx context.Context, req resource.CreateRequest, //template:end create //template:begin read -func (r *DeviceResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var state Device +func (r *PnPDeviceResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PnPDevice // Read state diags := req.State.Get(ctx, &state) @@ -166,8 +166,8 @@ func (r *DeviceResource) Read(ctx context.Context, req resource.ReadRequest, res //template:end read //template:begin update -func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var plan, state Device +func (r *PnPDeviceResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PnPDevice // Read plan diags := req.Plan.Get(ctx, &plan) @@ -201,8 +201,8 @@ func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest, //template:end update //template:begin delete -func (r *DeviceResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var state Device +func (r *PnPDeviceResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PnPDevice // Read state diags := req.State.Get(ctx, &state) @@ -226,7 +226,7 @@ func (r *DeviceResource) Delete(ctx context.Context, req resource.DeleteRequest, //template:end delete //template:begin import -func (r *DeviceResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *PnPDeviceResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } diff --git a/internal/provider/resource_catalystcenter_device_claim_site.go b/internal/provider/resource_catalystcenter_pnp_device_claim_site.go similarity index 85% rename from internal/provider/resource_catalystcenter_device_claim_site.go rename to internal/provider/resource_catalystcenter_pnp_device_claim_site.go index 60a9b7a3..cd097b35 100644 --- a/internal/provider/resource_catalystcenter_device_claim_site.go +++ b/internal/provider/resource_catalystcenter_pnp_device_claim_site.go @@ -41,24 +41,24 @@ import ( //template:begin model // Ensure provider defined types fully satisfy framework interfaces -var _ resource.Resource = &DeviceClaimSiteResource{} +var _ resource.Resource = &PnPDeviceClaimSiteResource{} -func NewDeviceClaimSiteResource() resource.Resource { - return &DeviceClaimSiteResource{} +func NewPnPDeviceClaimSiteResource() resource.Resource { + return &PnPDeviceClaimSiteResource{} } -type DeviceClaimSiteResource struct { +type PnPDeviceClaimSiteResource struct { client *cc.Client } -func (r *DeviceClaimSiteResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_device_claim_site" +func (r *PnPDeviceClaimSiteResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_pnp_device_claim_site" } -func (r *DeviceClaimSiteResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *PnPDeviceClaimSiteResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ // This description is used by the documentation generator and the language server. - MarkdownDescription: helpers.NewAttributeDescription("This resource can manage a Device Claim Site.").String, + MarkdownDescription: helpers.NewAttributeDescription("This resource can manage a PnP Device Claim Site.").String, Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -146,7 +146,7 @@ func (r *DeviceClaimSiteResource) Schema(ctx context.Context, req resource.Schem } } -func (r *DeviceClaimSiteResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { +func (r *PnPDeviceClaimSiteResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { if req.ProviderData == nil { return } @@ -157,8 +157,8 @@ func (r *DeviceClaimSiteResource) Configure(_ context.Context, req resource.Conf //template:end model //template:begin create -func (r *DeviceClaimSiteResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var plan DeviceClaimSite +func (r *PnPDeviceClaimSiteResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PnPDeviceClaimSite // Read plan diags := req.Plan.Get(ctx, &plan) @@ -170,7 +170,7 @@ func (r *DeviceClaimSiteResource) Create(ctx context.Context, req resource.Creat tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Id.ValueString())) // Create object - body := plan.toBody(ctx, DeviceClaimSite{}) + body := plan.toBody(ctx, PnPDeviceClaimSite{}) params := "" res, err := r.client.Post(plan.getPath()+params, body) @@ -189,8 +189,8 @@ func (r *DeviceClaimSiteResource) Create(ctx context.Context, req resource.Creat //template:end create //template:begin read -func (r *DeviceClaimSiteResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var state DeviceClaimSite +func (r *PnPDeviceClaimSiteResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PnPDeviceClaimSite // Read state diags := req.State.Get(ctx, &state) @@ -210,8 +210,8 @@ func (r *DeviceClaimSiteResource) Read(ctx context.Context, req resource.ReadReq //template:end read //template:begin update -func (r *DeviceClaimSiteResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var plan, state DeviceClaimSite +func (r *PnPDeviceClaimSiteResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PnPDeviceClaimSite // Read plan diags := req.Plan.Get(ctx, &plan) @@ -245,8 +245,8 @@ func (r *DeviceClaimSiteResource) Update(ctx context.Context, req resource.Updat //template:end update //template:begin delete -func (r *DeviceClaimSiteResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var state DeviceClaimSite +func (r *PnPDeviceClaimSiteResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PnPDeviceClaimSite // Read state diags := req.State.Get(ctx, &state) diff --git a/internal/provider/resource_catalystcenter_device_claim_site_test.go b/internal/provider/resource_catalystcenter_pnp_device_claim_site_test.go similarity index 74% rename from internal/provider/resource_catalystcenter_device_claim_site_test.go rename to internal/provider/resource_catalystcenter_pnp_device_claim_site_test.go index 9abd4e9f..8cc1b20b 100644 --- a/internal/provider/resource_catalystcenter_device_claim_site_test.go +++ b/internal/provider/resource_catalystcenter_pnp_device_claim_site_test.go @@ -30,27 +30,27 @@ import ( //template:end imports //template:begin testAcc -func TestAccCcDeviceClaimSite(t *testing.T) { +func TestAccCcPnPDeviceClaimSite(t *testing.T) { if os.Getenv("PNP") == "" { t.Skip("skipping test, set environment variable PNP") } var checks []resource.TestCheckFunc - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_device_claim_site.test", "device_id", "12345678-1234-1234-1234-123456789012")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_device_claim_site.test", "site_id", "12345678-1234-1234-1234-123456789012")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_device_claim_site.test", "type", "Default")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_device_claim_site.test", "image_id", "")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_device_claim_site.test", "image_skip", "true")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_device_claim_site.test", "config_id", "template1")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_device_claim_site.test", "config_parameters.0.name", "HOSTNAME")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_device_claim_site.test", "config_parameters.0.value", "switch1")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_pnp_device_claim_site.test", "device_id", "12345678-1234-1234-1234-123456789012")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_pnp_device_claim_site.test", "site_id", "12345678-1234-1234-1234-123456789012")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_pnp_device_claim_site.test", "type", "Default")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_pnp_device_claim_site.test", "image_id", "")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_pnp_device_claim_site.test", "image_skip", "true")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_pnp_device_claim_site.test", "config_id", "template1")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_pnp_device_claim_site.test", "config_parameters.0.name", "HOSTNAME")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_pnp_device_claim_site.test", "config_parameters.0.value", "switch1")) var steps []resource.TestStep steps = append(steps, resource.TestStep{ - Config: testAccCcDeviceClaimSiteConfig_all(), + Config: testAccCcPnPDeviceClaimSiteConfig_all(), Check: resource.ComposeTestCheckFunc(checks...), }) steps = append(steps, resource.TestStep{ - ResourceName: "catalystcenter_device_claim_site.test", + ResourceName: "catalystcenter_pnp_device_claim_site.test", ImportState: true, }) @@ -67,8 +67,8 @@ func TestAccCcDeviceClaimSite(t *testing.T) { //template:end testPrerequisites //template:begin testAccConfigMinimal -func testAccCcDeviceClaimSiteConfig_minimum() string { - config := `resource "catalystcenter_device_claim_site" "test" {` + "\n" +func testAccCcPnPDeviceClaimSiteConfig_minimum() string { + config := `resource "catalystcenter_pnp_device_claim_site" "test" {` + "\n" config += ` device_id = "12345678-1234-1234-1234-123456789012"` + "\n" config += ` site_id = "12345678-1234-1234-1234-123456789012"` + "\n" config += ` type = "Default"` + "\n" @@ -79,8 +79,8 @@ func testAccCcDeviceClaimSiteConfig_minimum() string { //template:end testAccConfigMinimal //template:begin testAccConfigAll -func testAccCcDeviceClaimSiteConfig_all() string { - config := `resource "catalystcenter_device_claim_site" "test" {` + "\n" +func testAccCcPnPDeviceClaimSiteConfig_all() string { + config := `resource "catalystcenter_pnp_device_claim_site" "test" {` + "\n" config += ` device_id = "12345678-1234-1234-1234-123456789012"` + "\n" config += ` site_id = "12345678-1234-1234-1234-123456789012"` + "\n" config += ` type = "Default"` + "\n" diff --git a/internal/provider/resource_catalystcenter_device_test.go b/internal/provider/resource_catalystcenter_pnp_device_test.go similarity index 79% rename from internal/provider/resource_catalystcenter_device_test.go rename to internal/provider/resource_catalystcenter_pnp_device_test.go index d2868e33..552c1155 100644 --- a/internal/provider/resource_catalystcenter_device_test.go +++ b/internal/provider/resource_catalystcenter_pnp_device_test.go @@ -30,25 +30,25 @@ import ( //template:end imports //template:begin testAcc -func TestAccCcDevice(t *testing.T) { +func TestAccCcPnPDevice(t *testing.T) { var checks []resource.TestCheckFunc - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_device.test", "serial_number", "FOC12345678")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_device.test", "stack", "false")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_device.test", "pid", "C9300-24P")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_device.test", "hostname", "switch1")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_pnp_device.test", "serial_number", "FOC12345678")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_pnp_device.test", "stack", "false")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_pnp_device.test", "pid", "C9300-24P")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_pnp_device.test", "hostname", "switch1")) var steps []resource.TestStep if os.Getenv("SKIP_MINIMUM_TEST") == "" { steps = append(steps, resource.TestStep{ - Config: testAccCcDeviceConfig_minimum(), + Config: testAccCcPnPDeviceConfig_minimum(), }) } steps = append(steps, resource.TestStep{ - Config: testAccCcDeviceConfig_all(), + Config: testAccCcPnPDeviceConfig_all(), Check: resource.ComposeTestCheckFunc(checks...), }) steps = append(steps, resource.TestStep{ - ResourceName: "catalystcenter_device.test", + ResourceName: "catalystcenter_pnp_device.test", ImportState: true, }) @@ -65,8 +65,8 @@ func TestAccCcDevice(t *testing.T) { //template:end testPrerequisites //template:begin testAccConfigMinimal -func testAccCcDeviceConfig_minimum() string { - config := `resource "catalystcenter_device" "test" {` + "\n" +func testAccCcPnPDeviceConfig_minimum() string { + config := `resource "catalystcenter_pnp_device" "test" {` + "\n" config += ` serial_number = "FOC12345678"` + "\n" config += ` pid = "C9300-24P"` + "\n" config += ` hostname = "switch1"` + "\n" @@ -77,8 +77,8 @@ func testAccCcDeviceConfig_minimum() string { //template:end testAccConfigMinimal //template:begin testAccConfigAll -func testAccCcDeviceConfig_all() string { - config := `resource "catalystcenter_device" "test" {` + "\n" +func testAccCcPnPDeviceConfig_all() string { + config := `resource "catalystcenter_pnp_device" "test" {` + "\n" config += ` serial_number = "FOC12345678"` + "\n" config += ` stack = false` + "\n" config += ` pid = "C9300-24P"` + "\n" diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 3fd46e65..7c8d0237 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -9,7 +9,9 @@ description: |- ## 0.1.3 (unreleased) -- Add `catalystcenter_device_role` resource +- Add `catalystcenter_device` resource +- BREAKING CHANGE: Rename `catalystcenter_device` resource and data source to `catalystcenter_pnp_device` +- BREAKING CHANGE: Rename `catalystcenter_device_claim_site` resource and data source to `catalystcenter_pnp_device_claim_site` ## 0.1.2