site24x7 / terraform-provider-site24x7

Terraform provider for Site24x7
MIT License
23 stars 36 forks source link

Data block not working for Credential Profile #298

Open kalyangitnew opened 3 months ago

kalyangitnew commented 3 months ago

data "site24x7_credential_profile" "s247credentialprofile" { // (Required) Regular expression denoting the name of the Credential Profile. name_regex = "url"

} I have tried and given name_regex as "null" as because all website monitors need credential profile getting error as below

Error as name_regex required field not set I have given but still it showing like this..

Then what we should give if we didn't need credential profile...

Please Help us quickly as we see many issues with site24x7 Terraform provider

kalyangitnew commented 3 months ago

Sometimes it getting oauth scope not support for api..after we still added all type of scopes with .All

Why it like this

If credential profile will work or not??? Why it showing like this

kalyangitnew commented 3 months ago

Sometimes it getting oauth scope not support for api..after we still added all type of scopes with .All

Why it like this

If credential profile will work or not??? Why it showing like this

Will credential profile data block works with null????

kalyangitnew commented 3 months ago

func DataSourceSite24x7CredentialProfile() *schema.Resource { return &schema.Resource{ Read: credentialProfileDataSourceRead, Schema: credentialProfileDataSourcceSchema, } }

// monitorDataSourceRead fetches all server monitors from Site24x7 func credentialProfileDataSourceRead(d *schema.ResourceData, meta interface{}) error { client := meta.(site24x7.Client)

    allWebCredentials, err := client.CredentialProfile().ListWebCredentials()
    if err != nil {
            return err
    }

    var genericCredentialProfile *api.CredentialProfile
    if nameRegex, ok := d.GetOk("name_regex"); ok {
            nameRegexPattern := regexp.MustCompile(nameRegex.(string))
            // nameRegexPattern := regexp.MustCompile("(?i)" + nameRegex.(string))
            for _, credentialProfile := range allWebCredentials {
                    if len(credentialProfile.CredentialName) > 0 {
                            if nameRegexPattern.MatchString(credentialProfile.CredentialName) {
                                    genericCredentialProfile = new(api.CredentialProfile)
                                    genericCredentialProfile.ID = credentialProfile.ID
                                    genericCredentialProfile.CredentialName = credentialProfile.CredentialName
                                    genericCredentialProfile.CredentialType = credentialProfile.CredentialType
                                    genericCredentialProfile.UserName = credentialProfile.UserName
                                    genericCredentialProfile.Password = credentialProfile.Password
                            }
                    }
            }
    }

    if genericCredentialProfile == nil {
            return errors.New("Unable to find monitor matching the name : \"" + d.Get("name_regex").(string))
    }

    updateResourceData(d, genericCredentialProfile)

    return nil

}

func updateResourceData(d schema.ResourceData, credentialProfile api.CredentialProfile) { d.SetId(credentialProfile.ID) d.Set("credential_name", credentialProfile.CredentialName) d.Set("credential_type", credentialProfile.CredentialType) d.Set("username", credentialProfile.UserName) d.Set("password", credentialProfile.Password) }

I guess it issue with getting credential profiles list still