Skip to content

Commit

Permalink
Merge pull request #87 from sl1pm4t/fix-annotations
Browse files Browse the repository at this point in the history
Fix TF re-adding annotations on every apply
  • Loading branch information
sl1pm4t authored Nov 22, 2018
2 parents a676d58 + 0b586bc commit 23b8de8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions kubernetes/resource_kubernetes_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ resource "kubernetes_deployment" "test" {
"prometheus.io/scrape" = "true"
"prometheus.io/scheme" = "https"
"prometheus.io/port" = "4000"
"kubernetes.io/egress-bandwidth" = "1M"
}
}
spec {
Expand Down
8 changes: 6 additions & 2 deletions kubernetes/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ func expandStringSlice(s []interface{}) []string {
return result
}

func flattenMetadata(meta metav1.ObjectMeta, d *schema.ResourceData) []map[string]interface{} {
func flattenMetadata(meta metav1.ObjectMeta, d *schema.ResourceData, metaPrefix ...string) []map[string]interface{} {
m := make(map[string]interface{})
configAnnotations := d.Get("metadata.0.annotations").(map[string]interface{})
prefix := ""
if len(metaPrefix) > 0 {
prefix = metaPrefix[0]
}
configAnnotations := d.Get(prefix + "metadata.0.annotations").(map[string]interface{})
m["annotations"] = removeInternalKeys(meta.Annotations, configAnnotations)
if meta.GenerateName != "" {
m["generate_name"] = meta.GenerateName
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/structures_daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func flattenDaemonSetSpec(in appsv1.DaemonSetSpec, d *schema.ResourceData) ([]in
// }
// att["template"] = podSpec

templateMetadata := flattenMetadata(in.Template.ObjectMeta, d)
templateMetadata := flattenMetadata(in.Template.ObjectMeta, d, "spec.0.template.0.")
podSpec, err := flattenPodSpec(in.Template.Spec)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/structures_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func flattenDeploymentSpec(in appsv1.DeploymentSpec, d *schema.ResourceData) ([]
att["selector"] = in.Selector.MatchLabels
att["strategy"] = flattenDeploymentStrategy(in.Strategy)

templateMetadata := flattenMetadata(in.Template.ObjectMeta, d)
templateMetadata := flattenMetadata(in.Template.ObjectMeta, d, "spec.0.template.0.")
podSpec, err := flattenPodSpec(in.Template.Spec)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/structures_stateful_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func flattenStatefulSetSpec(in appsv1.StatefulSetSpec, d *schema.ResourceData) (
att["selector"] = in.Selector.MatchLabels
att["update_strategy"] = flattenStatefulSetUpdateStrategy(in.UpdateStrategy, d)

templateMetadata := flattenMetadata(in.Template.ObjectMeta, d)
templateMetadata := flattenMetadata(in.Template.ObjectMeta, d, "spec.0.template.0.")
podSpec, err := flattenPodSpec(in.Template.Spec)
if err != nil {
return nil, err
Expand Down

0 comments on commit 23b8de8

Please sign in to comment.