本文整理汇总了Golang中github.com/xanzy/terraform-api/helper/schema.ResourceData类的典型用法代码示例。如果您正苦于以下问题:Golang ResourceData类的具体用法?Golang ResourceData怎么用?Golang ResourceData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResourceData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: resourceVcdVAppDelete
func resourceVcdVAppDelete(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*VCDClient)
vapp, err := vcdClient.OrgVdc.FindVAppByName(d.Id())
if err != nil {
return fmt.Errorf("error finding vapp: %s", err)
}
if err != nil {
return fmt.Errorf("Error getting VApp status: %#v", err)
}
_ = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.Undeploy()
if err != nil {
return fmt.Errorf("Error undeploying: %#v", err)
}
return task.WaitTaskCompletion()
})
err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.Delete()
if err != nil {
return fmt.Errorf("Error deleting: %#v", err)
}
return task.WaitTaskCompletion()
})
return err
}
示例2: resourceAzureAffinityGroupRead
// resourceAzureAffinityGroupRead does all the necessary API calls to
// read the state of the affinity group off Azure.
func resourceAzureAffinityGroupRead(d *schema.ResourceData, meta interface{}) error {
affinityGroupClient := meta.(*Client).affinityGroupClient
log.Println("[INFO] Issuing Azure Affinity Group list request.")
affinityGroups, err := affinityGroupClient.ListAffinityGroups()
if err != nil {
return fmt.Errorf("Error obtaining Affinity Group list off Azure: %s", err)
}
var found bool
name := d.Get("name").(string)
for _, group := range affinityGroups.AffinityGroups {
if group.Name == name {
found = true
d.Set("location", group.Location)
d.Set("label", group.Label)
d.Set("description", group.Description)
break
}
}
if !found {
// it means the affinity group has been deleted in the meantime, so we
// must stop tracking it:
d.SetId("")
}
return nil
}
示例3: resourceHerokuAddonCreate
func resourceHerokuAddonCreate(d *schema.ResourceData, meta interface{}) error {
addonLock.Lock()
defer addonLock.Unlock()
client := meta.(*heroku.Service)
app := d.Get("app").(string)
opts := heroku.AddonCreateOpts{Plan: d.Get("plan").(string)}
if v := d.Get("config"); v != nil {
config := make(map[string]string)
for _, v := range v.([]interface{}) {
for k, v := range v.(map[string]interface{}) {
config[k] = v.(string)
}
}
opts.Config = &config
}
log.Printf("[DEBUG] Addon create configuration: %#v, %#v", app, opts)
a, err := client.AddonCreate(app, opts)
if err != nil {
return err
}
d.SetId(a.ID)
log.Printf("[INFO] Addon ID: %s", d.Id())
return resourceHerokuAddonRead(d, meta)
}
示例4: roleFromResourceData
func roleFromResourceData(d *schema.ResourceData) (*chefc.Role, error) {
role := &chefc.Role{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
ChefType: "role",
}
var err error
err = json.Unmarshal(
[]byte(d.Get("default_attributes_json").(string)),
&role.DefaultAttributes,
)
if err != nil {
return nil, fmt.Errorf("default_attributes_json: %s", err)
}
err = json.Unmarshal(
[]byte(d.Get("override_attributes_json").(string)),
&role.OverrideAttributes,
)
if err != nil {
return nil, fmt.Errorf("override_attributes_json: %s", err)
}
runListI := d.Get("run_list").([]interface{})
role.RunList = make([]string, len(runListI))
for i, vI := range runListI {
role.RunList[i] = vI.(string)
}
return role, nil
}
示例5: resourceAWSEbsVolumeUpdate
func resourceAWSEbsVolumeUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
if _, ok := d.GetOk("tags"); ok {
setTags(conn, d)
}
return resourceAwsEbsVolumeRead(d, meta)
}
示例6: resourceAwsKinesisStreamDelete
func resourceAwsKinesisStreamDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).kinesisconn
sn := d.Get("name").(string)
_, err := conn.DeleteStream(&kinesis.DeleteStreamInput{
StreamName: aws.String(sn),
})
if err != nil {
return err
}
stateConf := &resource.StateChangeConf{
Pending: []string{"DELETING"},
Target: "DESTROYED",
Refresh: streamStateRefreshFunc(conn, sn),
Timeout: 5 * time.Minute,
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
_, err = stateConf.WaitForState()
if err != nil {
return fmt.Errorf(
"Error waiting for Stream (%s) to be destroyed: %s",
sn, err)
}
d.SetId("")
return nil
}
示例7: getNetworkName
func getNetworkName(d *schema.ResourceData, meta interface{}, networkID string) (string, error) {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
if err != nil {
return "", fmt.Errorf("Error creating OpenStack network client: %s", err)
}
opts := networks.ListOpts{ID: networkID}
pager := networks.List(networkingClient, opts)
networkName := ""
err = pager.EachPage(func(page pagination.Page) (bool, error) {
networkList, err := networks.ExtractNetworks(page)
if err != nil {
return false, err
}
for _, n := range networkList {
if n.ID == networkID {
networkName = n.Name
return false, nil
}
}
return true, nil
})
return networkName, err
}
示例8: resourceVcdNetworkDelete
func resourceVcdNetworkDelete(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*VCDClient)
vcdClient.Mutex.Lock()
defer vcdClient.Mutex.Unlock()
err := vcdClient.OrgVdc.Refresh()
if err != nil {
return fmt.Errorf("Error refreshing vdc: %#v", err)
}
network, err := vcdClient.OrgVdc.FindVDCNetwork(d.Id())
if err != nil {
return fmt.Errorf("Error finding network: %#v", err)
}
err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := network.Delete()
if err != nil {
return fmt.Errorf("Error Deleting Network: %#v", err)
}
return task.WaitTaskCompletion()
})
if err != nil {
return err
}
return nil
}
示例9: resourceAwsOpsworksSetStackCustomCookbooksSource
func resourceAwsOpsworksSetStackCustomCookbooksSource(d *schema.ResourceData, v *opsworks.Source) {
nv := make([]interface{}, 0, 1)
if v != nil {
m := make(map[string]interface{})
if v.Type != nil {
m["type"] = *v.Type
}
if v.Url != nil {
m["url"] = *v.Url
}
if v.Username != nil {
m["username"] = *v.Username
}
if v.Password != nil {
m["password"] = *v.Password
}
if v.Revision != nil {
m["revision"] = *v.Revision
}
nv = append(nv, m)
}
err := d.Set("custom_cookbooks_source", nv)
if err != nil {
// should never happen
panic(err)
}
}
示例10: resourceAwsIamRoleDelete
func resourceAwsIamRoleDelete(d *schema.ResourceData, meta interface{}) error {
iamconn := meta.(*AWSClient).iamconn
// Roles cannot be destroyed when attached to an existing Instance Profile
resp, err := iamconn.ListInstanceProfilesForRole(&iam.ListInstanceProfilesForRoleInput{
RoleName: aws.String(d.Id()),
})
if err != nil {
return fmt.Errorf("Error listing Profiles for IAM Role (%s) when trying to delete: %s", d.Id(), err)
}
// Loop and remove this Role from any Profiles
if len(resp.InstanceProfiles) > 0 {
for _, i := range resp.InstanceProfiles {
_, err := iamconn.RemoveRoleFromInstanceProfile(&iam.RemoveRoleFromInstanceProfileInput{
InstanceProfileName: i.InstanceProfileName,
RoleName: aws.String(d.Id()),
})
if err != nil {
return fmt.Errorf("Error deleting IAM Role %s: %s", d.Id(), err)
}
}
}
request := &iam.DeleteRoleInput{
RoleName: aws.String(d.Id()),
}
if _, err := iamconn.DeleteRole(request); err != nil {
return fmt.Errorf("Error deleting IAM Role %s: %s", d.Id(), err)
}
return nil
}
示例11: resourceAwsKeyPairRead
func resourceAwsKeyPairRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
req := &ec2.DescribeKeyPairsInput{
KeyNames: []*string{aws.String(d.Id())},
}
resp, err := conn.DescribeKeyPairs(req)
if err != nil {
awsErr, ok := err.(awserr.Error)
if ok && awsErr.Code() == "InvalidKeyPair.NotFound" {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving KeyPair: %s", err)
}
for _, keyPair := range resp.KeyPairs {
if *keyPair.KeyName == d.Id() {
d.Set("key_name", keyPair.KeyName)
d.Set("fingerprint", keyPair.KeyFingerprint)
return nil
}
}
return fmt.Errorf("Unable to find key pair within: %#v", resp.KeyPairs)
}
示例12: environmentFromResourceData
func environmentFromResourceData(d *schema.ResourceData) (*chefc.Environment, error) {
env := &chefc.Environment{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
ChefType: "environment",
}
var err error
err = json.Unmarshal(
[]byte(d.Get("default_attributes_json").(string)),
&env.DefaultAttributes,
)
if err != nil {
return nil, fmt.Errorf("default_attributes_json: %s", err)
}
err = json.Unmarshal(
[]byte(d.Get("override_attributes_json").(string)),
&env.OverrideAttributes,
)
if err != nil {
return nil, fmt.Errorf("override_attributes_json: %s", err)
}
env.CookbookVersions = make(map[string]string)
for k, vI := range d.Get("cookbook_constraints").(map[string]interface{}) {
env.CookbookVersions[k] = vI.(string)
}
return env, nil
}
示例13: resourceAwsSnsTopicRead
func resourceAwsSnsTopicRead(d *schema.ResourceData, meta interface{}) error {
snsconn := meta.(*AWSClient).snsconn
attributeOutput, err := snsconn.GetTopicAttributes(&sns.GetTopicAttributesInput{
TopicArn: aws.String(d.Id()),
})
if err != nil {
return err
}
if attributeOutput.Attributes != nil && len(attributeOutput.Attributes) > 0 {
attrmap := attributeOutput.Attributes
resource := *resourceAwsSnsTopic()
// iKey = internal struct key, oKey = AWS Attribute Map key
for iKey, oKey := range SNSAttributeMap {
log.Printf("[DEBUG] Updating %s => %s", iKey, oKey)
if attrmap[oKey] != nil {
// Some of the fetched attributes are stateful properties such as
// the number of subscriptions, the owner, etc. skip those
if resource.Schema[iKey] != nil {
value := *attrmap[oKey]
log.Printf("[DEBUG] Updating %s => %s -> %s", iKey, oKey, value)
d.Set(iKey, *attrmap[oKey])
}
}
}
}
return nil
}
示例14: resourceAwsIAMServerCertificateRead
func resourceAwsIAMServerCertificateRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).iamconn
resp, err := conn.GetServerCertificate(&iam.GetServerCertificateInput{
ServerCertificateName: aws.String(d.Get("name").(string)),
})
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
return fmt.Errorf("[WARN] Error reading IAM Server Certificate: %s: %s", awsErr.Code(), awsErr.Message())
}
return fmt.Errorf("[WARN] Error reading IAM Server Certificate: %s", err)
}
// these values should always be present, and have a default if not set in
// configuration, and so safe to reference with nil checks
d.Set("certificate_body", normalizeCert(resp.ServerCertificate.CertificateBody))
c := normalizeCert(resp.ServerCertificate.CertificateChain)
if c != "" {
d.Set("certificate_chain", c)
}
d.Set("path", resp.ServerCertificate.ServerCertificateMetadata.Path)
d.Set("arn", resp.ServerCertificate.ServerCertificateMetadata.Arn)
return nil
}
示例15: resourceAwsAutoscalingLifecycleHookPut
func resourceAwsAutoscalingLifecycleHookPut(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).autoscalingconn
params := getAwsAutoscalingPutLifecycleHookInput(d)
log.Printf("[DEBUG] AutoScaling PutLifecyleHook: %s", params)
err := resource.Retry(5*time.Minute, func() error {
_, err := conn.PutLifecycleHook(¶ms)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if strings.Contains(awsErr.Message(), "Unable to publish test message to notification target") {
return fmt.Errorf("[DEBUG] Retrying AWS AutoScaling Lifecycle Hook: %s", params)
}
}
return resource.RetryError{Err: fmt.Errorf("Error putting lifecycle hook: %s", err)}
}
return nil
})
if err != nil {
return err
}
d.SetId(d.Get("name").(string))
return resourceAwsAutoscalingLifecycleHookRead(d, meta)
}