Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraformer phase 2 updates #921

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions aci/base_attr_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,46 @@ package aci

import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

func GetBaseAttrSchema() map[string]*schema.Schema {
func GetAnnotationAttrSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"description": &schema.Schema{
"annotation": {
Type: schema.TypeString,
Optional: true,
Computed: true,
DefaultFunc: func() (interface{}, error) {
return "orchestrator:terraform", nil
},
},
"annotation": &schema.Schema{
}
}

func GetDescriptionAttrSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"description": {
Type: schema.TypeString,
Optional: true,
Computed: true,
DefaultFunc: func() (interface{}, error) {
return "orchestrator:terraform", nil
},
},
}
}

func GetAllowEmptyAttrSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"allow_empty_result": &schema.Schema{
"allow_empty_result": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
}
}

func GetBaseAttrSchema() map[string]*schema.Schema {
return AppendAttrSchemas(
GetAnnotationAttrSchema(),
GetDescriptionAttrSchema(),
)
}

// AppendBaseAttrSchema adds the BaseAttr to any schema
func AppendBaseAttrSchema(attrs map[string]*schema.Schema) map[string]*schema.Schema {
for key, value := range GetBaseAttrSchema() {
Expand Down
1 change: 1 addition & 0 deletions aci/resource_aci_aaaldapgroupmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func setLDAPGroupMapAttributes(aaaLdapGroupMap *models.LDAPGroupMap, d *schema.R
if err != nil {
return d, err
}
d.Set("annotation", aaaLdapGroupMapMap["annotation"])
d.Set("name", aaaLdapGroupMapMap["name"])
d.Set("name_alias", aaaLdapGroupMapMap["nameAlias"])
return d, nil
Expand Down
1 change: 1 addition & 0 deletions aci/resource_aci_aaaradiusprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func setRADIUSProviderAttributes(radius_type string, aaaRadiusProvider *models.R
d.Set("retries", aaaRadiusProviderMap["retries"])
d.Set("timeout", aaaRadiusProviderMap["timeout"])
d.Set("name_alias", aaaRadiusProviderMap["nameAlias"])
d.Set("annotation", aaaRadiusProviderMap["annotation"])
return d, nil
}

Expand Down
2 changes: 1 addition & 1 deletion aci/resource_aci_aaauserep.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func resourceAciUserManagementRead(ctx context.Context, d *schema.ResourceData,
aaaPwdProfileDn := dn + "/pwdprofile"
aaaPwdProfile, err := getRemotePasswordChangeExpirationPolicy(aciClient, aaaPwdProfileDn)
if err != nil {
return diag.FromErr(err)
return nil
}
_, err = setPasswordChangeExpirationPolicyAttributes(aaaPwdProfile, d)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion aci/resource_aci_aaauserrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func getRemoteUserRole(client *client.Client, dn string) (*models.UserRole, erro
func setUserRoleAttributes(aaaUserRole *models.UserRole, d *schema.ResourceData) (*schema.ResourceData, error) {
d.SetId(aaaUserRole.DistinguishedName)
d.Set("description", aaaUserRole.Description)

d.Set("annotation", aaaUserRole.Annotation)
aaaUserRoleMap, err := aaaUserRole.ToMap()
if err != nil {
return nil, err
Expand Down
57 changes: 28 additions & 29 deletions aci/resource_aci_bgpprotp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,35 @@ func resourceAciL3outBGPProtocolProfile() *schema.Resource {

SchemaVersion: 1,

Schema: map[string]*schema.Schema{
"logical_node_profile_dn": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Schema: AppendAttrSchemas(
GetAnnotationAttrSchema(),
map[string]*schema.Schema{
"logical_node_profile_dn": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"name_alias": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"relation_bgp_rs_best_path_ctrl_pol": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"relation_bgp_rs_bgp_node_ctx_pol": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
"name_alias": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"annotation": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "orchestrator:terraform",
},
"relation_bgp_rs_best_path_ctrl_pol": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"relation_bgp_rs_bgp_node_ctx_pol": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
),
}
}
func getRemoteL3outBGPProtocolProfile(client *client.Client, dn string) (*models.L3outBGPProtocolProfile, error) {
Expand Down
6 changes: 0 additions & 6 deletions aci/resource_aci_cloudrouterp.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ func resourceAciCloudVpnGateway() *schema.Resource {
ForceNew: true,
},

"annotation": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"name_alias": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down
6 changes: 0 additions & 6 deletions aci/resource_aci_dhcprelayp.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ func resourceAciDHCPRelayPolicy() *schema.Resource {
ForceNew: true,
},

"annotation": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"mode": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down
57 changes: 27 additions & 30 deletions aci/resource_aci_fabricexplicitgep.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,34 @@ func resourceAciVPCExplicitProtectionGroup() *schema.Resource {

SchemaVersion: 1,

Schema: map[string]*schema.Schema{

"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"switch1": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"switch2": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"vpc_domain_policy": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Schema: AppendAttrSchemas(
GetAnnotationAttrSchema(),
map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"switch1": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"switch2": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"vpc_domain_policy": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"vpc_explicit_protection_group_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
"annotation": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "orchestrator:terraform",
},
"vpc_explicit_protection_group_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
),
}
}

Expand Down
94 changes: 68 additions & 26 deletions aci/resource_aci_fabricrsoospath.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,32 @@ func resourceAciOutofServiceFabricPath() *schema.Resource {
},

SchemaVersion: 1,
Schema: AppendBaseAttrSchema(map[string]*schema.Schema{
"annotation": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Schema: AppendAttrSchemas(
GetAnnotationAttrSchema(),
map[string]*schema.Schema{

"pod_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
"node_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
"fex_id": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"interface": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
"pod_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
"node_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
"fex_id": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"interface": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
}),
),
}
}

Expand All @@ -73,6 +72,49 @@ func setOutofServiceFabricPathAttributes(fabricRsOosPath *models.OutofServiceFab
if err != nil {
return d, err
}
if fabricRsOosPath.TDn != "" {
interfaceRegEx := regexp.MustCompile(`topology/pod-([0-9]+?)/paths-([0-9]+?)/pathep-\[(.*?)\]`)
fexRegEx := regexp.MustCompile(`topology/pod-([0-9]+?)/paths-([0-9]+?)/extpaths-([0-9]+?)/pathep-\[(.*?)\]`)
matchInterface := interfaceRegEx.FindStringSubmatch(fabricRsOosPath.TDn)
if len(matchInterface) > 0 {
podId, err := strconv.Atoi(matchInterface[1])
if err != nil {
return nil, err
}
d.Set("pod_id", podId)

nodeId, err := strconv.Atoi(matchInterface[2])
if err != nil {
return nil, err
}
d.Set("node_id", nodeId)

d.Set("interface", matchInterface[3])
} else {
matchFex := fexRegEx.FindStringSubmatch(fabricRsOosPath.TDn)
if len(matchFex) > 0 {
podId, err := strconv.Atoi(matchFex[1])
if err != nil {
return nil, err
}
d.Set("pod_id", podId)

nodeId, err := strconv.Atoi(matchFex[2])
if err != nil {
return nil, err
}
d.Set("node_id", nodeId)

fexId, err := strconv.Atoi(matchFex[3])
if err != nil {
return nil, err
}
d.Set("fex_id", fexId)

d.Set("interface", matchFex[4])
}
}
}
d.Set("annotation", fabricRsOosPathMap["annotation"])
return d, nil
}
Expand Down
Loading