Skip to content

Commit

Permalink
[ignore] Added getBaseSiteResourceModel function to the nd_site resource
Browse files Browse the repository at this point in the history
  • Loading branch information
sajagana committed Aug 27, 2024
1 parent d3b4e16 commit d5770b5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func New(version string) func() provider.Provider {
// ndProvider is the provider implementation.
type ndProvider struct {
// version is set to the provider version on release, "dev" when the
// provider is built and ran locally, and "test" when running acceptance
// provider is built and run locally, and "test" when running acceptance
// testing.
version string
}
Expand Down
19 changes: 18 additions & 1 deletion internal/provider/resource_nd_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ type SiteResourceModel struct {
Longitude types.String `tfsdk:"longitude"`
}

func getBaseSiteResourceModel(username, password, login_domain string) *SiteResourceModel {
return &SiteResourceModel{
Id: basetypes.NewStringNull(),
SiteName: basetypes.NewStringNull(),
SitePassword: basetypes.NewStringValue(password),
SiteUsername: basetypes.NewStringValue(username),
LoginDomain: basetypes.NewStringValue(login_domain),
InbandEpg: basetypes.NewStringNull(),
Url: basetypes.NewStringNull(),
SiteType: basetypes.NewStringNull(),
Latitude: basetypes.NewStringNull(),
Longitude: basetypes.NewStringNull(),
}
}

func (r *SiteResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
tflog.Debug(ctx, "Start metadata of resource: nd_site")
resp.TypeName = req.ProviderTypeName + "_site"
Expand Down Expand Up @@ -428,6 +443,7 @@ func setSiteId(ctx context.Context, data *SiteResourceModel) {
func getAndSetSiteAttributes(ctx context.Context, diags *diag.Diagnostics, client *Client, data *SiteResourceModel) {

responseData := DoRestRequest(ctx, diags, client, fmt.Sprintf("%s/%s", sitePath, data.Id.ValueString()), "GET", nil)
*data = *getBaseSiteResourceModel(data.SiteUsername.ValueString(), data.SitePassword.ValueString(), data.LoginDomain.ValueString())

if diags.HasError() {
return
Expand All @@ -439,6 +455,7 @@ func getAndSetSiteAttributes(ctx context.Context, diags *diag.Diagnostics, clien
for attributeName, attributeValue := range specReadInfo {
if attributeName == "name" {
data.SiteName = basetypes.NewStringValue(attributeValue.(string))
data.Id = basetypes.NewStringValue(attributeValue.(string))
}

if attributeName == "siteConfig" {
Expand All @@ -463,7 +480,7 @@ func getAndSetSiteAttributes(ctx context.Context, diags *diag.Diagnostics, clien

if os.Getenv("ND_LOGIN_DOMAIN") != "" {
data.LoginDomain = basetypes.NewStringValue(os.Getenv("ND_LOGIN_DOMAIN"))
} else if attributeName == "loginDomain" && data.LoginDomain.IsUnknown() {
} else if attributeName == "loginDomain" {
data.LoginDomain = basetypes.NewStringValue(attributeValue.(string))
}
}
Expand Down
11 changes: 0 additions & 11 deletions internal/provider/resource_nd_site_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ func TestAccResourceNdSiteWithImportTest(t *testing.T) {
ResourceName: "nd_site.example_2",
ImportState: true,
ImportStateVerify: true,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("nd_site.example_2", "inband_epg", "test_epg"),
resource.TestCheckResourceAttr("nd_site.example_2", "latitude", ""),
resource.TestCheckResourceAttr("nd_site.example_2", "login_domain", "local"),
resource.TestCheckResourceAttr("nd_site.example_2", "longitude", ""),
resource.TestCheckResourceAttr("nd_site.example_2", "name", "example_2"),
resource.TestCheckResourceAttr("nd_site.example_2", "password", "password"),
resource.TestCheckResourceAttr("nd_site.example_2", "type", "aci"),
resource.TestCheckResourceAttr("nd_site.example_2", "username", "admin"),
resource.TestCheckResourceAttr("nd_site.example_2", "url", "10.195.219.155"),
),
},
// Update with full config and verify default ND values
{
Expand Down

0 comments on commit d5770b5

Please sign in to comment.