-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: maniputale TF stae based on FMC job history
- Loading branch information
1 parent
f9cc402
commit 27c727d
Showing
9 changed files
with
437 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "fmc_deployment" "example" { | ||
id = "76d24097-41c4-4558-a4d0-a8c07ac08470" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
resource "fmc_deployment" "example" { | ||
version = "1457566762351" | ||
device_list = ["d94f7ada-d141-11e5-acf3-c41f7e67fb1b"] | ||
device_list = ["2fe9063e-8bd5-11ef-9475-e4aeac78cf37"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// Copyright © 2023 Cisco Systems, Inc. and its affiliates. | ||
// All rights reserved. | ||
// | ||
// Licensed under the Mozilla Public License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://mozilla.org/MPL/2.0/ | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package provider | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin imports | ||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
"github.com/netascode/go-fmc" | ||
) | ||
|
||
// End of section. //template:end imports | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin model | ||
|
||
// Ensure the implementation satisfies the expected interfaces. | ||
var ( | ||
_ datasource.DataSource = &DeploymentDataSource{} | ||
_ datasource.DataSourceWithConfigure = &DeploymentDataSource{} | ||
) | ||
|
||
func NewDeploymentDataSource() datasource.DataSource { | ||
return &DeploymentDataSource{} | ||
} | ||
|
||
type DeploymentDataSource struct { | ||
client *fmc.Client | ||
} | ||
|
||
func (d *DeploymentDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_deployment" | ||
} | ||
|
||
func (d *DeploymentDataSource) 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 Deployment.", | ||
|
||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
MarkdownDescription: "The id of the object", | ||
Required: true, | ||
}, | ||
"domain": schema.StringAttribute{ | ||
MarkdownDescription: "The name of the FMC domain", | ||
Optional: true, | ||
}, | ||
"version": schema.StringAttribute{ | ||
MarkdownDescription: "Epoch unix time stamp (13 digits).", | ||
Computed: true, | ||
}, | ||
"force_deploy": schema.BoolAttribute{ | ||
MarkdownDescription: "Force deployment (even if there are no configuration changes).", | ||
Computed: true, | ||
}, | ||
"ignore_warning": schema.BoolAttribute{ | ||
MarkdownDescription: "Ignore warnings during deployment.", | ||
Computed: true, | ||
}, | ||
"device_list": schema.SetAttribute{ | ||
MarkdownDescription: "List of device ids to be deployed.", | ||
ElementType: types.StringType, | ||
Computed: true, | ||
}, | ||
"deployment_note": schema.StringAttribute{ | ||
MarkdownDescription: "User note related to deployment.", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *DeploymentDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
d.client = req.ProviderData.(*FmcProviderData).Client | ||
} | ||
|
||
// End of section. //template:end model | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin read | ||
|
||
func (d *DeploymentDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var config Deployment | ||
|
||
// Read config | ||
diags := req.Config.Get(ctx, &config) | ||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
// Set request domain if provided | ||
reqMods := [](func(*fmc.Req)){} | ||
if !config.Domain.IsNull() && config.Domain.ValueString() != "" { | ||
reqMods = append(reqMods, fmc.DomainName(config.Domain.ValueString())) | ||
} | ||
|
||
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) | ||
urlPath := config.getPath() + "/" + url.QueryEscape(config.Id.ValueString()) | ||
res, err := d.client.Get(urlPath, reqMods...) | ||
if err != nil { | ||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) | ||
return | ||
} | ||
|
||
config.fromBody(ctx, res) | ||
|
||
tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Id.ValueString())) | ||
|
||
diags = resp.State.Set(ctx, &config) | ||
resp.Diagnostics.Append(diags...) | ||
} | ||
|
||
// End of section. //template:end read |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright © 2023 Cisco Systems, Inc. and its affiliates. | ||
// All rights reserved. | ||
// | ||
// Licensed under the Mozilla Public License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://mozilla.org/MPL/2.0/ | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package provider | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin imports | ||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
// End of section. //template:end imports | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSource | ||
|
||
func TestAccDataSourceFmcDeployment(t *testing.T) { | ||
if os.Getenv("TF_VAR_timestamp") == "" && os.Getenv("TF_VAR_device_id_list") == "" { | ||
t.Skip("skipping test, set environment variable TF_VAR_timestamp or TF_VAR_device_id_list") | ||
} | ||
var checks []resource.TestCheckFunc | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceFmcDeploymentPrerequisitesConfig + testAccDataSourceFmcDeploymentConfig(), | ||
Check: resource.ComposeTestCheckFunc(checks...), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
// End of section. //template:end testAccDataSource | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites | ||
|
||
const testAccDataSourceFmcDeploymentPrerequisitesConfig = ` | ||
variable "timestamp" { default = null } // tests will set $TF_VAR_timestamp | ||
variable "device_id_list" { // tests will set $TF_VAR_device_id_list | ||
type = list(string) | ||
default = null | ||
} | ||
` | ||
|
||
// End of section. //template:end testPrerequisites | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig | ||
|
||
func testAccDataSourceFmcDeploymentConfig() string { | ||
config := `resource "fmc_deployment" "test" {` + "\n" | ||
config += ` version = var.timestamp` + "\n" | ||
config += ` ignore_warning = true` + "\n" | ||
config += ` device_list = var.device_id_list` + "\n" | ||
config += `}` + "\n" | ||
|
||
config += ` | ||
data "fmc_deployment" "test" { | ||
id = fmc_deployment.test.id | ||
} | ||
` | ||
return config | ||
} | ||
|
||
// End of section. //template:end testAccDataSourceConfig |
Oops, something went wrong.