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

Data block not working for Credential Profile #298

Open
kalyangitnew opened this issue Jul 26, 2024 · 3 comments
Open

Data block not working for Credential Profile #298

kalyangitnew opened this issue Jul 26, 2024 · 3 comments

Comments

@kalyangitnew
Copy link

kalyangitnew commented Jul 26, 2024

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
Copy link
Author

kalyangitnew commented Jul 26, 2024

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
Copy link
Author

kalyangitnew commented Jul 26, 2024

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant