Skip to content

Commit

Permalink
[bugfix] Fix issue where state was deleted if credentials to APIC wer…
Browse files Browse the repository at this point in the history
…e incorrect (CiscoDevNet#1006)
  • Loading branch information
shrsr authored Feb 24, 2023
1 parent 1ab0cf5 commit 52b34b7
Show file tree
Hide file tree
Showing 228 changed files with 525 additions and 705 deletions.
5 changes: 2 additions & 3 deletions aci/resource_aci_aaa_domain_relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func getRemoteAaaDomainRelationship(client *client.Client, dn string) (*models.A
}
aaaDomainRef := models.AaaDomainRefFromContainer(aaaDomainRefCont)
if aaaDomainRef.DistinguishedName == "" {
return nil, fmt.Errorf("AaaDomainRef %s not found", aaaDomainRef.DistinguishedName)
return nil, fmt.Errorf("Aaa Domain Ref %s not found", dn)
}
return aaaDomainRef, nil
}
Expand Down Expand Up @@ -119,8 +119,7 @@ func resourceAciDomainRelationshipRead(ctx context.Context, d *schema.ResourceDa

aaaDomainRef, err := getRemoteAaaDomainRelationship(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}

_, err = setAaaDomainRelationshipAttributes(aaaDomainRef, d)
Expand Down
11 changes: 5 additions & 6 deletions aci/resource_aci_aaaauthrealm.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func getRemoteDefaultRadiusAuthenticationSettings(client *client.Client, dn stri
}
aaaPingEp := models.DefaultRadiusAuthenticationSettingsFromContainer(aaaPingEpCont)
if aaaPingEp.DistinguishedName == "" {
return nil, fmt.Errorf("DefaultRadiusAuthenticationSettings %s not found", aaaPingEp.DistinguishedName)
return nil, fmt.Errorf("Default Radius Authentication Settings %s not found", dn)
}
return aaaPingEp, nil
}
Expand All @@ -76,7 +76,7 @@ func getRemoteAAAAuthentication(client *client.Client, dn string) (*models.AAAAu
}
aaaAuthRealm := models.AAAAuthenticationFromContainer(aaaAuthRealmCont)
if aaaAuthRealm.DistinguishedName == "" {
return nil, fmt.Errorf("AAAAuthentication %s not found", aaaAuthRealm.DistinguishedName)
return nil, fmt.Errorf("AAA Authentication %s not found", dn)
}
return aaaAuthRealm, nil
}
Expand Down Expand Up @@ -244,12 +244,12 @@ func resourceAciAAAAuthenticationUpdate(ctx context.Context, d *schema.ResourceD

func resourceAciAAAAuthenticationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Printf("[DEBUG] %s: Beginning Read", d.Id())
dn := d.Id()
aciClient := m.(*client.Client)
dnauthrealm := "uni/userext/authrealm"
aaaAuthRealm, err := getRemoteAAAAuthentication(aciClient, dnauthrealm)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setAAAAuthenticationAttributes(aaaAuthRealm, d)
if err != nil {
Expand All @@ -259,8 +259,7 @@ func resourceAciAAAAuthenticationRead(ctx context.Context, d *schema.ResourceDat
dnpingep := "uni/userext/pingext"
aaaPingEp, err := getRemoteDefaultRadiusAuthenticationSettings(aciClient, dnpingep)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setDefaultRadiusAuthenticationSettingsAttributes(aaaPingEp, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaaconsoleauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func getRemoteConsoleAuthenticationMethod(client *client.Client, dn string) (*mo
}
aaaConsoleAuth := models.ConsoleAuthenticationMethodFromContainer(aaaConsoleAuthCont)
if aaaConsoleAuth.DistinguishedName == "" {
return nil, fmt.Errorf("ConsoleAuthenticationMethod %s not found", aaaConsoleAuth.DistinguishedName)
return nil, fmt.Errorf("Console Authentication Method %s not found", dn)
}
return aaaConsoleAuth, nil
}
Expand Down Expand Up @@ -181,8 +181,7 @@ func resourceAciConsoleAuthenticationMethodRead(ctx context.Context, d *schema.R
dn := d.Id()
aaaConsoleAuth, err := getRemoteConsoleAuthenticationMethod(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setConsoleAuthenticationMethodAttributes(aaaConsoleAuth, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaadefaultauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func getRemoteDefaultAuthenticationMethodforallLogins(client *client.Client, dn
}
aaaDefaultAuth := models.DefaultAuthenticationMethodforallLoginsFromContainer(aaaDefaultAuthCont)
if aaaDefaultAuth.DistinguishedName == "" {
return nil, fmt.Errorf("DefaultAuthenticationMethodforallLogins %s not found", aaaDefaultAuth.DistinguishedName)
return nil, fmt.Errorf("Default Authentication Method for all Logins %s not found", dn)
}
return aaaDefaultAuth, nil
}
Expand Down Expand Up @@ -205,8 +205,7 @@ func resourceAciDefaultAuthenticationMethodforallLoginsRead(ctx context.Context,
dn := d.Id()
aaaDefaultAuth, err := getRemoteDefaultAuthenticationMethodforallLogins(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setDefaultAuthenticationMethodforallLoginsAttributes(aaaDefaultAuth, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaadomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func getRemoteSecurityDomain(client *client.Client, dn string) (*models.Security
aaaDomain := models.SecurityDomainFromContainer(aaaDomainCont)

if aaaDomain.DistinguishedName == "" {
return nil, fmt.Errorf("SecurityDomain %s not found", aaaDomain.DistinguishedName)
return nil, fmt.Errorf("Security Domain %s not found", dn)
}

return aaaDomain, nil
Expand Down Expand Up @@ -163,8 +163,7 @@ func resourceAciSecurityDomainRead(ctx context.Context, d *schema.ResourceData,
aaaDomain, err := getRemoteSecurityDomain(aciClient, dn)

if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setSecurityDomainAttributes(aaaDomain, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaaduoprovidergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func getRemoteDuoProviderGroup(client *client.Client, dn string) (*models.DuoPro
}
aaaDuoProviderGroup := models.DuoProviderGroupFromContainer(aaaDuoProviderGroupCont)
if aaaDuoProviderGroup.DistinguishedName == "" {
return nil, fmt.Errorf("DuoProviderGroup %s not found", aaaDuoProviderGroup.DistinguishedName)
return nil, fmt.Errorf("Duo Provider Group %s not found", dn)
}
return aaaDuoProviderGroup, nil
}
Expand Down Expand Up @@ -253,8 +253,7 @@ func resourceAciDuoProviderGroupRead(ctx context.Context, d *schema.ResourceData
dn := d.Id()
aaaDuoProviderGroup, err := getRemoteDuoProviderGroup(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setDuoProviderGroupAttributes(aaaDuoProviderGroup, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaaldapgroupmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func getRemoteLDAPGroupMap(client *client.Client, dn string) (*models.LDAPGroupM
}
aaaLdapGroupMap := models.LDAPGroupMapFromContainer(aaaLdapGroupMapCont)
if aaaLdapGroupMap.DistinguishedName == "" {
return nil, fmt.Errorf("LDAPGroupMap %s not found", aaaLdapGroupMap.DistinguishedName)
return nil, fmt.Errorf("LDAP Group Map %s not found", dn)
}
return aaaLdapGroupMap, nil
}
Expand Down Expand Up @@ -154,8 +154,7 @@ func resourceAciLDAPGroupMapRead(ctx context.Context, d *schema.ResourceData, m
dn := d.Id()
aaaLdapGroupMap, err := getRemoteLDAPGroupMap(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setLDAPGroupMapAttributes(aaaLdapGroupMap, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaaldapgroupmaprule.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func getRemoteLDAPGroupMapRule(client *client.Client, dn string) (*models.LDAPGr
}
aaaLdapGroupMapRule := models.LDAPGroupMapRuleFromContainer(aaaLdapGroupMapRuleCont)
if aaaLdapGroupMapRule.DistinguishedName == "" {
return nil, fmt.Errorf("LDAPGroupMapRule %s not found", aaaLdapGroupMapRule.DistinguishedName)
return nil, fmt.Errorf("LDAP Group Map Rule %s not found", dn)
}
return aaaLdapGroupMapRule, nil
}
Expand Down Expand Up @@ -184,8 +184,7 @@ func resourceAciLDAPGroupMapRuleRead(ctx context.Context, d *schema.ResourceData
dn := d.Id()
aaaLdapGroupMapRule, err := getRemoteLDAPGroupMapRule(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
ldap_group_map_rule := strings.Split(dn, "/")

Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaaldapgroupmapruleref.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func getRemoteLDAPGroupMapruleref(client *client.Client, dn string) (*models.LDA
}
aaaLdapGroupMapRuleRef := models.LDAPGroupMaprulerefFromContainer(aaaLdapGroupMapRuleRefCont)
if aaaLdapGroupMapRuleRef.DistinguishedName == "" {
return nil, fmt.Errorf("LDAPGroupMapruleref %s not found", aaaLdapGroupMapRuleRef.DistinguishedName)
return nil, fmt.Errorf("LDAP Group Map Rule Ref %s not found", dn)
}
return aaaLdapGroupMapRuleRef, nil
}
Expand Down Expand Up @@ -153,8 +153,7 @@ func resourceAciLDAPGroupMaprulerefRead(ctx context.Context, d *schema.ResourceD
dn := d.Id()
aaaLdapGroupMapRuleRef, err := getRemoteLDAPGroupMapruleref(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setLDAPGroupMaprulerefAttributes(aaaLdapGroupMapRuleRef, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaaldapprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func getRemoteLDAPProvider(client *client.Client, dn string) (*models.LDAPProvid
}
aaaLdapProvider := models.LDAPProviderFromContainer(aaaLdapProviderCont)
if aaaLdapProvider.DistinguishedName == "" {
return nil, fmt.Errorf("LDAPProvider %s not found", aaaLdapProvider.DistinguishedName)
return nil, fmt.Errorf("LDAP Provider %s not found", dn)
}
return aaaLdapProvider, nil
}
Expand Down Expand Up @@ -460,8 +460,7 @@ func resourceAciLDAPProviderRead(ctx context.Context, d *schema.ResourceData, m
dn := d.Id()
aaaLdapProvider, err := getRemoteLDAPProvider(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}

ldap_provider_group := strings.Split(dn, "/")
Expand Down
10 changes: 4 additions & 6 deletions aci/resource_aci_aaalogindomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func getRemoteAuthenticationMethodfortheDomain(client *client.Client, dn string)
}
aaaDomainAuth := models.AuthenticationMethodfortheDomainFromContainer(aaaDomainAuthCont)
if aaaDomainAuth.DistinguishedName == "" {
return nil, fmt.Errorf("AuthenticationMethodfortheDomain %s not found", aaaDomainAuth.DistinguishedName)
return nil, fmt.Errorf("Authentication Method for the Domain %s not found", dn)
}
return aaaDomainAuth, nil
}
Expand All @@ -82,7 +82,7 @@ func getRemoteLoginDomain(client *client.Client, dn string) (*models.LoginDomain
}
aaaLoginDomain := models.LoginDomainFromContainer(aaaLoginDomainCont)
if aaaLoginDomain.DistinguishedName == "" {
return nil, fmt.Errorf("LoginDomain %s not found", aaaLoginDomain.DistinguishedName)
return nil, fmt.Errorf("Login Domain %s not found", dn)
}
return aaaLoginDomain, nil
}
Expand Down Expand Up @@ -244,8 +244,7 @@ func resourceAciLoginDomainRead(ctx context.Context, d *schema.ResourceData, m i
log.Printf("%s", childDn)
aaaLoginDomain, err := getRemoteLoginDomain(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setLoginDomainAttributes(aaaLoginDomain, d)
if err != nil {
Expand All @@ -255,8 +254,7 @@ func resourceAciLoginDomainRead(ctx context.Context, d *schema.ResourceData, m i

aaaDomainAuth, err := getRemoteAuthenticationMethodfortheDomain(aciClient, childDn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setAuthenticationMethodfortheDomainAttributes(aaaDomainAuth, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaaproviderref.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func getRemoteProviderGroupMember(client *client.Client, dn string) (*models.Pro
}
aaaProviderRef := models.ProviderGroupMemberFromContainer(aaaProviderRefCont)
if aaaProviderRef.DistinguishedName == "" {
return nil, fmt.Errorf("ProviderGroupMember %s not found", aaaProviderRef.DistinguishedName)
return nil, fmt.Errorf("Provider Group Member %s not found", dn)
}
return aaaProviderRef, nil
}
Expand Down Expand Up @@ -177,8 +177,7 @@ func resourceAciProviderGroupMemberRead(ctx context.Context, d *schema.ResourceD
dn := d.Id()
aaaProviderRef, err := getRemoteProviderGroupMember(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setProviderGroupMemberAttributes(aaaProviderRef, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaaradiusprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func getRemoteRADIUSProvider(client *client.Client, dn string) (*models.RADIUSPr
}
aaaRadiusProvider := models.RADIUSProviderFromContainer(aaaRadiusProviderCont)
if aaaRadiusProvider.DistinguishedName == "" {
return nil, fmt.Errorf("RADIUSProvider %s not found", aaaRadiusProvider.DistinguishedName)
return nil, fmt.Errorf("RADIUS Provider %s not found", dn)
}
return aaaRadiusProvider, nil
}
Expand Down Expand Up @@ -394,8 +394,7 @@ func resourceAciRADIUSProviderRead(ctx context.Context, d *schema.ResourceData,
dn := d.Id()
aaaRadiusProvider, err := getRemoteRADIUSProvider(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}

radius_provider_group := strings.Split(dn, "/")
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaaradiusprovidergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func getRemoteRADIUSProviderGroup(client *client.Client, dn string) (*models.RAD
}
aaaRadiusProviderGroup := models.RADIUSProviderGroupFromContainer(aaaRadiusProviderGroupCont)
if aaaRadiusProviderGroup.DistinguishedName == "" {
return nil, fmt.Errorf("RADIUSProviderGroup %s not found", aaaRadiusProviderGroup.DistinguishedName)
return nil, fmt.Errorf("RADIUS Provider Group %s not found", dn)
}
return aaaRadiusProviderGroup, nil
}
Expand Down Expand Up @@ -142,8 +142,7 @@ func resourceAciRADIUSProviderGroupRead(ctx context.Context, d *schema.ResourceD
dn := d.Id()
aaaRadiusProviderGroup, err := getRemoteRADIUSProviderGroup(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setRADIUSProviderGroupAttributes(aaaRadiusProviderGroup, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaarsaprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func getRemoteRSAProvider(client *client.Client, dn string) (*models.RSAProvider
}
aaaRsaProvider := models.RSAProviderFromContainer(aaaRsaProviderCont)
if aaaRsaProvider.DistinguishedName == "" {
return nil, fmt.Errorf("RSAProvider %s not found", aaaRsaProvider.DistinguishedName)
return nil, fmt.Errorf("RSA Provider %s not found", dn)
}
return aaaRsaProvider, nil
}
Expand Down Expand Up @@ -364,8 +364,7 @@ func resourceAciRSAProviderRead(ctx context.Context, d *schema.ResourceData, m i
dn := d.Id()
aaaRsaProvider, err := getRemoteRSAProvider(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setRSAProviderAttributes(aaaRsaProvider, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaasamlprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func getRemoteSAMLProvider(client *client.Client, dn string) (*models.SAMLProvid
}
aaaSamlProvider := models.SAMLProviderFromContainer(aaaSamlProviderCont)
if aaaSamlProvider.DistinguishedName == "" {
return nil, fmt.Errorf("SAMLProvider %s not found", aaaSamlProvider.DistinguishedName)
return nil, fmt.Errorf("SAML Provider %s not found", dn)
}
return aaaSamlProvider, nil
}
Expand Down Expand Up @@ -512,8 +512,7 @@ func resourceAciSAMLProviderRead(ctx context.Context, d *schema.ResourceData, m
dn := d.Id()
aaaSamlProvider, err := getRemoteSAMLProvider(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setSAMLProviderAttributes(aaaSamlProvider, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaasamlprovidergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func getRemoteSAMLProviderGroup(client *client.Client, dn string) (*models.SAMLP
}
aaaSamlProviderGroup := models.SAMLProviderGroupFromContainer(aaaSamlProviderGroupCont)
if aaaSamlProviderGroup.DistinguishedName == "" {
return nil, fmt.Errorf("SAMLProviderGroup %s not found", aaaSamlProviderGroup.DistinguishedName)
return nil, fmt.Errorf("SAML Provider Group %s not found", dn)
}
return aaaSamlProviderGroup, nil
}
Expand Down Expand Up @@ -141,8 +141,7 @@ func resourceAciSAMLProviderGroupRead(ctx context.Context, d *schema.ResourceDat
dn := d.Id()
aaaSamlProviderGroup, err := getRemoteSAMLProviderGroup(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setSAMLProviderGroupAttributes(aaaSamlProviderGroup, d)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions aci/resource_aci_aaatacacsplusprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func getRemoteTACACSProvider(client *client.Client, dn string) (*models.TACACSPr
}
aaaTacacsPlusProvider := models.TACACSProviderFromContainer(aaaTacacsPlusProviderCont)
if aaaTacacsPlusProvider.DistinguishedName == "" {
return nil, fmt.Errorf("TACACSProvider %s not found", aaaTacacsPlusProvider.DistinguishedName)
return nil, fmt.Errorf("TACACS Provider %s not found", dn)
}
return aaaTacacsPlusProvider, nil
}
Expand Down Expand Up @@ -363,8 +363,7 @@ func resourceAciTACACSProviderRead(ctx context.Context, d *schema.ResourceData,
dn := d.Id()
aaaTacacsPlusProvider, err := getRemoteTACACSProvider(aciClient, dn)
if err != nil {
d.SetId("")
return nil
return errorForObjectNotFound(err, dn, d)
}
_, err = setTACACSProviderAttributes(aaaTacacsPlusProvider, d)
if err != nil {
Expand Down
Loading

0 comments on commit 52b34b7

Please sign in to comment.