本文整理匯總了Golang中github.com/hashicorp/terraform/helper/schema.ResourceData.SetDependencies方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResourceData.SetDependencies方法的具體用法?Golang ResourceData.SetDependencies怎麽用?Golang ResourceData.SetDependencies使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/terraform/helper/schema.ResourceData
的用法示例。
在下文中一共展示了ResourceData.SetDependencies方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: resourceHerokuAddonRead
func resourceHerokuAddonRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*heroku.Service)
addon, err := resource_heroku_addon_retrieve(
d.Get("app").(string), d.Id(), client)
if err != nil {
return err
}
// Determine the plan. If we were configured without a specific plan,
// then just avoid the plan altogether (accepting anything that
// Heroku sends down).
plan := addon.Plan.Name
if v := d.Get("plan").(string); v != "" {
if idx := strings.IndexRune(v, ':'); idx == -1 {
idx = strings.IndexRune(plan, ':')
if idx > -1 {
plan = plan[:idx]
}
}
}
d.Set("name", addon.Name)
d.Set("plan", plan)
d.Set("provider_id", addon.ProviderID)
d.Set("config_vars", []interface{}{addon.ConfigVars})
d.SetDependencies([]terraform.ResourceDependency{
terraform.ResourceDependency{ID: d.Get("app").(string)},
})
return nil
}
示例2: resourceRecordRead
func resourceRecordRead(d *schema.ResourceData, meta interface{}) error {
p := meta.(*ResourceProvider)
client := p.client
rec, err := client.RetrieveRecord(d.Get("domain").(string), d.Id())
if err != nil {
// If the record is somehow already destroyed, mark as
// succesfully gone
if strings.Contains(err.Error(), "404 Not Found") {
d.SetId("")
return nil
}
return err
}
d.Set("name", rec.Name)
d.Set("type", rec.Type)
d.Set("value", rec.Data)
d.Set("weight", rec.StringWeight())
d.Set("priority", rec.StringPriority())
d.Set("port", rec.StringPort())
// We belong to a Domain
d.SetDependencies([]terraform.ResourceDependency{
terraform.ResourceDependency{ID: d.Get("domain").(string)},
})
return nil
}
示例3: resourceAwsSecurityGroupRead
func resourceAwsSecurityGroupRead(d *schema.ResourceData, meta interface{}) error {
p := meta.(*ResourceProvider)
ec2conn := p.ec2conn
sgRaw, _, err := SGStateRefreshFunc(ec2conn, d.Id())()
if err != nil {
return err
}
if sgRaw == nil {
d.SetId("")
return nil
}
sg := sgRaw.(*ec2.SecurityGroupInfo)
var deps []terraform.ResourceDependency
// Gather our ingress rules
ingressRules := make([]map[string]interface{}, len(sg.IPPerms))
for i, perm := range sg.IPPerms {
n := make(map[string]interface{})
n["from_port"] = perm.FromPort
n["protocol"] = perm.Protocol
n["to_port"] = perm.ToPort
if len(perm.SourceIPs) > 0 {
n["cidr_blocks"] = perm.SourceIPs
}
if len(perm.SourceGroups) > 0 {
// We depend on other security groups
for _, v := range perm.SourceGroups {
deps = append(deps,
terraform.ResourceDependency{ID: v.Id},
)
}
n["security_groups"] = flattenSecurityGroups(perm.SourceGroups)
}
ingressRules[i] = n
}
if v := d.Get("vpc_id"); v != nil && v.(string) != "" {
deps = append(deps,
terraform.ResourceDependency{ID: v.(string)},
)
}
d.Set("description", sg.Description)
d.Set("name", sg.Name)
d.Set("vpc_id", sg.VpcId)
d.Set("owner_id", sg.OwnerId)
d.Set("ingress", ingressRules)
d.SetDependencies(deps)
return nil
}
示例4: resourceHerokuAddonRead
func resourceHerokuAddonRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*heroku.Client)
addon, err := resource_heroku_addon_retrieve(
d.Get("app").(string), d.Id(), client)
if err != nil {
return err
}
d.Set("name", addon.Name)
d.Set("plan", addon.Plan.Name)
d.Set("provider_id", addon.ProviderId)
d.Set("config_vars", []interface{}{addon.ConfigVars})
d.SetDependencies([]terraform.ResourceDependency{
terraform.ResourceDependency{ID: d.Get("app").(string)},
})
return nil
}
示例5: resourceHerokuDrainCreate
func resourceHerokuDrainCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*heroku.Client)
app := d.Get("app").(string)
url := d.Get("url").(string)
log.Printf("[DEBUG] Drain create configuration: %#v, %#v", app, url)
dr, err := client.LogDrainCreate(app, url)
if err != nil {
return err
}
d.SetId(dr.Id)
d.Set("url", dr.URL)
d.Set("token", dr.Token)
d.SetDependencies([]terraform.ResourceDependency{
terraform.ResourceDependency{ID: app},
})
log.Printf("[INFO] Drain ID: %s", d.Id())
return nil
}
示例6: resourceHerokuDomainCreate
func resourceHerokuDomainCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*heroku.Service)
app := d.Get("app").(string)
hostname := d.Get("hostname").(string)
log.Printf("[DEBUG] Domain create configuration: %#v, %#v", app, hostname)
do, err := client.DomainCreate(app, heroku.DomainCreateOpts{hostname})
if err != nil {
return err
}
d.SetId(do.ID)
d.Set("hostname", do.Hostname)
d.Set("cname", fmt.Sprintf("%s.herokuapp.com", app))
d.SetDependencies([]terraform.ResourceDependency{
terraform.ResourceDependency{ID: app},
})
log.Printf("[INFO] Domain ID: %s", d.Id())
return nil
}
示例7: resourceAwsInstanceRead
func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
p := meta.(*ResourceProvider)
ec2conn := p.ec2conn
resp, err := ec2conn.Instances([]string{d.Id()}, ec2.NewFilter())
if err != nil {
// If the instance was not found, return nil so that we can show
// that the instance is gone.
if ec2err, ok := err.(*ec2.Error); ok && ec2err.Code == "InvalidInstanceID.NotFound" {
d.SetId("")
return nil
}
// Some other error, report it
return err
}
// If nothing was found, then return no state
if len(resp.Reservations) == 0 {
d.SetId("")
return nil
}
instance := &resp.Reservations[0].Instances[0]
// If the instance is terminated, then it is gone
if instance.State.Name == "terminated" {
d.SetId("")
return nil
}
d.Set("availability_zone", instance.AvailZone)
d.Set("key_name", instance.KeyName)
d.Set("public_dns", instance.DNSName)
d.Set("public_ip", instance.PublicIpAddress)
d.Set("private_dns", instance.PrivateDNSName)
d.Set("private_ip", instance.PrivateIpAddress)
d.Set("subnet_id", instance.SubnetId)
var deps []terraform.ResourceDependency
// Determine whether we're referring to security groups with
// IDs or names. We use a heuristic to figure this out. By default,
// we use IDs if we're in a VPC. However, if we previously had an
// all-name list of security groups, we use names. Or, if we had any
// IDs, we use IDs.
useID := instance.SubnetId != ""
if v := d.Get("security_groups"); v != nil {
match := false
for _, v := range v.(*schema.Set).List() {
if strings.HasPrefix(v.(string), "sg-") {
match = true
break
}
}
useID = match
}
// Build up the security groups
sgs := make([]string, len(instance.SecurityGroups))
for i, sg := range instance.SecurityGroups {
if useID {
sgs[i] = sg.Id
} else {
sgs[i] = sg.Name
}
deps = append(deps, terraform.ResourceDependency{ID: sg.Id})
}
d.Set("security_groups", sgs)
// If we're in a VPC, we depend on the subnet
if instance.SubnetId != "" {
deps = append(deps, terraform.ResourceDependency{ID: instance.SubnetId})
}
d.SetDependencies(deps)
return nil
}