diff --git a/internal/provider/client.go b/internal/provider/client.go index da9402f..227f99e 100644 --- a/internal/provider/client.go +++ b/internal/provider/client.go @@ -70,10 +70,11 @@ type Device struct { // Organization represents a TowerOps organization. type Organization struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Slug string `json:"slug,omitempty"` - UseSites bool `json:"use_sites"` + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Slug string `json:"slug,omitempty"` + UseSites bool `json:"use_sites"` + SnmpCommunity string `json:"snmp_community,omitempty"` } // organizationResponse wraps the API response for organization endpoints. diff --git a/internal/provider/organization_resource.go b/internal/provider/organization_resource.go index 0f95777..70c0d05 100644 --- a/internal/provider/organization_resource.go +++ b/internal/provider/organization_resource.go @@ -20,10 +20,11 @@ type OrganizationResource struct { // OrganizationResourceModel describes the resource data model. type OrganizationResourceModel struct { - ID types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` - Slug types.String `tfsdk:"slug"` - UseSites types.Bool `tfsdk:"use_sites"` + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Slug types.String `tfsdk:"slug"` + UseSites types.Bool `tfsdk:"use_sites"` + SnmpCommunity types.String `tfsdk:"snmp_community"` } // NewOrganizationResource creates a new organization resource. @@ -59,6 +60,11 @@ func (r *OrganizationResource) Schema(ctx context.Context, req resource.SchemaRe Description: "Whether the organization uses sites to group devices. When true, devices are organized under sites. When false, devices belong directly to the organization.", Required: true, }, + "snmp_community": schema.StringAttribute{ + Description: "Default SNMP community string for devices. Can only be set by organization owners.", + Optional: true, + Sensitive: true, + }, }, } } @@ -97,6 +103,11 @@ func (r *OrganizationResource) Create(ctx context.Context, req resource.CreateRe org.Name = data.Name.ValueString() } + // Include SNMP community if provided + if !data.SnmpCommunity.IsNull() && !data.SnmpCommunity.IsUnknown() { + org.SnmpCommunity = data.SnmpCommunity.ValueString() + } + updated, err := r.client.UpdateOrganization(org) if err != nil { resp.Diagnostics.AddError("Failed to update organization", err.Error()) @@ -107,6 +118,7 @@ func (r *OrganizationResource) Create(ctx context.Context, req resource.CreateRe data.Name = types.StringValue(updated.Name) data.Slug = types.StringValue(updated.Slug) data.UseSites = types.BoolValue(updated.UseSites) + data.SnmpCommunity = types.StringValue(updated.SnmpCommunity) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } @@ -150,6 +162,11 @@ func (r *OrganizationResource) Update(ctx context.Context, req resource.UpdateRe org.Name = data.Name.ValueString() } + // Include SNMP community if provided + if !data.SnmpCommunity.IsNull() && !data.SnmpCommunity.IsUnknown() { + org.SnmpCommunity = data.SnmpCommunity.ValueString() + } + updated, err := r.client.UpdateOrganization(org) if err != nil { resp.Diagnostics.AddError("Failed to update organization", err.Error()) @@ -160,6 +177,7 @@ func (r *OrganizationResource) Update(ctx context.Context, req resource.UpdateRe data.Name = types.StringValue(updated.Name) data.Slug = types.StringValue(updated.Slug) data.UseSites = types.BoolValue(updated.UseSites) + data.SnmpCommunity = types.StringValue(updated.SnmpCommunity) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }