From 200ccd3a3676b418cd6d2ee3ed4195b0162214b0 Mon Sep 17 00:00:00 2001 From: Lionel Hercot Date: Mon, 24 Jan 2022 00:39:39 +0100 Subject: [PATCH] Add support for aci_snmp_community a more generic version of aci_vrf_snmp_context_community and deprecate aci_vrf_snmp_context_community --- aci/data_source_aci_snmpcommunityp.go | 16 +- ...ta_source_aci_snmpcommunityp_deprecated.go | 50 +++++ aci/provider.go | 6 +- aci/resource_aci_fvctx.go | 3 +- aci/resource_aci_fvtenant.go | 1 - aci/resource_aci_snmpcommunityp.go | 38 +++- aci/resource_aci_snmpcommunityp_deprecated.go | 176 ++++++++++++++++++ aci/resource_aci_snmpcommunityp_test.go | 55 +++--- examples/aci_snmp_community/main.tf | 44 +++++ examples/vrf_snmp_context_community/main.tf | 40 ++-- .../d/login_domain_provider.html.markdown | 2 +- website/docs/d/snmp_community.html.markdown | 45 +++++ website/docs/r/snmp_community.html.markdown | 50 +++++ 13 files changed, 471 insertions(+), 55 deletions(-) create mode 100644 aci/data_source_aci_snmpcommunityp_deprecated.go create mode 100644 aci/resource_aci_snmpcommunityp_deprecated.go create mode 100644 examples/aci_snmp_community/main.tf create mode 100644 website/docs/d/snmp_community.html.markdown create mode 100644 website/docs/r/snmp_community.html.markdown diff --git a/aci/data_source_aci_snmpcommunityp.go b/aci/data_source_aci_snmpcommunityp.go index d0e38f65f..56d2470f8 100644 --- a/aci/data_source_aci_snmpcommunityp.go +++ b/aci/data_source_aci_snmpcommunityp.go @@ -5,16 +5,17 @@ import ( "fmt" "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceAciSNMPCommunity() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceAciSNMPCommunityReadContext, + ReadContext: dataSourceAciSNMPCommunityRead, SchemaVersion: 1, Schema: AppendBaseAttrSchema(AppendNameAliasAttrSchema(map[string]*schema.Schema{ - "vrf_snmp_context_dn": &schema.Schema{ + "parent_dn": &schema.Schema{ Type: schema.TypeString, Required: true, }, @@ -26,20 +27,23 @@ func dataSourceAciSNMPCommunity() *schema.Resource { } } -func dataSourceAciSNMPCommunityReadContext(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func dataSourceAciSNMPCommunityRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { aciClient := m.(*client.Client) name := d.Get("name").(string) - VRFSNMPCtxDn := d.Get("vrf_snmp_context_dn").(string) - rn := fmt.Sprintf("community-%s", name) - dn := fmt.Sprintf("%s/%s", VRFSNMPCtxDn, rn) + parentDn := d.Get("parent_dn").(string) + dn := fmt.Sprintf(models.DnsnmpCommunityP, parentDn, name) + snmpCommunityP, err := getRemoteSNMPCommunity(aciClient, dn) if err != nil { return diag.FromErr(err) } + d.SetId(dn) + _, err = setSNMPCommunityAttributes(snmpCommunityP, d) if err != nil { return diag.FromErr(err) } + return nil } diff --git a/aci/data_source_aci_snmpcommunityp_deprecated.go b/aci/data_source_aci_snmpcommunityp_deprecated.go new file mode 100644 index 000000000..7a5549780 --- /dev/null +++ b/aci/data_source_aci_snmpcommunityp_deprecated.go @@ -0,0 +1,50 @@ +package aci + +import ( + "context" + "fmt" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func dataSourceAciSNMPCommunityDeprecated() *schema.Resource { + return &schema.Resource{ + DeprecationMessage: "Use aci_snmp_community data source instead", + ReadContext: dataSourceAciSNMPCommunityReadDeprecated, + SchemaVersion: 1, + Schema: AppendBaseAttrSchema(AppendNameAliasAttrSchema(map[string]*schema.Schema{ + "vrf_snmp_context_dn": &schema.Schema{ + Type: schema.TypeString, + Required: true, + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + }, + })), + } +} + +func dataSourceAciSNMPCommunityReadDeprecated(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + aciClient := m.(*client.Client) + name := d.Get("name").(string) + parentDn := d.Get("vrf_snmp_context_dn").(string) + dn := fmt.Sprintf(models.DnsnmpCommunityP, parentDn, name) + + snmpCommunityP, err := getRemoteSNMPCommunity(aciClient, dn) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(dn) + + _, err = setSNMPCommunityAttributesDeprecated(snmpCommunityP, d) + if err != nil { + return diag.FromErr(err) + } + + return nil +} diff --git a/aci/provider.go b/aci/provider.go index 27e282f9c..9eda8c05f 100644 --- a/aci/provider.go +++ b/aci/provider.go @@ -247,7 +247,8 @@ func Provider() *schema.Provider { "aci_spine_switch_policy_group": resourceAciSpineSwitchPolicyGroup(), "aci_recurring_window": resourceAciRecurringWindow(), "aci_file_remote_path": resourceAciRemotePathofaFile(), - "aci_vrf_snmp_context_community": resourceAciSNMPCommunity(), + "aci_vrf_snmp_context_community": resourceAciSNMPCommunityDeprecated(), + "aci_snmp_community": resourceAciSNMPCommunity(), "aci_mgmt_zone": resourceAciManagedNodesZone(), "aci_vrf_snmp_context": resourceAciSNMPContextProfile(), "aci_endpoint_ip_aging_profile": resourceAciIPAgingPolicy(), @@ -460,7 +461,8 @@ func Provider() *schema.Provider { "aci_spine_switch_policy_group": dataSourceAciSpineSwitchPolicyGroup(), "aci_recurring_window": dataSourceAciRecurringWindow(), "aci_file_remote_path": dataSourceAciRemotePathofaFile(), - "aci_vrf_snmp_context_community": dataSourceAciSNMPCommunity(), + "aci_vrf_snmp_context_community": dataSourceAciSNMPCommunityDeprecated(), + "aci_snmp_community": dataSourceAciSNMPCommunity(), "aci_mgmt_zone": dataSourceAciManagedNodesZone(), "aci_vrf_snmp_context": dataSourceAciSNMPContextProfile(), "aci_endpoint_ip_aging_profile": dataSourceAciIPAgingPolicy(), diff --git a/aci/resource_aci_fvctx.go b/aci/resource_aci_fvctx.go index a4532888c..0cda03909 100644 --- a/aci/resource_aci_fvctx.go +++ b/aci/resource_aci_fvctx.go @@ -721,8 +721,7 @@ func resourceAciVRFRead(ctx context.Context, d *schema.ResourceData, m interface fvRsCtxMcastToData, err := aciClient.ReadRelationfvRsCtxMcastToFromVRF(dn) if err != nil { log.Printf("[DEBUG] Error while reading relation fvRsCtxMcastTo %v", err) - d.Set("relation_fv_rs_ctx_mcast_to", fvRsCtxMcastToData) - + setRelationAttribute(d, "relation_fv_rs_ctx_mcast_to", make([]interface{}, 0, 1)) } else { setRelationAttribute(d, "relation_fv_rs_ctx_mcast_to", toStringList(fvRsCtxMcastToData.(*schema.Set).List())) } diff --git a/aci/resource_aci_fvtenant.go b/aci/resource_aci_fvtenant.go index 8a10dd512..b7302646f 100644 --- a/aci/resource_aci_fvtenant.go +++ b/aci/resource_aci_fvtenant.go @@ -288,7 +288,6 @@ func resourceAciTenantRead(ctx context.Context, d *schema.ResourceData, m interf if err != nil { log.Printf("[DEBUG] Error while reading relation fvRsTnDenyRule %v", err) setRelationAttribute(d, "relation_fv_rs_tn_deny_rule", make([]interface{}, 0, 1)) - } else { setRelationAttribute(d, "relation_fv_rs_tn_deny_rule", toStringList(fvRsTnDenyRuleData.(*schema.Set).List())) } diff --git a/aci/resource_aci_snmpcommunityp.go b/aci/resource_aci_snmpcommunityp.go index f79fac1b9..134366d4d 100644 --- a/aci/resource_aci_snmpcommunityp.go +++ b/aci/resource_aci_snmpcommunityp.go @@ -24,7 +24,7 @@ func resourceAciSNMPCommunity() *schema.Resource { SchemaVersion: 1, Schema: AppendBaseAttrSchema(AppendNameAliasAttrSchema(map[string]*schema.Schema{ - "vrf_snmp_context_dn": &schema.Schema{ + "parent_dn": &schema.Schema{ Type: schema.TypeString, Required: true, ForceNew: true, @@ -44,24 +44,32 @@ func getRemoteSNMPCommunity(client *client.Client, dn string) (*models.SNMPCommu if err != nil { return nil, err } + snmpCommunityP := models.SNMPCommunityFromContainer(snmpCommunityPCont) if snmpCommunityP.DistinguishedName == "" { - return nil, fmt.Errorf("SNMPCommunity %s not found", snmpCommunityP.DistinguishedName) + return nil, fmt.Errorf("SNMP Community %s not found", snmpCommunityP.DistinguishedName) } + return snmpCommunityP, nil } func setSNMPCommunityAttributes(snmpCommunityP *models.SNMPCommunity, d *schema.ResourceData) (*schema.ResourceData, error) { + dn := d.Id() d.SetId(snmpCommunityP.DistinguishedName) d.Set("description", snmpCommunityP.Description) + if dn != snmpCommunityP.DistinguishedName { + d.Set("parent_dn", "") + } + snmpCommunityPMap, err := snmpCommunityP.ToMap() if err != nil { - return nil, err + return d, err } + d.Set("name", snmpCommunityPMap["name"]) d.Set("name_alias", snmpCommunityPMap["nameAlias"]) d.Set("annotation", snmpCommunityPMap["annotation"]) - d.Set("vrf_snmp_context_dn", GetParentDn(d.Id(), fmt.Sprintf("/community-%s", snmpCommunityPMap["name"]))) + d.Set("parent_dn", GetParentDn(d.Id(), fmt.Sprintf("/community-%s", snmpCommunityPMap["name"]))) return d, nil } @@ -70,14 +78,17 @@ func resourceAciSNMPCommunityImport(d *schema.ResourceData, m interface{}) ([]*s log.Printf("[DEBUG] %s: Beginning Import", d.Id()) aciClient := m.(*client.Client) dn := d.Id() + snmpCommunityP, err := getRemoteSNMPCommunity(aciClient, dn) if err != nil { return nil, err } + schemaFilled, err := setSNMPCommunityAttributes(snmpCommunityP, d) if err != nil { return nil, err } + log.Printf("[DEBUG] %s: Import finished successfully", d.Id()) return []*schema.ResourceData{schemaFilled}, nil } @@ -87,13 +98,15 @@ func resourceAciSNMPCommunityCreate(ctx context.Context, d *schema.ResourceData, aciClient := m.(*client.Client) desc := d.Get("description").(string) name := d.Get("name").(string) - VRFSNMPCtxDn := d.Get("vrf_snmp_context_dn").(string) + SNMPPolicyDn := d.Get("parent_dn").(string) snmpCommunityPAttr := models.SNMPCommunityAttributes{} + nameAlias := "" if NameAlias, ok := d.GetOk("name_alias"); ok { nameAlias = NameAlias.(string) } + if Annotation, ok := d.GetOk("annotation"); ok { snmpCommunityPAttr.Annotation = Annotation.(string) } else { @@ -103,7 +116,8 @@ func resourceAciSNMPCommunityCreate(ctx context.Context, d *schema.ResourceData, if Name, ok := d.GetOk("name"); ok { snmpCommunityPAttr.Name = Name.(string) } - snmpCommunityP := models.NewSNMPCommunity(fmt.Sprintf("community-%s", name), VRFSNMPCtxDn, desc, nameAlias, snmpCommunityPAttr) + + snmpCommunityP := models.NewSNMPCommunity(fmt.Sprintf(models.RnsnmpCommunityP, name), SNMPPolicyDn, desc, nameAlias, snmpCommunityPAttr) err := aciClient.Save(snmpCommunityP) if err != nil { @@ -120,8 +134,10 @@ func resourceAciSNMPCommunityUpdate(ctx context.Context, d *schema.ResourceData, aciClient := m.(*client.Client) desc := d.Get("description").(string) name := d.Get("name").(string) - VRFSNMPCtxDn := d.Get("vrf_snmp_context_dn").(string) + SNMPPolicyDn := d.Get("parent_dn").(string) + snmpCommunityPAttr := models.SNMPCommunityAttributes{} + nameAlias := "" if NameAlias, ok := d.GetOk("name_alias"); ok { nameAlias = NameAlias.(string) @@ -136,9 +152,11 @@ func resourceAciSNMPCommunityUpdate(ctx context.Context, d *schema.ResourceData, if Name, ok := d.GetOk("name"); ok { snmpCommunityPAttr.Name = Name.(string) } - snmpCommunityP := models.NewSNMPCommunity(fmt.Sprintf("community-%s", name), VRFSNMPCtxDn, desc, nameAlias, snmpCommunityPAttr) + + snmpCommunityP := models.NewSNMPCommunity(fmt.Sprintf("community-%s", name), SNMPPolicyDn, desc, nameAlias, snmpCommunityPAttr) snmpCommunityP.Status = "modified" + err := aciClient.Save(snmpCommunityP) if err != nil { return diag.FromErr(err) @@ -153,11 +171,13 @@ func resourceAciSNMPCommunityRead(ctx context.Context, d *schema.ResourceData, m log.Printf("[DEBUG] %s: Beginning Read", d.Id()) aciClient := m.(*client.Client) dn := d.Id() + snmpCommunityP, err := getRemoteSNMPCommunity(aciClient, dn) if err != nil { d.SetId("") return diag.FromErr(err) } + _, err = setSNMPCommunityAttributes(snmpCommunityP, d) if err != nil { d.SetId("") @@ -172,10 +192,12 @@ func resourceAciSNMPCommunityDelete(ctx context.Context, d *schema.ResourceData, log.Printf("[DEBUG] %s: Beginning Destroy", d.Id()) aciClient := m.(*client.Client) dn := d.Id() + err := aciClient.DeleteByDn(dn, "snmpCommunityP") if err != nil { return diag.FromErr(err) } + log.Printf("[DEBUG] %s: Destroy finished successfully", d.Id()) d.SetId("") return diag.FromErr(err) diff --git a/aci/resource_aci_snmpcommunityp_deprecated.go b/aci/resource_aci_snmpcommunityp_deprecated.go new file mode 100644 index 000000000..9219579c7 --- /dev/null +++ b/aci/resource_aci_snmpcommunityp_deprecated.go @@ -0,0 +1,176 @@ +package aci + +import ( + "context" + "fmt" + "log" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceAciSNMPCommunityDeprecated() *schema.Resource { + return &schema.Resource{ + DeprecationMessage: "Use aci_snmp_community resource instead", + CreateContext: resourceAciSNMPCommunityCreateDeprecated, + UpdateContext: resourceAciSNMPCommunityUpdateDeprecated, + ReadContext: resourceAciSNMPCommunityReadDeprecated, + DeleteContext: resourceAciSNMPCommunityDelete, + + Importer: &schema.ResourceImporter{ + State: resourceAciSNMPCommunityImport, + }, + + SchemaVersion: 1, + Schema: AppendBaseAttrSchema(AppendNameAliasAttrSchema(map[string]*schema.Schema{ + "vrf_snmp_context_dn": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateNameAttribute(), + }, + })), + } +} + +func setSNMPCommunityAttributesDeprecated(snmpCommunityP *models.SNMPCommunity, d *schema.ResourceData) (*schema.ResourceData, error) { + dn := d.Id() + d.SetId(snmpCommunityP.DistinguishedName) + d.Set("description", snmpCommunityP.Description) + if dn != snmpCommunityP.DistinguishedName { + d.Set("vrf_snmp_context_dn", "") + } + + snmpCommunityPMap, err := snmpCommunityP.ToMap() + if err != nil { + return d, err + } + + d.Set("name", snmpCommunityPMap["name"]) + d.Set("name_alias", snmpCommunityPMap["nameAlias"]) + d.Set("annotation", snmpCommunityPMap["annotation"]) + d.Set("vrf_snmp_context_dn", GetParentDn(d.Id(), fmt.Sprintf("/community-%s", snmpCommunityPMap["name"]))) + + return d, nil +} + +func resourceAciSNMPCommunityImportDeprecated(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { + log.Printf("[DEBUG] %s: Beginning Import", d.Id()) + aciClient := m.(*client.Client) + dn := d.Id() + + snmpCommunityP, err := getRemoteSNMPCommunity(aciClient, dn) + if err != nil { + return nil, err + } + + schemaFilled, err := setSNMPCommunityAttributesDeprecated(snmpCommunityP, d) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] %s: Import finished successfully", d.Id()) + return []*schema.ResourceData{schemaFilled}, nil +} + +func resourceAciSNMPCommunityCreateDeprecated(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Printf("[DEBUG] SNMPCommunity: Beginning Creation") + aciClient := m.(*client.Client) + desc := d.Get("description").(string) + name := d.Get("name").(string) + SNMPPolicyDn := d.Get("vrf_snmp_context_dn").(string) + + snmpCommunityPAttr := models.SNMPCommunityAttributes{} + + nameAlias := "" + if NameAlias, ok := d.GetOk("name_alias"); ok { + nameAlias = NameAlias.(string) + } + + if Annotation, ok := d.GetOk("annotation"); ok { + snmpCommunityPAttr.Annotation = Annotation.(string) + } else { + snmpCommunityPAttr.Annotation = "{}" + } + + if Name, ok := d.GetOk("name"); ok { + snmpCommunityPAttr.Name = Name.(string) + } + + snmpCommunityP := models.NewSNMPCommunity(fmt.Sprintf(models.RnsnmpCommunityP, name), SNMPPolicyDn, desc, nameAlias, snmpCommunityPAttr) + + err := aciClient.Save(snmpCommunityP) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(snmpCommunityP.DistinguishedName) + log.Printf("[DEBUG] %s: Creation finished successfully", d.Id()) + return resourceAciSNMPCommunityReadDeprecated(ctx, d, m) +} + +func resourceAciSNMPCommunityUpdateDeprecated(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Printf("[DEBUG] SNMPCommunity: Beginning Update") + aciClient := m.(*client.Client) + desc := d.Get("description").(string) + name := d.Get("name").(string) + SNMPPolicyDn := d.Get("vrf_snmp_context_dn").(string) + + snmpCommunityPAttr := models.SNMPCommunityAttributes{} + + nameAlias := "" + if NameAlias, ok := d.GetOk("name_alias"); ok { + nameAlias = NameAlias.(string) + } + + if Annotation, ok := d.GetOk("annotation"); ok { + snmpCommunityPAttr.Annotation = Annotation.(string) + } else { + snmpCommunityPAttr.Annotation = "{}" + } + + if Name, ok := d.GetOk("name"); ok { + snmpCommunityPAttr.Name = Name.(string) + } + + snmpCommunityP := models.NewSNMPCommunity(fmt.Sprintf("community-%s", name), SNMPPolicyDn, desc, nameAlias, snmpCommunityPAttr) + + snmpCommunityP.Status = "modified" + + err := aciClient.Save(snmpCommunityP) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(snmpCommunityP.DistinguishedName) + log.Printf("[DEBUG] %s: Update finished successfully", d.Id()) + return resourceAciSNMPCommunityReadDeprecated(ctx, d, m) +} + +func resourceAciSNMPCommunityReadDeprecated(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Printf("[DEBUG] %s: Beginning Read", d.Id()) + aciClient := m.(*client.Client) + dn := d.Id() + + snmpCommunityP, err := getRemoteSNMPCommunity(aciClient, dn) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + _, err = setSNMPCommunityAttributesDeprecated(snmpCommunityP, d) + if err != nil { + d.SetId("") + return nil + } + + log.Printf("[DEBUG] %s: Read finished successfully", d.Id()) + return nil +} diff --git a/aci/resource_aci_snmpcommunityp_test.go b/aci/resource_aci_snmpcommunityp_test.go index 053443599..684165e3e 100644 --- a/aci/resource_aci_snmpcommunityp_test.go +++ b/aci/resource_aci_snmpcommunityp_test.go @@ -12,6 +12,8 @@ import ( func TestAccAciSNMPCommunity_Basic(t *testing.T) { var snmp_community models.SNMPCommunity + snmp_pol_name := acctest.RandString(5) + snmp_community_p_name := acctest.RandString(5) description := "snmp_community created while acceptance testing" resource.Test(t, resource.TestCase{ @@ -20,10 +22,10 @@ func TestAccAciSNMPCommunity_Basic(t *testing.T) { CheckDestroy: testAccCheckAciSNMPCommunityDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckAciSNMPCommunityConfig_basic(description), + Config: testAccCheckAciSNMPCommunityConfig_basic(snmp_pol_name, snmp_community_p_name), Check: resource.ComposeTestCheckFunc( - testAccCheckAciSNMPCommunityExists("aci_vrf_snmp_context_community.foosnmp_community", &snmp_community), - testAccCheckAciSNMPCommunityAttributes(description, &snmp_community), + testAccCheckAciSNMPCommunityExists("aci_snmp_community.foosnmp_community", &snmp_community), + testAccCheckAciSNMPCommunityAttributes(snmp_pol_name, snmp_community_p_name, description, &snmp_community), ), }, }, @@ -32,6 +34,8 @@ func TestAccAciSNMPCommunity_Basic(t *testing.T) { func TestAccAciSNMPCommunity_Update(t *testing.T) { var snmp_community models.SNMPCommunity + snmp_pol_name := acctest.RandString(5) + snmp_community_p_name := acctest.RandString(5) description := "snmp_community created while acceptance testing" resource.Test(t, resource.TestCase{ @@ -40,34 +44,39 @@ func TestAccAciSNMPCommunity_Update(t *testing.T) { CheckDestroy: testAccCheckAciSNMPCommunityDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckAciSNMPCommunityConfig_basic(description), + Config: testAccCheckAciSNMPCommunityConfig_basic(snmp_pol_name, snmp_community_p_name), Check: resource.ComposeTestCheckFunc( - testAccCheckAciSNMPCommunityExists("aci_vrf_snmp_context_community.foosnmp_community", &snmp_community), - testAccCheckAciSNMPCommunityAttributes(description, &snmp_community), + testAccCheckAciSNMPCommunityExists("aci_snmp_community.foosnmp_community", &snmp_community), + testAccCheckAciSNMPCommunityAttributes(snmp_pol_name, snmp_community_p_name, description, &snmp_community), ), }, { - Config: testAccCheckAciSNMPCommunityConfig_basic(description), + Config: testAccCheckAciSNMPCommunityConfig_basic(snmp_pol_name, snmp_community_p_name), Check: resource.ComposeTestCheckFunc( - testAccCheckAciSNMPCommunityExists("aci_vrf_snmp_context_community.foosnmp_community", &snmp_community), - testAccCheckAciSNMPCommunityAttributes(description, &snmp_community), + testAccCheckAciSNMPCommunityExists("aci_snmp_community.foosnmp_community", &snmp_community), + testAccCheckAciSNMPCommunityAttributes(snmp_pol_name, snmp_community_p_name, description, &snmp_community), ), }, }, }) } -func testAccCheckAciSNMPCommunityConfig_basic(description string) string { +func testAccCheckAciSNMPCommunityConfig_basic(snmp_pol_name, snmp_community_p_name string) string { return fmt.Sprintf(` - resource "aci_vrf_snmp_context_community" "foosnmp_community" { - name = "test" - description = "%s" - vrf_snmp_context_dn = aci_vrf_snmp_context.test.id - annotation = "Test_Annotation" - name_alias = "Test_name_alias" + resource "aci_snmp_policy" "foosnmp_policy" { + name = "%s" + description = "snmp_policy created while acceptance testing" + + } + + resource "aci_snmp_community" "foosnmp_community" { + name = "%s" + description = "snmp_community created while acceptance testing" + parent_dn = aci_snmp_policy.foosnmp_policy.id } - `, description) + + `, snmp_pol_name, snmp_community_p_name) } func testAccCheckAciSNMPCommunityExists(name string, snmp_community *models.SNMPCommunity) resource.TestCheckFunc { @@ -101,7 +110,7 @@ func testAccCheckAciSNMPCommunityExists(name string, snmp_community *models.SNMP func testAccCheckAciSNMPCommunityDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*client.Client) for _, rs := range s.RootModule().Resources { - if rs.Type == "aci_vrf_snmp_context_community" { + if rs.Type == "aci_snmp_community" { cont, err := client.Get(rs.Primary.ID) snmp_community := models.SNMPCommunityFromContainer(cont) if err == nil { @@ -114,16 +123,18 @@ func testAccCheckAciSNMPCommunityDestroy(s *terraform.State) error { return nil } -func testAccCheckAciSNMPCommunityAttributes(description string, snmp_community *models.SNMPCommunity) resource.TestCheckFunc { +func testAccCheckAciSNMPCommunityAttributes(snmp_pol_name, snmp_community_p_name, description string, snmp_community *models.SNMPCommunity) resource.TestCheckFunc { return func(s *terraform.State) error { - if "test" != snmp_community.Name { - return fmt.Errorf("Bad snmp_community_p %s", snmp_community.Name) + if snmp_community_p_name != GetMOName(snmp_community.DistinguishedName) { + return fmt.Errorf("Bad snmp_community_p %s", GetMOName(snmp_community.DistinguishedName)) } + if snmp_pol_name != GetMOName(GetParentDn(snmp_community.DistinguishedName)) { + return fmt.Errorf(" Bad snmp_pol %s", GetMOName(GetParentDn(snmp_community.DistinguishedName))) + } if description != snmp_community.Description { return fmt.Errorf("Bad snmp_community Description %s", snmp_community.Description) } - if "Test_Annotation" != snmp_community.Annotation { return fmt.Errorf("Bad snmp_community Annotation %s", snmp_community.Annotation) } diff --git a/examples/aci_snmp_community/main.tf b/examples/aci_snmp_community/main.tf new file mode 100644 index 000000000..9dde9d598 --- /dev/null +++ b/examples/aci_snmp_community/main.tf @@ -0,0 +1,44 @@ +terraform { + required_providers { + aci = { + source = "ciscodevnet/aci" + } + } +} + +provider "aci" { + username = "" + password = "" + url = "" + insecure = true +} + +resource "aci_snmp_community" "public" { + parent_dn = "uni/fabric/snmppol-default" + name = "public" + description = "from terraform" + annotation = "aci_snmp_community" + name_alias = "example" +} + +resource "aci_snmp_community" "public_vrf" { + parent_dn = aci_vrf_snmp_context.example.id + name = "public" + description = "from terraform" + annotation = "aci_snmp_community" + name_alias = "example" +} + +resource "aci_vrf_snmp_context" "example" { + vrf_dn = aci_vrf.example.id + name = "example" +} + +resource "aci_tenant" "example" { + name = "tenant_snmp" +} + +resource "aci_vrf" "example" { + tenant_dn = aci_tenant.example.id + name = "vrf_example" +} diff --git a/examples/vrf_snmp_context_community/main.tf b/examples/vrf_snmp_context_community/main.tf index 6c55e0377..c7427b5f2 100644 --- a/examples/vrf_snmp_context_community/main.tf +++ b/examples/vrf_snmp_context_community/main.tf @@ -1,22 +1,36 @@ terraform { - required_providers { - aci = { - source = "ciscodevnet/aci" - } + required_providers { + aci = { + source = "ciscodevnet/aci" } + } } provider "aci" { - username = "" - password = "" - url = "" - insecure = true + username = "" + password = "" + url = "" + insecure = true } resource "aci_vrf_snmp_context_community" "example" { - vrf_snmp_context_dn = aci_vrf_snmp_context.test.id - name = "test" - description = "From Terraform" - annotation = "Test_Annotation" - name_alias = "Test_name_alias" + vrf_snmp_context_dn = aci_vrf_snmp_context.example.id + name = "test" + description = "From Terraform" + annotation = "Test_Annotation" + name_alias = "Test_name_alias" +} + +resource "aci_vrf_snmp_context" "example" { + vrf_dn = aci_vrf.example.id + name = "example" +} + +resource "aci_tenant" "example" { + name = "tenant_snmp" +} + +resource "aci_vrf" "example" { + tenant_dn = aci_tenant.example.id + name = "vrf_example" } diff --git a/website/docs/d/login_domain_provider.html.markdown b/website/docs/d/login_domain_provider.html.markdown index d0b9c7530..dd989b839 100644 --- a/website/docs/d/login_domain_provider.html.markdown +++ b/website/docs/d/login_domain_provider.html.markdown @@ -13,7 +13,7 @@ Data source for ACI Login Domain Provider ## API Information ## * `Class` - aaaProviderRef -* `Suppoerted Distinguished Names`
+* `Supported Distinguished Names`
[1] uni/userext/duoext/duoprovidergroup-{name}/providerref-{name}
[2] uni/userext/rsaext/rsaprovidergroup-{name}/providerref-{name}
[3] uni/userext/samlext/samlprovidergroup-{name}/providerref-{name}
diff --git a/website/docs/d/snmp_community.html.markdown b/website/docs/d/snmp_community.html.markdown new file mode 100644 index 000000000..abea642c5 --- /dev/null +++ b/website/docs/d/snmp_community.html.markdown @@ -0,0 +1,45 @@ +--- +subcategory: "" +layout: "aci" +page_title: "ACI: aci_snmp_community" +sidebar_current: "docs-aci-data-source-snmp_community" +description: |- + Data source for ACI SNMP Community +--- + +# aci_snmp_community # + +Data source for ACI SNMP Community + + +## API Information ## + +* `Class` - snmpCommunityP +* `Distinguished Name` - {parent_dn}/community-{name} + +## GUI Information ## + +* `Locations` +- Fabric > Fabric Policies > Policies > Pod > SNMP > {snmp_policy} > Community Policies +- Tenant > {tenant} > Networking > VRFs > {vrf} > SNMP Context > Community Policies + + + +## Example Usage ## + +```hcl +data "aci_snmp_community" "example" { + parent_dn = aci_snmp_policy.example.id + name = "example" +} +``` + +## Argument Reference ## + +* `parent_dn` - (Required) Distinguished name of the parent object. +* `name` - (Required) Name of object SNMP Community. + +## Attribute Reference ## +* `id` - Attribute id set to the Dn of the SNMP Community. +* `annotation` - (Optional) Annotation of the SNMP Community. +* `name_alias` - (Optional) Name Alias of the SNMP Community. diff --git a/website/docs/r/snmp_community.html.markdown b/website/docs/r/snmp_community.html.markdown new file mode 100644 index 000000000..b98a4d8cb --- /dev/null +++ b/website/docs/r/snmp_community.html.markdown @@ -0,0 +1,50 @@ +--- +subcategory: "" +layout: "aci" +page_title: "ACI: aci_snmp_community" +sidebar_current: "docs-aci-resource-snmp_community" +description: |- + Manages ACI SNMP Community +--- + +# aci_snmp_community # + +Manages ACI SNMP Community + +## API Information ## + +* `Class` - snmpCommunityP +* `Distinguished Name` - {parent_dn}/community-{name} + +## GUI Information ## + +* `Locations` +- Fabric > Fabric Policies > Policies > Pod > SNMP > {snmp_policy} > Community Policies +- Tenant > {tenant} > Networking > VRFs > {vrf} > SNMP Context > Community Policies + + +## Example Usage ## + +```hcl +resource "aci_snmp_community" "example" { + parent_dn = aci_snmp_policy.example.id + name = "example" +} +``` + +## Argument Reference ## + +* `parent_dn` - (Required) Distinguished name of the parent object. +* `name` - (Required) Name of the SNMP Community. +* `annotation` - (Optional) Annotation of the SNMP Community. +* `name_alias` - (Optional) Name Alias of the SNMP Community. + +## Importing ## + +An existing SNMPCommunity can be [imported][docs-import] into this resource via its Dn, via the following command: +[docs-import]: https://www.terraform.io/docs/import/index.html + + +``` +terraform import aci_snmp_community.example +``` \ No newline at end of file